Index error in Week 4 Exercise of MLS Course

I have attached these 2 screenshots. I am not able to understand why this index error is coming when I have passed all the test before.
There is some error on when target variable is pure it should return -1 but I am not able to understand where that should come.
I am getting the correct output however still I am doing some mistake in the tests I suppose since the final cell is also working fine.

I checked in the pubic test and I was getting error here:

def get_best_split_test(target):
    X = np.array([[1, 0], 
         [1, 0], 
         [1, 0], 
         [0, 0], 
         [0, 1]])

    y = np.array([[0, 0, 0, 0, 0]]).T
    node_indexes = list(range(5))

    result = target(X, y, node_indexes)
    assert result == -1, f"When the target variable is pure, there is no best split to do. Expected -1, got {result}"

Here when I pass my get_best_split to the get_best_split_test I am getting this error however when I define the X and y in the similar manner I do not get any error.
I am not able to get to the bottom of the problem.

The error is resolved, by mistake I had referenced root_indices instead of node_indexes inside the get_best_split function which is why I was getting the indices error.
Please close this post.

1 Like