Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I calculate the Adjusted R-squared score using scikit-learn?

I'm already using the r2_score function but don't understand how I can get the "adjusted" R^2 score from this. The description at this page doesn't mention it - maybe it's the adjusted score by default?

like image 835
Nic Cottrell Avatar asked Mar 20 '18 10:03

Nic Cottrell


People also ask

How do you calculate adjusted R-squared in python?

y = (N-1) / (n-p-1)

How is adjusted R-squared calculated?

Adjusted R squared is calculated by dividing the residual mean square error by the total mean square error (which is the sample variance of the target field). The result is then subtracted from 1. Adjusted R2 is always less than or equal to R2.

What is R2 score in Scikit learn?

(coefficient of determination) regression score function. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse).


3 Answers

Adjusted R2 requires number of independent variables as well. That's why it will not be calculated using such an independent metrics function (as we are not providing, how ypred was calculated).

However you can calculate the adjusted R2 from R2 with a simple formula given here

enter image description here

where n is number of observations in sample and p is number of independent variables in model

like image 137
Aritesh Avatar answered Oct 08 '22 20:10

Aritesh


alternatively...

# adjusted R-squared
1 - ( 1-model.score(X, y) ) * ( len(y) - 1 ) / ( len(y) - X.shape[1] - 1 )
like image 38
Manoj Kumar Avatar answered Oct 08 '22 20:10

Manoj Kumar


Simple calculation of Adj. R2

Adj_r2 = 1 - (1-r2_score(y_test, y_pred)) * (len(y)-1)/(len(y)-X.shape[1]-1)
like image 2
Suhas_Pote Avatar answered Oct 08 '22 20:10

Suhas_Pote