Notes

R-Squared (Coefficient of Determination)

When you build a regression model, you usually want a quick sense of whether it’s capturing real signal or just guessing around the average. R-squared gives that “how much did we explain?” feeling in a single number.

What R-squared measures

R-squared (Coefficient of Determination) compares your model to a simple baseline that always predicts the mean of the target. It is computed 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 much the true values vary around their mean). An R² of 0 means “no better than predicting the mean.” An R² of 1 means perfect predictions. It can be negative if the model is worse than the mean baseline (common when evaluating on new data).

How it shows up in real work

In house price prediction, an R² of 0.75 suggests the model explains about 75% of the variation in prices in the evaluation set. In demand forecasting, a low R² can indicate missing drivers (promotions, seasonality) even if errors look “small” in absolute terms for low-volume items.

  • Scale-free comparison: useful when targets are in dollars vs. units, because it’s a ratio.
  • Model debugging: negative R² is a strong warning sign of poor generalization or leakage issues.
Why it matters (and common traps)

R² helps you judge whether added features or a more complex model actually improve explanatory power. But it doesn’t tell you whether errors are acceptable in business terms, and it can look artificially good if evaluated on training data. In scikit-learn, you’ll see it via sklearn.metrics.r2_score(y_true, y_pred) or the .score() method on many regressors.

R-Squared (Coefficient of Determination) is a regression metric that measures the proportion of variance in the target variable explained by a model, relative to a baseline that predicts the target mean. It is commonly computed as 1 − (sum of squared residuals / total sum of squares), yielding 1 for perfect fit and 0 for no improvement over the mean (and it can be negative if worse). It matters for quickly comparing explanatory fit across regression models.

Imagine you’re trying to guess people’s heights from their shoe sizes. If your guesses are all over the place, your “rule” isn’t very helpful. If your guesses land close to the real heights, it’s doing a good job. R-Squared (Coefficient of Determination) is a simple score that tells you how well a prediction model explains what you’re trying to predict.

In regression (predicting a number, like house price), R-Squared is often described as “how much of the variation” in the real values your model can account for. An R-squared near 1 means the model fits the data well; near 0 means it doesn’t improve much over a basic average guess.