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

Linear Regression Line Fitting

Move a line; explain slope, intercept and vertical residuals.

Your dataset

Five fixed toy observations. Move only the solid line: drag the square at X = 0 for Intercept, the diamond at X = 4 for Slope, or the solid line vertically to shift it. The circles stay fixed. Use the native controls below for exact or keyboard edits.

Your line: ŷ = 0.0X + 2.0. SSE = 20.00. Point 3: X = 2, observed Y = 3, predicted Y = 2.00, residual = +1.00.

01234-404812YX

Solid indigo = your line; circles = fixed observations, with Point 3 outlined. Orange segments are signed vertical gaps at each X; their lengths show absolute residual size. A handle can coincide with an observation; moving it still changes only the line.

Predicted Y change per one X unit. The diamond pivots the line about X = 0. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Predicted Y at X = 0. The square or solid line shifts every prediction equally. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Build the vertical residual

Point 3: observed 3 − predicted 2.00 = +1.00. Squared contribution = 1.00.
SSE = sum of all five squared residuals = 20.00. Signed residual sum = +8.00.

Positive residuals lie above the line; negative ones below it. Residuals are differences, not necessarily data mistakes. Signed gaps can cancel; their squares do not. SSE uses squared Y units and describes fit to these points.

Slope

Change in predicted Y per one X unit.

0.0

Hold Intercept fixed → pivot about X = 0

Intercept

Predicted Y at X = 0.

2.0

Hold Slope fixed → parallel vertical shift

This is a descriptive fit to five fixed toy pairs. Neither a small SSE nor the fitted slope establishes causation or guarantees accuracy on new observations.

Pair and residual table
Your solid candidate. All observed X and Y values stay fixed until you switch datasets. Residual = observed minus predicted at the same X.
PointXObserved YPredicted YResidualSquared
1022.000.000.00
2132.00+1.001.00
3232.00+1.001.00
4352.00+3.009.00
5452.00+3.009.00
Conventions and sources

Least squares with an intercept minimizes Σ[observed Y − (Slope × X + Intercept)]² over all straight lines, not just the editable tenths grid. Slope = Σ[(X − mean X)(Y − mean Y)] / Σ(X − mean X)²; Intercept = mean Y − Slope × mean X. The five distinct X values make the denominator positive and the minimum unique. The reference parameters happen to be tenths for these prepared datasets; calculations use full precision before display.

Normality is not required to compute this descriptive minimum. No regression inference, causal estimate, loss landscape, R²/residual diagnostic model or train/test guarantee is supplied here. Straight is an exact constructed boundary where the reference residuals are zero; the scattered examples retain nonzero residuals.

NIST · Least-squares criterion and straight-line coefficients
OpenStax · Signed vertical residuals and line interpretation