Greetings TMosh, thank you very much for your great work. I’m similarly having a problem with this lab.
I have checked the indents and believe all is as it should be. I have tried multiple variations for computing P1. Lots of assertion errors. I relented and looked at the hint. I was pretty confident with the entropy formula further down. I checked that as well because I continued to get errors. I have tried running it code separate in another notebook and it seems to work (of course, I’m probably missing some crucial detail).
Yes. The assertion tells you exactly what the problem is. When the unit test feeds your function an array of all-ones, it does not give the correct result.
You can read the details of the test it is failing by opening the public_tests.py file (using the File menu), and then finding the compute_entropy_test() function.
Greetings again TMosh, apparently, haha, I’m still stuck.
I presume this function compute_entropy(y) takes its input for y outside the function so it can deal with different y training sets if required. So the public_tests.py supply the missing information. Would that be correct?
I have created another notebook page to test everything – but I do add y = y_train inside the function so I can see what it computes.
When I call compute_entropy(y) outside the function, with this array – y_train = np.array([1,1,0,0,1,0,0,1,1,0])
5/10
I get 1.0 – most impure
When I change the y_train array to equal ([1,1,0,1,1,1])
5/6
I get 0.6428571428571429
Are these correct? The code in the lab is the same as what I’m using to generate these answers (except for putting the training array inside the function).
Thank you very much for your help.
Ubik
ps. I had originally used p1 = np.sum(y) / …
for the first part of the assignment for p1 – I presume that this isn’t the equivalent of the supplied hint’s expression. But it seems to compute the same?
@TMosh I’m also having some challenges with this exercise (# UNQ_C3). I successfully computed compute_entropy() & split_dataset in the first 2 exercises. But I am getting an error “TypeError: unsupported operand type(s) for *: ‘float’ and ‘NoneType’” on my unit test. Not sure how to address at this point.
I didn’t modify any of the pre-written code. I have checked spellings as well.
I do notice something odd about the comment in the pre-written code, where is explains the args and return value. It only lists 3 of the 4 args, and returns “cost” instead of “information gain” which is the function that we are defining
Hi, I am having the same problem with the last code. I have successfully executed all the 4 exercises but because of the last code, I am not able to submit my assignment. I keep getting the same error no matter how I change the above code.