Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Machine Learning by (19k points)

I'm using linear_model.LinearRegression from scikit-learn as a predictive model. It works and it's perfect. I have a problem to evaluate the predicted results using the accuracy_score metric. This is my true Data :

array([1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0])

My predictive Data:

array([ 0.07094605,  0.1994941 , 0.19270157,  0.13379635, 0.04654469,

    0.09212494,  0.19952108, 0.12884365,  0.15685076, -0.01274453,

    0.32167554,  0.32167554, -0.10023553,  0.09819648, -0.06755516,

    0.25390082,  0.17248324])

My code:

accuracy_score(y_true, y_pred, normalize=False)

Error message:

ValueError: Can't handle mix of binary and continuous target

Help ? Thank you.

2 Answers

0 votes
by (33.1k points)

Linear regression is a very poor classifier because it can’t classify two classes clearly. So It is not recommended to use for classification problems.

You can fix this error by using the following code:

accuracy_score(y_true, y_pred.round(), normalize=False)

If you wish to learn more about Machine Learning, then check out this Machine Learning Tutorial for more insights.

Hope this answer helps.

0 votes
by (1.2k points)

The issue over here is that the Linear Regression algorithm is much more suited and tailored towards the regression or predictive tasks for continuous data rather than classification tasks. Hence the evaluation metrics in this case are expected to be MSE, R2_score, MAE. But since here we are using accuracy_score as a metric for prediction that expects to compare the results based on the classes predicted correctly for categorical data.

Hence the given error is generated

Though, if you want to still work on the same, correct way is:

accuracy_score(y_true, y_pred.round(), normalise=False)

But the suitable approach is finding the best fit line

r2_score(y_true, y_pred)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...