Hi everyone, I tried to submit the assignment, but it gives me some error in exercise 2, 3 and 4, even though I think I’ve done everything fine.
Here’s the errors:
Errors exercise 2:
ValueError Traceback (most recent call last)
in
17
18 # UNIT TESTS
—> 19 split_dataset_test(split_dataset)
~/work/public_tests.py in split_dataset_test(target)
70 ‘right’: np.array([2, 7, 9, 10])}
71
—> 72 assert np.allclose(right, expected[‘right’]) and np.allclose(left, expected[‘left’]), f"Wrong value when target is at index 0. \nExpected: {expected} \ngot: {left:{left}, ‘right’: {right}}"
73
74
<array_function internals> in allclose(*args, **kwargs)
/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py in allclose(a, b, rtol, atol, equal_nan)
2247
2248 “”"
→ 2249 res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
2250 return bool(res)
2251
<array_function internals> in isclose(*args, **kwargs)
/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py in isclose(a, b, rtol, atol, equal_nan)
2356 yfin = isfinite(y)
2357 if all(xfin) and all(yfin):
→ 2358 return within_tol(x, y, atol, rtol)
2359 else:
2360 finite = xfin & yfin
/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py in within_tol(x, y, atol, rtol)
2337 def within_tol(x, y, atol, rtol):
2338 with errstate(invalid=‘ignore’):
→ 2339 return less_equal(abs(x-y), atol + rtol * abs(y))
2340
2341 x = asanyarray(a)
ValueError: operands could not be broadcast together with shapes (7,) (4,)
Errors exercise 3:
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)
101 node_indexes = list(range(4))
102 result = target(X, y, node_indexes, 0)
→ 103 assert np.isclose(result, 0.311278, atol=1e-6), f"Wrong information gain. Expected {0.311278} got: {result}"
104
105 result = target(X, y, node_indexes, 1)
AssertionError: Wrong information gain. Expected 0.311278 got: -0.18872187554086706
And errors exercise 4:
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)
140 node_indexes = [2, 3, 4]
141 result = target(X, y, node_indexes)
→ 142 assert result == 0, f"Wrong result. Expected 0, got {result}"
143
144 n_samples = 100
AssertionError: Wrong result. Expected 0, got -1
So, maybe the last two errors may be due to some mistake, but I can’t figure out what makes explode the error in exercise 2.