Best feature to split on: 2
AssertionError Traceback (most recent call last)
in
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 0
1 Like
I fixed this problem but it sure would be nice if the error messages were easier to understand.
2 Likes
Hey @toontalk,
Thanks for confirming that you were able to find the solution. However, I would like to take some time and explain this error, since it may be concise but can easily tell you where the problem lies in your function.
I am assuming after reviewing the lecture videos, you are well-accustomed to the fact that when the target variable is pure, there is no best split to do, i.e., when we are already at a leaf node, we don’t need to perform a split any more. In this case, your function get_best_split
is supposed to return best_feature = -1
, since best_feature
was initialized with -1, however, your function is returning 0, i.e., “Expected -1, got 0”.
I hope the error makes sense to you now.
Regards,
Elemento
5 Likes
Why is the best_feature initialised with -1 ?
1 Like
Hi, could you please share how you fixed this error. I am getting the same problem and do not see how to solve it?
If you have got the same error
you have assigned best_feature = 0 creating that error, it should be -1