Reputation: 1881
I am using sklearn.linear_model.LogisticRegression and using that I calculate the R^2 value as follows
regr.score(xtest, ytest)
and I get a score of 0.65
Now, just to compare i used the metric provided by sklearn.metrics.r2_score¶ and I calculate the score as follows
r2_score(ytest,regr.predict(xtest))
and I get a score of -0.54
According to the documentation regr.score returns "R^2 of self.predict(X) wrt. y." and this is what I did to calculate R^2 using the metric, but I don't get why the values are so different?
Can anyone help me explain it a bit?
Update: As suggested I switched the variables ytest,regr.predict(xtest) in r2_score, but in logistic regression I still get different values. So I updated the question.
Upvotes: 3
Views: 4670
Reputation: 3391
The reason you get different values because the score
function in LogisticRegression
class by default calculates the accuracy score. The accuracy score is simply the number of correct predictions divided by the total number of predictions. On the other hand an R2 score is entirely different and you can read more about its mathematics here.
Hope that helps!
Upvotes: 4