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?
CodePudding user response:
There is no difference. model.score(test_x, test_y)
is simply a convenience method of most, possibly all classifiers that returns accuracy_score(test_y, model.predict(test_x))
.
CodePudding user response:
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).