Error in Ex1: C2_W4_Decision_Tree_with_Markdown

Greetings Teachers,
I am doing the Practical lab titled: C2_W4_Decision_Tree_with_Markdown.

In Exercise 1, I’ve entered my code. On running the test code section : … # UNIT TESTS
compute_entropy_test(compute_entropy) …, it fails for me.

This is the case even though my output (Entropy at root node: 1.0) is the same as shown in the ‘Expected Output’ cell below.

Below is copy paste of error and cells above and below:

print("Entropy at root node: ", compute_entropy(y_train)) 

Entropy at root node:  1.0
AssertionError                            Traceback (most recent call last)
<ipython-input-58-05098bb5d0e3> in <module>
      6 # UNIT TESTS
----> 7 compute_entropy_test(compute_entropy)

~/work/ in compute_entropy_test(target)
      5     result = target(y)
----> 7     assert result == 0, "Entropy must be 0 with array of ones"
      9     y = np.array([0] * 10)

AssertionError: Entropy must be 0 with array of ones

Expected Output:

Entropy at root node: 1.0

Any thoughts why I didnt pass the Tests for this exercise 1. Your assistence will be greatly appreciated. Please advise. Sincerely.

Thank you

Hi. Even when the result is the same, it can also be wrong, since the public test evaluates your code and the expected output in different situations. So, it looks like even when you get the correct result for y_train, the code is not accurate at computing the entropy.

Aha! ok Thank you Pastorsoto for advice. Will work on it.
Edit: Few hours later.
Glad its working and all tests passed. Thank you again :pray:

1 Like