Machine Learning Specialization - DeepLearning.AI Help

Exercise 4

8/25

Failed test case: Expected 0, but got -1.
Expected:
0,
but got:
-1.

Failed test case: Expected best feature in [0,1], but got -1.
Expected:
[0, 1],
but got:
-1.

Exercise 3

17/25

Failed test case: compute_information_gain test 1 failed.
Expected:
1.0,
but got:
0.
Explain the cause of the error.

Could you please specify which assignment or lab you’re currently working on? That will help mentors understand the context of your issue.

Based on what you’ve shared so far, it’s likely that there’s an issue somewhere in your code. I’d recommend going back through your implementation carefully and comparing it with the assignment instructions to see if anything was missed.

At the moment, I can’t determine exactly what’s causing the problem without knowing which lab you’re working on and seeing the relevant code or error message.

C2W4_Assignment

From what I’ve seen in the exercises, although I’m not a mentor specifically for this course, you should only fill in the code between the START CODE HERE and END CODE HERE markers.

For Exercise 3, in particular, I noticed that there are quite a few helpful hints available. If you click the green “Click for hints” section at the end of the compute_information_gain function, you’ll find guidance on how to approach the implementation. If you scroll further down, there are even more detailed hints, including how to calculate the entropies and other intermediate steps.

In general, the exercise is designed so that you build on the functions you implemented earlier, so make sure you’re reusing those functions instead of rewriting the logic from scratch.

Hi @Sami_Sayyar, were you able to get this figured out with the suggestions from @gent.spah?

If not, could you share a screenshot of the errors you’re getting? Let’s start with the first exercise that’s giving you an error (Exercise 3). Sometimes errors in one exercise will cause problems in future exercises. Can you also check if the results you’re seeing from these tests right before the call to compute_information_gain_test() are returning the results that match the expected output (shown right below the cell with the tests)?

Thanks, @Sami_Sayyar,

I see. You are getting errors when you submit the assignment.

Let’s start by looking at Exercise 3, since an error in one exercise could lead to errors in future exercises.

The error message you’re getting for Exercise 3 says it was expecting compute_information_gain() to return 1, but instead, it returned 0.

Think about what situation causes an information gain of 1.0. That is the maximum information gain. That could happen if the node you started with had an equal number of poisonous and non-poisonous mushrooms (entropy = 1), and the split caused all the poisonous mushrooms to go to one group and all the non-poisonous mushrooms to go to the other group, (entropy = 0 for both left and right). A perfect split. In this case, your information gain from the split = 1 (entropy from the original node - sum of the weighted entropies of the two nodes it was split into.)

So, you know your code for exercise 3 is not handling that case as expected. Armed with that information, and the hints in the exercise, you should be able to take a stab at seeing where the problem is.

Before you dig into that case, though, I would make sure that all the unit tests in the assignment are passing. It can be easier to debug these tests first. (And helpful that if you get stuck on them, you have access to the test code in public_tests.py, to help you see exactly what the test is trying to do.). For the Exercise 3 tests, you should get the same answers as the “Expected Output” for the 3 test calls I mentioned above, and you should see “All tests passed” for the rest of the tests.

If you are still stuck, please share a screenshot of your unit test results for Exercise 3 and we can go from there.