I’ve passed the tests of the first three exercises but in the fourth one when writing “get_best_split” I get the error below:
AssertionError Traceback (most recent call last)
<ipython-input-49-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)
131 y = 1 - X[:,0]
132 result = target(X, y, node_indexes)
--> 133 assert result == 0, f"If the target is fully correlated with other feature, that feature must be the best split. Expected 0, got {result}"
134
135 y = np.array([[0, 1, 0, 1, 0]]).T
AssertionError: If the target is fully correlated with other feature, that feature must be the best split. Expected 0, got 1
Also I when I submit the assignments I can’t get a grade and a similar message appears:
Cell #13. Can’t compile the student’s code. Error: AssertionError(‘If the target is fully correlated with other feature, that feature must be the best split. Expected 1, got -1’)
After I wrote my code and wasn’t passing, I’ve checked the Hints provided, and tried to rewrite the exercises using them, but still getting the same error as with my code. Are the tests provided correct or I am doing something wrong?
Hi Jose - You need to change your logic to consider for the situation when information gain is zero. I think the test program has all zeros in y, because of which your h_node & weighted entropy are zero. (information_gain = h_node - weighted_entropy)…Below is how I tried and it worked.
info_gain= compute_information_gain(X, y, node_indices, i)
if info_gain > max_info_gain:
max_info_gain = info_gain
best_feature = i
Have issue with C2W4 4.4 get_best_split with the following errors:
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)
129 result = target(X, y, node_indexes)
130
→ 131 assert result == -1, f"When the target variable is pure, there is no best split to do. Expected -1, got {result}"
132
133 y = X[:,0]
AssertionError: When the target variable is pure, there is no best split to do. Expected -1, got 1
Hi, I also get errors from the unittest in this exam, for example in the compute information gain exercise I get the following, although I get the expected results to the last decimal point:
Information Gain from splitting the root on brown cap: 0.034851554559677034
Information Gain from splitting the root on tapering stalk shape: 0.12451124978365313
Information Gain from splitting the root on solitary: 0.2780719051126377
AssertionError Traceback (most recent call last)
in
9
10 # UNIT TESTS
—> 11 compute_information_gain_test(compute_information_gain)
~/work/public_tests.py in compute_information_gain_test(target)
113
114 result = target(X, y, node_indexes, 1)
→ 115 assert np.isclose(result, 0, atol=1e-6), f"Wrong information gain. Expected {0.0} got: {result}"
116
117 print(“\033[92m All tests passed.”)
AssertionError: Wrong information gain. Expected 0.0 got: nan
I had this issue as well, but found out that the way I was going about it was wrong. In short, use the logic suggested to you in the hint. That is, updating max_gain at each step. I had a slightly different code which tried to append the computed gains at each step and then select the max value from the resulting list, which would give me the same issues as you’ve seen. Hope this helps.