Machine LearningRegression Metrics

R-squared vs Adjusted R-squared

Question 293 of 303 · Updated

On this page

R-squared (R²) measures how much better a regression model fits the observed target values than a mean-only baseline. Adjusted R-squared modifies that score to account for how many predictors the model uses.

The key difference: ordinary R² never decreases when predictors are added to an ordinary least-squares model fitted on the same data; adjusted R² can decrease when a new predictor does not improve the fit enough to justify its added complexity.

1. What is R-squared?#

R-squared is also called the coefficient of determination. It compares the model's residual error with the total variation around the target's mean.

Where:

  • SSE (residual sum of squares) =
  • SST (total sum of squares) =
  • = actual target value
  • = predicted target value
  • ȳ = mean of actual target values

A simple way to understand it: compare your regression model with a baseline that predicts the mean target for every observation. R² measures the reduction in squared error relative to that baseline.

Example#

Suppose the total variation around the target mean is 1,000 and the model's residual squared error is 200.

The model accounts for 80% of the target variation relative to the mean baseline on this dataset. It does not mean that 80% of predictions are correct, nor does it establish that the predictors cause the outcome.

2. What is Adjusted R-squared?#

Adjusted R-squared modifies ordinary R² by accounting for the number of predictors and the sample size.

For a standard multiple linear regression with an intercept:

Where:

  • = ordinary coefficient of determination
  • n = number of observations
  • p = number of predictors, excluding the intercept

The adjustment reflects the degrees of freedom used by the model. A model with many predictors needs to reduce residual error sufficiently to maintain or improve its adjusted score.

This formula assumes an intercept and requires n > p + 1.

3. Numerical example: why the adjustment matters#

Suppose a house-price model has:

  • 100 training observations
  • 5 predictors

Then:

So:

The adjusted value is slightly lower because the model uses five predictors.

What happens when you add a weak predictor?#

Imagine you add a sixth predictor, such as an irrelevant random column. The training R² might rise slightly from 0.8000 to 0.8010 simply because ordinary least squares can use the extra coefficient to fit the training data at least as well.

But adjusted R² becomes:

The adjusted score falls from about 0.7894 to 0.7881. The tiny reduction in residual error did not justify the extra predictor under this penalty.

These figures are illustrative. In real data, the result depends on the fitted model and observations.

4. Why does ordinary R² increase when predictors are added?#

In ordinary least squares (OLS), adding a predictor expands the set of possible models. The new model can always reproduce the previous model by assigning the new predictor a coefficient of zero.

Therefore, when both models are fitted on the same observations using the same OLS objective, the residual sum of squares cannot increase. Since SST remains unchanged, ordinary R² cannot decrease.

This is a mathematical property of nested OLS models—not proof that every added feature is useful.

Adjusted R² introduces a degrees-of-freedom penalty. It rises only when the improvement in residual fit is large enough to compensate for the additional predictor.

5. How should you interpret the scores?#

R²

  • 1.0: perfect predictions on the evaluated observations.
  • 0.0: the model performs like the mean-only baseline in squared-error terms.
  • Between 0 and 1: improvement over that baseline.
  • Below 0: the model performs worse than the mean-only baseline on the evaluated data.

For a conventional OLS model with an intercept evaluated on its own training data, R² is between 0 and 1. On unseen data, R² can be negative.

Adjusted R²

  • Is usually less than or equal to ordinary R² for the standard intercept-based OLS setting.
  • Increases when the improvement in fit justifies the added predictors.
  • Decreases when the added predictors do not improve fit enough.
  • Can be negative, indicating poor fit after the degrees-of-freedom adjustment.

Neither score tells you the typical error in the target's original units. Pair them with MAE or RMSE when the size of prediction errors matters.

6. Assumptions and when the comparison is valid#

The familiar adjusted R² formula is designed for multiple linear regression fitted by ordinary least squares with an intercept.

For a fair comparison:

  • Fit models on the same response variable and the same observations.
  • Use the same handling of missing values and the same target transformations.
  • Count predictors consistently; the standard formula excludes the intercept from p.
  • Ensure the sample size is adequate relative to the number of predictors.
  • Compare models with compatible specifications and estimation procedures.

R² can be computed for many predictive models, but the classic adjusted R² formula does not automatically become a universally valid complexity correction for every algorithm, regularized estimator, weighted fit, or model without an intercept.

