Getting errors with Autograder for W4 assignment

Hi,
I am getting errors in autograder even though output from my code is identical to the expected output. How do I fix this? When I submit for grading - it fails because of these errors.

See example below:

Information Gain from splitting the root on brown cap: 0.03485155455967709
Information Gain from splitting the root on tapering stalk shape: 0.12451124978365324
Information Gain from splitting the root on solitary: 0.2780719051126377
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
in
** 9 **
** 10 # UNIT TESTS**
—> 11 compute_information_gain_test(compute_information_gain)

~/work/public_tests.py in compute_information_gain_test(target)
** 94 node_indexes = list(range(5))**
** 95 **
—> 96 result1 = target(X, y, node_indexes, 0)
** 97 result2 = target(X, y, node_indexes, 0)**
** 98 **

in compute_information_gain(X, y, node_indices, feature)
** 17 “”" **
** 18 # Split dataset**
—> 19 left_indices, right_indices = split_dataset(X, root_indices, feature)
** 20 **
** 21 # Some useful variables**

in split_dataset(X, node_indices, feature)
** 25 for i in node_indices:**
** 26 **
—> 27 if X[i,feature] == 1:
** 28 left_indices.append(i)**
** 29 else:**

IndexError: index 5 is out of bounds for axis 0 with size 5

Expected Output:

Information Gain from splitting the root on brown cap:  0.034851554559677034
Information Gain from splitting the root on tapering stalk shape:  0.12451124978365313
Information Gain from splitting the root on solitary:  0.2780719051126377

There are multiple test cases in the notebook. Not all of them display the expected results in your console.

Your code does not pass one of the tests in the “compute_information_gain_test()” function.

You can view this function (and see what data is uses) from the File menu, then open the “public_tests.py” file.

Thanks, not clear to me what test is failing as the only portion of code I need to write, for calculating information gain, looks right (see below). Is there a way to recreate the workbook? Maybe I deleted a line by mistake.

Most often, this issue is caused by errors in your compute_entropy() function.

Also, please don’t post your code on the forum. That’s not allowed by the Code of Conduct.

If a mentor needs to see your code, we’ll contact you with instructions.

Got it. Thanks - I removed the code.

It passed the test but I will look into it again. Appreciate your help.

Is there a way to restart from scratch? Recreate the workbook? Seems like I am playing a game of whack a mole :slight_smile: