Week 4 last assignment errors

Hello mentors,

I am having some issues with the last assignment that this course offers. I am getting some errors that I am unable to work on.

Exercise 3:

I am able to get the expected output, yet the above error is being showed. In fact I even tried using the exact code that was given in in Hints just to see where I went wrong but to no avail.

I am facing the same issue with Exercise 4 and 5 but couldn’t attach their screenshots as only one image is allowed.

As a result of this I am unable to achieve the required grades.

I request you to help me out with this.
Thanks!

This what I am getting when submitting the assignment:

The error refers to “nan”. That means “not a number”.
There is more than one test of your code.
I suspect that for one of the tests, your code is trying to divide by zero. That will give a “nan” result error code.

1 Like

Hey, it worked! Thanks a lot for your help. I wasn’t paying attention to the errors being shown in a proper manner and thus was a mistake from my end.

The issue was int he function definition in exercise 1. When calculating

entropy=-p1*np.log2(p1)-(1-p1)*np.log2(1-p1))
where p1= len(y[y == 1]) / len(y)

one has to make sure that there is a condition statement used for when len(y)=0.

The tests conducted by the system in exercise 1 didn’t account for that and as a result it caused issues later on in the assignment.

Putting the code block inside the conditional statement:
if len(y)!=0 solved the problem!

Once again thanks a lot for bringing my attention to the main issue

1 Like