Scikit-learn: ValueError: continuous format is not supported in RidgeClassifierCV

Created on 26 Mar 2016  ·  3Comments  ·  Source: scikit-learn/scikit-learn

If you run the following code:

import numpy as np
from sklearn.linear_model.ridge import RidgeClassifierCV

classifier = RidgeClassifierCV(scoring='roc_auc')
x = np.array([[1, 2, 3], [3, 4, 9], [4, 9, 1], [8, 0, 4], [1, 1, 4], [1.1, 2, 4]])
y = np.array([True, False, True, False, True, False])
classifier.fit(x, y)

You get the exception: _ValueError: continuous format is not supported_ with the stacktrace:

File "E:/myfolder/cv_issue.py", line 7, in classifier.fit(x, y)
File "E:Anaconda2libsite-packagessklearnlinear_modelridge.py", line 1258, in fit
_BaseRidgeCV.fit(self, X, Y, sample_weight=sample_weight)
File "E:Anaconda2libsite-packagessklearnlinear_modelridge.py", line 1022, in fit
estimator.fit(X, y, sample_weight=sample_weight)
File "E:Anaconda2libsite-packagessklearnlinear_modelridge.py", line 965, in fit
for i in range(len(self.alphas))]
File "E:Anaconda2libsite-packagessklearnmetricsscorer.py", line 159, in __call__
raise ValueError("{0} format is not supported".format(y_type))
ValueError: continuous format is not supported

But, obviously, I provided a binary output so I don't expect such error here. And if you replace RidgeClassifierCV(scoring='roc_auc') with a RidgeClassifierCV(scoring='roc_auc', cv=2), the code runs fine.

My versions:

Windows-8.1-6.3.9600
('Python', '2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)]')
('NumPy', '1.10.4')
('SciPy', '0.17.0')
('Scikit-Learn', '0.17')

Most helpful comment

"roc_auc" is a classification or ranking metric, not a regression metric. So it doesn't accept continuous y.

All 3 comments

Hi, it seems that the values being passed to the scorer in here are y and cv_values[:,i] are passed as y_true and y_score for roc_auc_score, but in the scorer, _ThresholdScorer takes arguments X and y which now correspond to y_true and y_score in your case are

[ 1. -1.  1. -1.  1. -1.] 
[ 0.45824999 -1.64622488  0.6707735  -0.74680963  0.07694918  0.49169546]

Thus the check of y_type is raising an error of continuous type. I am not sure if this is the expected behavior in here since Threshold scorer was designed with this intent. Sorry can't be of much help here.

"roc_auc" is a classification or ranking metric, not a regression metric. So it doesn't accept continuous y.

I believe the OP stated that his targets were discrete, not continuous. I am also getting the same error with targets being discrete, 0s and 1s only.

Was this page helpful?
0 / 5 - 0 ratings