C2_W4_Decision_Tree_with_Markdown - tests start failing

Hi,

This is on the Wk4 programming assignment:
I added code copy/pasting from the hints and I got the expected results + All tests passed.
However,
From # UNQ_C3 onwards, while still getting the expected results, my tests fail.

I can’t make up from the errors what to do different.

Any advise, pls ?

Thanks!

2 Likes

Please post a screen capture image showing the error messages or asserts.

1 Like

In the Hint code for the compute_entropy() function, you can put in some code here to give p1 an initial value.

1 Like

That initial value is discussed in the instructions:
image

I’m seeing different Hints for # UNQ_C3…

1 Like

…and this is #UNQ_C3, with my copy/pasted code…

{moderator edit: code removed}

1 Like

Well, you’re looking at UNQ_C3 “compute_information_gain()”, and I’m talking about UNQ_C1 “compute_entropy()”.

On UNQ_C1 I look good, as much as I can tell…

{moderator edit: code removed}

1 Like


1 Like

Refer to the image of the hint code I posted earlier. You’re missing setting an initial value for P1.

Passing the notebook unit tests doesn’t prove your code is perfect.

1 Like

I thought the initial value of p1 was…
p1 = len(y[y == 1]) / len(y)

1 Like

Yes it should be.
Where is that in your code?

Here…
{moderator edit: code removed}

1 Like

That should solve the problem of the “p1 referenced before assignment” error.

…supposably on #UNQ_C3.
And it doesn’t solve the problem of the “p1 referenced before assignment” error.

1 Like

Check your personal messages for instructions.

Files (4).zip (330.2 KB)

1 Like

Sorry, I don’t open zip files for security reasons.

See my personal message to you for instructions. Send the ipynb file via a personal message. Do not modify the file name.

1 Like

Update for those who find this thread later:

Inside the compute_entropy() function, the code that tests the p1 values was not indented to the correct level.

1 Like