C2_w4 practice Lab

while compiling code for 2nd question it say’s “NameError: name ‘root_indices’ is not defined”

Hi @MOHD_SADIK,

The cell for testing the function split_dataset() should have the following line at the beginning of the cell:

root_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

This is where root_indices is defined.
Try refreshing the kernel and rerun the code from start should help.

by refreshing the kernal code is still not working , can you tell where i should add root_indices line

Hi @MOHD_SADIK ,

That line of code is given in the test cell which is located just below the function split_dataset() definition in UNQ_C2. Unless you have made changes to the test cell, it should be there.

I have restarted the kernal and root_indices line is showing now, but code still says root_indices not defined.

Hi @MOHD_SADIK

Could you send me a direct message with the code for the definition and test cell. I will have a look for you.

Hi @MOHD_SADIK ,

Some how the test cell has been changed. root_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] should be at the start of the test cell, before the comment line # Feel free to play around with these variables.
This root_indices is a variable created with data for testing the function split_dataset() that you have written. This variable should not be included in the split_dataset() function.

As you can see from the test cell, the function split_data() is called with root_indices as one of the parameters being passed to the function. If root_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] is not in the test cell, then the interpreter wouldn’t know what this root_indices is, hence the NameError message is raised .

Just move root_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] to the top of the test cell and refresh the kernel and rerun the code. That should solve the problem.

1 Like

Thank You!, It’s working.