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?
y = (N-1) / (n-p-1)
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.
(coefficient of determination) regression score function. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse).
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
where n is number of observations in sample and p is number of independent variables in model
alternatively...
# adjusted R-squared
1 - ( 1-model.score(X, y) ) * ( len(y) - 1 ) / ( len(y) - X.shape[1] - 1 )
Adj_r2 = 1 - (1-r2_score(y_test, y_pred)) * (len(y)-1)/(len(y)-X.shape[1]-1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With