AI Grounds

Open AI Grounds on a desktop

These interactive lessons need a larger screen. Please continue on a desktop or laptop computer.

Guided discovery

R Squared & Residual Diagnostics

Compare the score; inspect what the residuals hide.

Your dataset

Eight constructed observations, not random samples. Scenario and Residual scale change the data. Model changes predictions; View changes only the coordinates.

R² 0.690 · SSE 72.00 · SST 232.00. Candidate: ŷ = 2.0X + 10.0. Observed mean 10.00.

-2410162226-3-113Observed YX

Gray circles = observations; indigo line = selected candidate; orange vertical segments = signed residuals. Switch to Residuals to put those gaps on their own axis. A ×2 marker represents two observations at the same coordinates; none are discarded.

Construct observations around the same refitted line; this changes the data, not just a chart zoom. All patterns vanish at zero. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

R² = 1 − SSE/SST = 1 − 72.00/232.00 = 0.690. Signed residual sum 0.00.

SSE sums squared observed-minus-predicted gaps. SST sums squared observed-minus-mean gaps: the error of Mean only. Both use squared Y units; R² has no units and is not a fraction of correctly classified observations.

R²

Squared-error reduction relative to the observed mean.

0.690

1 − SSE/SST

A score alone cannot validate the model.

Squared error

Sum of squared residuals of the current candidate.

72.00

Σ(observed Y − predicted Y)²

Mean benchmark

Squared error of predicting observed mean Y for every pair.

232.00

Σ(observed Y − mean Y)²

Residual patterns suggest what to investigate; they do not establish a generating law, causality, or accurate predictions on new observations. Even spread is a designed contrast, not proof of random errors.

Eight pairs and residuals
All eight identities remain present, including coincident pairs. Mean Y = 10.00.
PointXObserved YPredicted YResidualSquared gapSquared mean gap
1-37.004.00+3.009.009.00
2-31.004.00−3.009.0081.00
3-15.008.00−3.009.0025.00
4-111.008.00+3.009.001.00
5115.0012.00+3.009.0025.00
619.0012.00−3.009.001.00
7313.0016.00−3.009.009.00
8319.0016.00+3.009.0081.00
Construction and conventions

Observed Y = 10 + 2X + Residual scale × pattern. The patterns each have signed sum 0, X-weighted sum 0 and squared sum 72. Refitting ordinary least squares with an intercept therefore gives slope 2 and intercept 10 for every displayed scenario and scale. The observed mean is 10. The exact engine recomputes coefficients from the paired sums.

For Fitted line, SSE = 72scale² and SST = 160 + 72scale². At zero scale, SSE is 0 and R² 1; all patterns coincide. Mean only has SSE = SST, R² 0. Shifted line deliberately adds 10 to the refitted intercept, yielding SSE = 72scale² + 800. It is a poor candidate, not an optimized fit.

The raw formula 1 − SSE/SST can be negative and cannot exceed 1 when SST is positive. For a fit with an intercept on its fitting data, the mean-only predictor is an available candidate, so the least-squares score is nonnegative. If all observed Y were constant, SST would be zero and the raw ratio undefined; this page’s constructed datasets always have SST ≥160. No finite replacement is used.

Observed Y and Residual views have separate fixed vertical scales. Identical coordinates are grouped with a multiplicity label, preserving all rows. Full-precision arithmetic precedes two-decimal sums and three-decimal R² display. There are no automatic optimizers, hypothesis tests, causal estimates or held-out performance results.

Conventions and sources

Curved residuals suggest checking the mean-function form. Widening spread suggests checking variability, but mean-function misspecification can also produce that appearance. One residual plot and a high R² are insufficient to validate a model; these deterministic examples show contrasts rather than diagnose a real population.

NIST · R² and graphical residual analysis
NIST · Functional-pattern warnings
NIST · Spread warnings and limitations
scikit-learn · Negative scores and constant-target convention