I’ve been on the last assignment for Course 2. My code works and produces the required results; however, I have encountered issues with some embedded Assertion Errors and as a result can’t pass the assignment.
For instance, on the compute_entropy function, my code provides the correct result. I have even gone ahead to check the hint and implement accordingly., but the code returns ‘AssertionError: Entropy must be 0 with array of ones’.
Another instance is the compute_information_gain function, my code produces the expected output. However, it also returns an error ‘AssertionError: Information gain must be 0 when target variable is pure. Got nan and nan’. To rectify this, I imported the math module, added a condition ‘if math.isnan(information_gain): information_gain =0’, yet it returned same error.
Despite these, I went ahead to implement the function to get best split. While it produces the right output, it ptoduces yet another error ‘AssertionError: When the target variable is pure, there is no best split to do. Expected -1, got 0’
Note that these errors come when you run the cells used to check correct implementations of functions.
So the question is, when the input is an array of ones, such as np.array([1,1,1,1]), what does your function do? Why doesn’t it return a zero?
If you can’t figure it out by just reading the code, then I would suggest you to use the print function inside your function to print something out for you to keep track of the progress of your function, and make sure you see for your eye that each step is working really as your expectation because if you can’t “read” the error out, then something isn’t working as you are expecting for.