nappingkid
nappingkid

Reputation: 175

Classification report for regression (sklearn)

When you try to predict if something belongs to a certain class you can use the classification report from sklearn. However, this only works when the classes are categorical.

Does anyone happen to figure out how to use the classification report from sklearn when you try to predict a value instead, like with a support vector regression machine or linear regression?

I get the following error:

ValueError: Unknown label type: (123     13.409091
760     16.593333
748     13.646667
334     13.828571)

When trying:

print("Classification report: ", classification_report(y_test, y_pred))

Here y_test is a column of a pandas DataFrame and y_pred is a numpy array. I tried converting the column into a numpy array, but then it gives the same error, but with the array.

Does any know how to make the classification work to check the auc, precision/recall and f1-score for the prediction of a value (if there is a better way than sklearn, please do not hesitate to say so.)

Upvotes: 8

Views: 14832

Answers (1)

Owlright
Owlright

Reputation: 180

The metrics that you named (accuracy, precision, recall & f1-score) are specifically for classification problems, where the prediction can be either right or wrong.

As you want to predict values, you are dealing with a regression problem and you want your metric to tell you how close your prediction is. A good metric for this is the coefficient of determination also called r2-score.

Upvotes: 9

Related Questions