How to calculated the adjusted R2 value using scikit

25,190

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

Adj r2 = 1-(1-R2)*(n-1)/(n-p-1)

Adjusted R2 requires number of independent variables as well. That's why it will not be calculated using this function.

Share:
25,190
Ahamed Moosa
Author by

Ahamed Moosa

Updated on May 18, 2020

Comments

  • Ahamed Moosa
    Ahamed Moosa about 4 years

    I have a dataset for which I have to develop various models and compute the adjusted R2 value of all models.

        cv = KFold(n_splits=5,shuffle=True,random_state=45)
        r2 = make_scorer(r2_score)
        r2_val_score = cross_val_score(clf, x, y, cv=cv,scoring=r2)
        scores=[r2_val_score.mean()]
        return scores
    

    I have used the above code to calculate the R2 value of every model. But I am more interested to know the adjusted R2 value of every models Is there any package in python which can do the job?

    I will appreciate your help.

  • Ahamed Moosa
    Ahamed Moosa almost 6 years
    Thanks , so I assume n = number of sample size , p = number of independent variables
  • nvergos
    nvergos about 5 years
    When we want to calculate adjusted R2 for each fold during cross-validation, will n correspond to the size of the dataset or the size of the fold? (e.g., 80% of the number of rows if we are doing 5-fold CV) @min2bro
  • jeffhale
    jeffhale almost 4 years
    @nvergos n should correspond to the size of the fold.
  • vasili111
    vasili111 about 3 years
    Should I use nand p of train set if I am evaluating for train or test set. Or I should use nand p for train set if I am evaluating for train set and use test set nand p if I am evaluating for test set?
  • Girish Kumar Chandora
    Girish Kumar Chandora almost 3 years
    @vasili111 we check the model performance on test data, so its better to check the adjusted r2 and r2 on test data.