Skip to content
Advertisement

Sklearn ROC AUC Score : ValueError: y should be a 1d array, got an array of shape (15, 2) instead

I have this dataset with target LULUS, it’s an imbalance dataset. I’m trying to print roc auc score if I could for each fold of my data but in every fold somehow it’s always raise error saying ValueError: y should be a 1d array, got an array of shape (15, 2) instead.. I’m kind of confused which part I did wrong because I do it exactly like in the documentation. And in several fold, I get it that It won’t print the score if there’s only one label but then it will return the second type of error about 1d array.

JavaScript

See my data in spreadsheet

Advertisement

Answer

Your output from model.predict_proba() is a matrix with 2 columns, one for each class. To calculate roc, you need to provide the probability of the positive class:

Using an example dataset:

JavaScript

It looks like this:

JavaScript

Then do:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement