user961627
user961627

Reputation: 12747

Plotting ROC curve - too many indices error

I'm picking up the ROC code straight from here: http://scikit-learn.org/stable/auto_examples/plot_roc.html

I've hard coded my number of classes as 46, in the for loop, as you can see, however even if I set it down to as low as 2, I still get an error.

# Compute ROC curve and ROC area for each class
tpr = dict()
roc_auc = dict()
for i in range(46):
    fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_pred[:, i])
    roc_auc[i] = auc(fpr[i], tpr[i])

The error is:

Traceback (most recent call last):
  File "C:\Users\app\Documents\Python Scripts\gbc_classifier_test.py", line 150, in <module>
    fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_pred[:, i])
IndexError: too many indices

y_pred is as you can see here: array.shape() giving error tuple not callable

and y_test is just a 1D array similar to y_pred, except with the true classes of my problem.

I don't understand, what has too many indices?

Upvotes: 2

Views: 2090

Answers (1)

Fred Foo
Fred Foo

Reputation: 363567

Both the y_pred shown in your other question and y_test are 1-d, so the expressions y_pred[:, i] and y_test[:, i] have too many indices. You can only index a 1-d array with a single index.

That said, you should probably just call roc_curve(y_test, y_pred).

Upvotes: 5

Related Questions