Week # 4 C2_W4_Decision_Tree Lab Assignment. I am getting below error)
The output results are correct ( after you test the code) but still getting error. Also p1 variable is used/defined correctly in previous entropy function.

I followed below steps to troubleshoot and resolve any issues -
Kernel -Restart-clear all outputs and started all over again
It gave me different error next time when I ran above code which is X Train is not defined but it is defined already in first few code cells. I checked for all typos or variable defintions seems to be alright. And now again its giving me above error.

I also checked public_tests.py file but not able to make out the exact error in my program.


1 Like

One of your functions does not correctly handle the case where the length of y is zero.

1 Like

So are you saying my compute information gain function is not functining correctly for y = 0 ?

my brain is freezed :slight_smile: at this point.

1 Like

Could also be compute_entropy.

1 Like

Ok I am frustrated I checked compute information gain and compute entropy function and they seem to be correct. Do I have declaer P1 variable as float with value 0. ? Any help to resolve this error would be beneficial

I will again check everything tomorrow.

In compute_entropy(), it looks to me like you have an indentation problem around line 22.

Check the Hint code below that function.

You don’t want to use the p1 variable if the length of y is 0. In that case, you want to fall through the if-statement and hit the return statement, with entropy already set to 0 (from earlier in the function).

Hi @TMosh

Thank you for your guidance on variable p1 thats what I exactly thought and hence was not adding anything in the code or defining variable p1 even through error was bit mis leading.
However as you have stated the entrophy function had indentation error and that resolved all the issues:-) ( I checked all the program step by step and resolved it.) what a relief.

Thank you for the help

1 Like