I am getting an assertion error for the get_best_split() function. I have tried implementing without looking at the hints and have got this error so I looked at the hints in the practice lab for help, but I still get the same error and have no idea as to why it is coming.
This is the error I keep getting:
Best feature to split on: 2
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-25-c263c9190d86> in <module>
3
4 # UNIT TESTS
----> 5 get_best_split_test(get_best_split)
~/work/public_tests.py in get_best_split_test(target)
120 result = target(X, y, node_indexes)
121
--> 122 assert result == -1, f"When the target variable is pure, there is no best split to do. Expected -1, got {result}"
123
124 y = X[:,0]
AssertionError: When the target variable is pure, there is no best split to do. Expected -1, got 1
One thing that seems very puzzling here is that if the feature is pure then the information gain will always be 0, since entropy is at its maximum of 1. So the code in my implemented function must return -1 since the if statement would never execute as 0 > 0 is false (any split would be 0, and max_info_gain would stay 0) and so the value of best_feature should not change from -1. However the assert is getting 1 and I have no idea why.
All the other functions before this one work correctly and pass all the assertion tests and I have checked this function many times. I would be very grateful for an explanation as to why this error is occuring and the mistake that I have made, especially since the code appears correct. Thank you.