0
votes

I use random forest classifier in a multi class problem.

rf = RandomForestClassifier(()
rf.fit(train_X, train_y)

And then for prediction:

pred = rf.predict(test_X)

So then I want to compute the roc_auc_score like so:

roc_value = roc_auc_score(test_y, pred, average='weighted', 
    multi_class='ovr',labels=[0,1,2,3,4])

But this gives an error:

numpy.AxisError: axis 1 is out of bounds for array of dimension 1

How do I fix this?

1

1 Answers

2
votes

If you are interested in ROC AUC, pred needs to be probabilities, not predicted labels. In your case, it is a multiclass classification problem, so pred needs to be a matrix of shape (n_samples, n_classes). To get it you just need to use predict_proba instead of predict:

pred = rf.predict_proba(test_X)