Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to obtain accuracy score for my linear

I am working on my regression model based on the IMDB data, to predict IMDB value. On my linear-regression, i was unable to obtain the accuracy score.

my line of code:

metrics.accuracy_score(test_y, linear_predicted_rating)

Error :

ValueError: continuous is not supported

if i were to change that line to obtain the r2 score,

metrics.r2_score(test_y,linear_predicted_rating)

i was able to obtain r2 without any error. Any clue why i am seeing this?

Thanks.

Edit: One thing i found out is test_y is panda data frame whereas the linear_predicted_rating is in numpy array format.

like image 972
ML N00b Avatar asked Nov 27 '22 20:11

ML N00b


2 Answers

metrics.accuracy_score is used to measure classification accuracy, it can't be used to measure accuracy of regression model because it doesn't make sense to see accuracy for regression - predictions rarely can equal the expected values. And if predictions differ from expected values by 1%, the accuracy will be zero, though these predictions are great

Here are some metrics for regression: http://scikit-learn.org/stable/modules/classes.html#regression-metrics

like image 76
Andrey Lukyanenko Avatar answered Dec 10 '22 12:12

Andrey Lukyanenko


NOTE: Accuracy (e.g. classification accuracy) is a measure for classification, not regression so we can't calculate accuracy for a regression model. For regression, one of the matrices we've to get the score (ambiguously termed as accuracy) is R-squared (R2).

You can get the R2 score (i.e accuracy) of your prediction using the score(X, y, sample_weight=None) function from LinearRegression as follows by changing the logic accordingly.

from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(x_train,y_train)
r2_score = regressor.score(x_test,y_test)
print(r2_score*100,'%')

output (a/c to my model)

86.23%
like image 35
Garvit Avatar answered Dec 10 '22 12:12

Garvit