Classical linear-regression assumptions—such as linearity, independent errors, constant error variance, and appropriate error behavior—matter for coefficient inference, standard errors, confidence intervals, and hypothesis tests. They are not all mathematical requirements for calculating the descriptive R² value. Check residual diagnostics and study design before drawing inferential conclusions.

7. Important limitations#

Adjusted R² does not guarantee generalization. It penalizes the number of predictors, but it does not directly measure performance on new data. A model can have a high adjusted R² and still overfit, suffer from data leakage, or fail after a population shift.

It does not prove that a predictor is statistically significant. Use suitable coefficient tests, confidence intervals, or model-comparison tests when inferential claims are needed. Adjusted R² is not a substitute for those procedures.

It does not measure absolute error. A model can have a high R² while still making errors that are too large for a business application. Report MAE or RMSE in the target's units.

It does not establish causality. A high R² describes fit, not whether a predictor causes the outcome.

It can be misleading across datasets. R² depends on the variation in the evaluated target. Do not compare scores from different target populations or different test sets as if they were directly equivalent.

It does not automatically solve multicollinearity. Correlated predictors can make individual coefficients unstable even when overall fit scores look strong.

8. Python example#

Scikit-learn provides r2_score for ordinary R². It does not provide a general adjusted_r2_score metric in this API, so calculate the standard formula when its assumptions apply.

```python from sklearn.linear_model import LinearRegression from sklearn.metrics import r2_score

model = LinearRegression() model.fit(X_train, y_train)

LaTeX
LaTeX

n = X_test.shape[0] p = X_train.shape[1] # predictors, excluding intercept

if n > p + 1: adjusted_r2 = 1 - (1 - r2) * (n - 1) / (n - p - 1) else: adjusted_r2 = None

print("R-squared:", r2) print("Adjusted R-squared:", adjusted_r2) ```

Important: This code demonstrates the arithmetic, but applying the classic adjusted R² formula to a test-set R² is not the usual inferential interpretation of adjusted R². The standard formula is normally reported for an OLS fit on its estimation sample. For model selection, use validation or cross-validation performance on unseen folds rather than treating test-set adjusted R² as a universal selection metric.

For a training-sample illustration:

```python from sklearn.linear_model import LinearRegression from sklearn.metrics import r2_score

model = LinearRegression() model.fit(X_train, y_train)

r2_train = r2_score(y_train, model.predict(X_train)) n = X_train.shape[0] p = X_train.shape[1]

adjusted_r2_train = ( 1 - (1 - r2_train) * (n - 1) / (n - p - 1) )

print("Training R-squared:", r2_train) print("Training Adjusted R-squared:", adjusted_r2_train) ```

This second example assumes a standard OLS regression with an intercept, and that the feature matrix contains the predictors counted in p.

9. Which one should you use?#

Use R² when:

  • You want a simple measure of fit relative to the mean baseline.
  • You are describing how much target variation a fitted model accounts for.
  • You are comparing models with the same predictors or the same complexity on the same observations.

Use Adjusted R² when:

  • Comparing standard multiple OLS regression models with different numbers of predictors.
  • You want a fit statistic that penalizes unnecessary predictors.
  • You are exploring whether extra features improve in-sample fit enough to justify their degrees of freedom.

For production model selection, do not choose a model solely because its adjusted R² is highest. Use cross-validation or a properly designed validation set, compare MAE/RMSE and business costs, inspect residuals and important segments, and reserve a final test set for an independent evaluation. For time-dependent or grouped data, use time-aware or group-aware splits rather than random splitting.

Key takeaway#

R² measures in-sample fit relative to a mean baseline; Adjusted R² adds a penalty for the number of predictors. R² cannot decrease when predictors are added to a nested OLS model on the same data, while adjusted R² can decrease if the new feature adds too little value. Use adjusted R² for comparing compatible linear models, but rely on unseen-data validation and practical error metrics to select production models.

Interview answer: R² measures the proportion of target variation accounted for by a regression model relative to a mean baseline. Adjusted R² modifies it using sample size and predictor count, discouraging unnecessary features. R² always stays the same or increases when predictors are added to a nested OLS model on the same data; adjusted R² can go down. Neither replaces validation on unseen data.

Related questions

Explore other topics:Deep LearningMLOps