Coefficient of determination

Also known as: R-squared

On this page 7

The coefficient of determination, usually written R-squared or R², is a regression metric that measures the proportion of variance in the target variable that a model explains, relative to a baseline that always predicts the mean. In model evaluation for Artificial intelligence and machine learning, it is one of the standard scores reported for regression tasks alongside mean squared error and mean absolute error.

A value of 1 means perfect predictions, a value of 0 means the model is no better than the mean, and on held-out data the score can be negative when the model performs worse than that simple baseline. Because it is scale-free, R-squared allows rough comparison across targets measured in different units.

How R-squared is calculated

R-squared is defined as one minus the ratio of residual error to total variance. The residual sum of squares adds up the squared differences between actual values and predictions. The total sum of squares adds up the squared differences between actual values and their mean. The formula is R² = 1 − SS_res / SS_tot.

This construction makes R-squared a normalized version of mean squared error: dividing the model’s squared error by the variance of the target removes the units. For ordinary least squares with an intercept, evaluated on the training data, R-squared also equals the square of the Pearson correlation between predictions and actual values, which explains the name. That equivalence does not hold for other models or for test data.

The table below defines each component and its role in the calculation, using standard notation for actual values, predictions and the sample mean.

ComponentDefinitionRole
Residual sum of squaresSum of (actual − predicted)²Error the model leaves unexplained
Total sum of squaresSum of (actual − mean)²Error of the mean-only baseline
Explained sum of squaresSum of (predicted − mean)²Variation captured by the model
R-squared1 − residual / totalShare of variance explained
Components of the R-squared formula

Interpreting R-squared values

The meaning of an R-squared value depends strongly on the domain. In controlled physical systems, values above 0.95 are common, while in social science, finance or human behavior, a value of 0.2 to 0.4 may represent a useful model because the outcome is inherently noisy.

R-squared valueInterpretationTypical context
1.0Perfect fit, often a warning signPossible data leakage or overfitting
0.9 to 0.99Very high explained variancePhysical measurements, engineering systems
0.5 to 0.9Substantial explained varianceDemand forecasting, pricing models
0.1 to 0.5Modest but potentially usefulBehavioral, economic, medical outcomes
0No better than predicting the meanUninformative features or wrong model
Below 0Worse than predicting the meanPoor generalization on test data
How to read typical R-squared values

A high score on training data says little about generalization. The test-set R-squared is the figure that matters for deployment, and a large gap between training and test values is a classic sign of overfitting.

Several variants of R-squared address its known weaknesses, and it is usually reported together with error metrics expressed in the original units. Each answers a slightly different question about model quality.

MetricUnitsWhat it answersKey caveat
R-squaredUnitlessHow much variance is explainedGrows with added features in training
Adjusted R-squaredUnitlessVariance explained per feature usedAssumes linear regression framework
Mean squared errorSquared target unitsAverage squared errorHard to interpret directly
Root mean squared errorTarget unitsTypical error sizeSensitive to outliers
Mean absolute errorTarget unitsAverage absolute errorIgnores error direction and variance
R-squared compared with related metrics

Adjusted R-squared penalizes each additional predictor, so it rises only when a new feature improves the fit more than chance would. Predicted R-squared, computed from leave-one-out cross-validation residuals, estimates performance on new data and is a useful check against overfitting in small datasets.

Using R-squared in machine learning practice

In machine learning workflows, R-squared is most useful as a quick, comparable summary across models trained on the same target. Common libraries compute it on held-out folds during cross-validation, where values can legitimately fall below zero.

  • Report it on validation or test data, not only on training data.
  • Pair it with RMSE or MAE so stakeholders see the error in real units.
  • Compare models on the same dataset, because R-squared depends on target variance.
  • Inspect residual plots, since a good score can hide systematic bias in some ranges.
  • Use adjusted or cross-validated R-squared when comparing models with different feature counts.

For multi-output regression, libraries usually offer a choice between averaging scores across outputs or weighting them by output variance. The choice should be stated, because it can change the reported figure noticeably.

Limitations and common misconceptions

R-squared is widely misread as a measure of correctness or causality, which it is not. It describes only how much variance the predictions track, and it says nothing about whether the model is unbiased, well specified or appropriate for decisions.

MisconceptionRealityBetter practice
High R-squared means a good modelLeakage or overfitting can inflate itValidate on truly held-out data
Low R-squared means a useless modelNoisy targets cap achievable scoresJudge against domain baselines
R-squared cannot be negativeTest-set values can fall below zeroTreat negatives as worse than the mean
Scores compare across datasetsDepends on each target’s varianceCompare only on the same data
It measures causal strengthIt reflects association onlyUse causal methods for causal claims
Common misconceptions about R-squared

R-squared is also sensitive to outliers and to the range of the data. A dataset with a wide spread of target values can produce a high score even when errors are large in absolute terms, which is why error metrics in real units should always accompany it.

The idea in brief

Imagine guessing the price of houses. The simplest guess is the average price for every house. That guess is often far off.

A model tries to do better by using facts such as size and location. The coefficient of determination tells you how much better the model is than the average guess. A score of 0.8 means the model accounts for about 80 percent of the variation in prices. A score of zero means it adds nothing.

It is a handy summary, but it is not the whole story. You still need to know how large the typical mistake is.

A practical scenario

An energy utility builds a regression model to predict hourly electricity demand for a city from temperature, time of day, day of week and holiday flags. On five years of training data, the gradient-boosted model reaches an R-squared of 0.97, which looks excellent.

The analytics team then evaluates the model on the most recent year, which it held out completely. The test-set R-squared is 0.91, and the root mean squared error is about 3 percent of average demand. The gap reveals mild overfitting, which the team reduces by limiting tree depth.

Residual plots show that the model underestimates demand during heat waves, when errors are largest. The team adds a feature for consecutive hot days, and the final model improves peak-hour accuracy, which helps the utility schedule reserve generation more reliably.