Hi, in the last assigment, when I’m grading the assignment I receive this error
The cell 11 is supposed to be this (where you have to build the compute_information_gain)
{moderator edit: code removed}
and when I run the next cell, which is
info_gain0 = compute_information_gain(X_train, y_train, root_indices, feature=0)
print("Information Gain from splitting the root on brown cap: ", info_gain0)
info_gain1 = compute_information_gain(X_train, y_train, root_indices, feature=1)
print("Information Gain from splitting the root on tapering stalk shape: ", info_gain1)
info_gain2 = compute_information_gain(X_train, y_train, root_indices, feature=2)
print("Information Gain from splitting the root on solitary: ", info_gain2)
I don’t know if that’s the cause behind my grading issue, although it doesn’t look like. But the code I wrote is just right, so I can’t get how this error in the test is raised.
My compute_entropy() function pass all the tests, so it doesn’t seem to be the problem. Also, it happens the same with the code from the hint. How is it possible to get a nan when you are making a normal numeric operation in Python?
In the compute_entropy() function, the variable entropy is set to a float of value 0.0 in the template code that is already done for you. If you have changed the code there, and this variable entropy only exists inside the if code block, then the function would return NAN value when the input node has no samples.