Reputation: 19
What is the difference in sklearn, between
accuracy_score(y_test,y_pred)
and model.score(X_test,y_test)
?
I tried both of these in several models and both of them gave me the same results as their output. So what is the exact difference between them? Which one is the most useful?
Upvotes: 1
Views: 853
Reputation: 872
There is no difference. model.score(test_x, test_y)
is simply a convenience method of all classifiers that returns accuracy_score(test_y, model.predict(test_x))
. (As the other commenter noted, it will call r2_score
for regressors.)
Upvotes: 2
Reputation: 166
By using score,it calls r2_score, which is the coefficient of determination defined in the statistics course.
The accuracy_score method is used to calculate the accuracy of either the fraction or count of correct prediction in Python Scikit learn. Mathematically it represents the ratio of the sum of true positives and true negatives out of all the predictions. If normalize == True, return the fraction of correctly classified samples (float), else returns the number of correctly classified samples (int).
Upvotes: 0