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

Overfitting

Fit familiar points. Check predictions on held-out points.

Degree 1 is a straight line; higher degrees allow more flexible curves. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Scales each split’s own fixed deviations from the underlying signal. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Fitted curve

Training circles determine the fit; held-out squares measure its predictions. The dashed curve is the underlying signal before noise.

● Training: 12■ Held-out: 11━ Fitted curve┄ Underlying signal
-4.504.5-101yx

Axes stay fixed across degrees for this scenario and noise: y -4.5 to 4.5. Changing scenario or noise can change this range. Plot lines join 120 evaluated x positions; exact predictions at every observed point appear below.

Training MSE

Average squared error on 12 points used for fitting.

≈ 0.20037

mean((observed y − predicted y)²)

Fits minimize training error plus a fixed tiny coefficient penalty.

Held-out MSE

Average squared error on 11 points withheld from fitting.

≈ 0.11187

Same error formula; different points.

Lower here means better predictions on this set.

Held-out − train

Difference between the two finite-set errors.

≈ -0.08851

Held-out MSE − training MSE

Negative is possible; a positive gap alone is not proof of overfitting.

Loss by polynomial degree

Every degree uses the same current points and fitting rule. Read both losses; degree and gap alone do not diagnose overfitting.

● Solid: training MSE■ Dashed: held-out MSE
00.110.2214812MSEPolynomial degree

The loss scale stays fixed when degree changes. The chart summarizes these two finite sets; it does not guarantee an error on future data.

These fixed, illustrative splits use different noise patterns and are not an unbiased estimate of future error. In real work, choose complexity on validation data and reserve an untouched test set for final evaluation. Repeatedly choosing from test error leaks evaluation information.

All degree losses
Same points and noise at all degrees. MSE is in squared y units; values are rounded. Scientific notation preserves tiny nonzero errors.
DegreeTraining MSEHeld-out MSE
1 (current)0.200370.11187
20.165000.06333
30.095650.00796
40.078910.00665
50.075900.00741
60.061990.01345
70.057470.02090
80.048430.04340
90.044540.03177
100.043000.07228
110.030480.18521
120.030390.17962
All point predictions
Observed y = signal + Noise amplitude × fixed deviation. Residual = observed − predicted. MSE averages the squared residuals within each split.
Split / pointxObserved yPredicted yResidual²
Training 1-0.96-0.47000-0.778660.09527
Training 2-0.78-1.20847-0.650760.31105
Training 3-0.62-0.76406-0.537060.05153
Training 4-0.45-0.38803-0.416270.00080
Training 5-0.27-0.77381-0.288360.23566
Training 6-0.080.29556-0.153350.20152
Training 70.110.19366-0.018350.04495
Training 80.311.056370.123770.86974
Training 90.50.356870.258780.00962
Training 100.680.624340.386680.05648
Training 110.84-0.123850.500370.38966
Training 120.970.220970.592750.13822
Held-out 1-0.88-0.91609-0.721810.03774
Held-out 2-0.7-0.86298-0.593910.07240
Held-out 3-0.54-0.85616-0.480220.14133
Held-out 4-0.36-0.52334-0.352320.02925
Held-out 5-0.18-0.20486-0.224410.00038
Held-out 60.020.31486-0.082300.15773
Held-out 70.220.523840.059820.21532
Held-out 80.410.696880.194830.25206
Held-out 90.590.541350.322730.04779
Held-out 100.760.374090.443530.00482
Held-out 110.910.028870.550110.27169
How the fit is computed

A degree d polynomial is a₀ + a₁x + … + a_d x^d. Only training points determine these coefficients. A fixed tiny penalty makes the fit unique even when coefficients outnumber training examples; its size does not jump with degree. The fitting objective is sum of squared training errors + 10⁻⁷ × (0.1a₀² + a₁² + … + a_d²). MSE displays the average squared prediction error alone, excluding that penalty. Numerical QR fitting avoids unstable normal equations.

The common illustrative signal is 0.58 sin(π(x + 0.12)) + 0.34x − 0.24x². Each preset keeps its original x positions and fixed train/held-out noise patterns. Noise zero removes deviations, but a finite polynomial need not match this signal exactly. The plotted signal is a teaching reference unavailable for real unknown data.

Balanced Split, degree 1, noise 0.34. Training MSE 0.20037; held-out MSE 0.11187; held-out minus train -0.08851. Only training points fit the curve.