Notes

R-Squared (Coefficient of Determination)

R-squared is a quick way to describe how well a regression model “tracks” the ups and downs in your data. If your predictions rise when the real values rise (and fall when they fall), R-squared tends to be higher.

What it measures

R-Squared (Coefficient of Determination) measures the fraction of variability in the target variable that is explained by the model’s predictions. In ordinary least squares regression with an intercept, it’s commonly written as:

R² = 1 − (SS_res / SS_tot)

where SS_res is the sum of squared residuals (prediction errors) and SS_tot is the total sum of squares (how spread out the true values are around their mean). An R² of 0.70 means the model explains about 70% of the variance in the target, relative to a baseline that always predicts the mean.

How to interpret it (and common surprises)

R² is often between 0 and 1, but it can be negative (meaning the model is worse than predicting the mean), especially on test data or if the model lacks an intercept.

  • Higher R² usually means a better fit to the observed targets.
  • It does not mean the model is “correct,” causal, or that predictions are accurate in absolute terms.
  • Adding more features can inflate R² even if they’re useless; adjusted R² penalizes extra predictors.
Practical examples

If you predict house prices from size and location and get R² = 0.85, your model captures most price variation across homes. In exam-score prediction, R² = 0.20 might still be realistic because many unmeasured factors (sleep, stress) drive scores.

Why it matters in ML workflows

R² is a standard regression metric in tools like scikit-learn (r2_score). It’s useful for quick model comparison, but it should be paired with error metrics like MAE/RMSE and evaluated on held-out data to avoid being misled by overfitting.

R-Squared (Coefficient of Determination) measures the proportion of variance in a continuous target variable explained by a regression model, typically computed as 1 minus the ratio of residual sum of squares to total sum of squares. Values closer to 1 indicate better in-sample fit, but it can be misleading with nonlinearity, outliers, or added predictors (use adjusted R² for comparison). Example: R² = 0.80 means the model explains 80% of target variability.

Imagine you’re trying to guess someone’s test score from how many hours they studied. If your guesses are very close to the real scores, you’d say your method explains the scores well. R-squared (Coefficient of Determination) is a number that tells you how well a prediction model explains what happened in the data.

It ranges from 0 to 1: 0 means the model explains none of the ups and downs in the outcome, and 1 means it explains them perfectly. In AI and machine learning (especially regression), it’s a quick way to judge how well a model fits the data.