Unable to obtain accuracy score for my linear

Viewed 46692

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.

5 Answers

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%

The above is R squared value and not the accuracy :

# R squared value
metrics.explained_variance_score(y_test, predictions)

You can not predict the accuracy of regression model,however you can analyze your model using Mean absolute error ,Mean squared error ,Root mean squared error,Max error,median error R-square etc. for reference you can go this to gain more knowledge

Related