Approximation & signals

Least Squares Regression Explorer

Fits a least-squares polynomial of degree 0 to 8 to up to 21 points you place and drag, by an orthogonal (QR) factorisation in a scaled or a raw x basis. It shows the curve for every degree at once, the residuals, held-out points and their error, the exact leave-one-out error, each point's leverage and Cook's distance, the best degree by each error, and the condition estimate with the digits lost by the factorisation and by the normal equations, with five challenges. For learning how to choose a model that predicts new points rather than one that only fits the old ones.

Last updated

Calculator overview

Inputs and outputs

This summary comes from the calculator's published input and output contract.

Inputs

Point 9 x (required)
About this input

The x of point 9, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 9 is among the points used.

Default 8 Range -25 to 25
Point 1 y (required)
About this input

The y of point 1, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 1 is among the points used.

Default 2.3 Range -1000000000 to 1000000000
Point 7 x (required)
About this input

The x of point 7, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 7 is among the points used.

Default 6 Range -25 to 25
Point 8 x (required)
About this input

The x of point 8, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 8 is among the points used.

Default 7 Range -25 to 25
Point 12 y (required)
About this input

The y of point 12, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 12 is among the points used.

Default 7.5 Range -1000000000 to 1000000000
Point 13 y (required)
About this input

The y of point 13, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 13 is among the points used.

Default 8 Range -1000000000 to 1000000000
Point 10 y (required)
About this input

The y of point 10, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 10 is among the points used.

Default 6.5 Range -1000000000 to 1000000000
Point 11 y (required)
About this input

The y of point 11, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 11 is among the points used.

Default 7 Range -1000000000 to 1000000000
Point 6 x (required)
About this input

The x of point 6, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 6 is among the points used.

Default 5 Range -25 to 25
Point 2 x (required)
About this input

The x of point 2, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 2 is among the points used.

Default 1 Range -25 to 25
Point 20 x (required)
About this input

The x of point 20, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 20 is among the points used.

Default 19 Range -25 to 25
Point 18 x (required)
About this input

The x of point 18, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 18 is among the points used.

Default 17 Range -25 to 25
Point 19 x (required)
About this input

The x of point 19, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 19 is among the points used.

Default 18 Range -25 to 25
Point 4 x (required)
About this input

The x of point 4, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 4 is among the points used.

Default 3 Range -25 to 25
Point 5 x (required)
About this input

The x of point 5, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 5 is among the points used.

Default 4 Range -25 to 25
Point 21 x (required)
About this input

The x of point 21, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 21 is among the points used.

Default 20 Range -25 to 25
Point 3 x (required)
About this input

The x of point 3, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 3 is among the points used.

Default 2 Range -25 to 25
Point 5 y (required)
About this input

The y of point 5, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 5 is among the points used.

Default 4.35 Range -1000000000 to 1000000000
Point 6 y (required)
About this input

The y of point 6, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 6 is among the points used.

Default 4.4 Range -1000000000 to 1000000000
Point 3 y (required)
About this input

The y of point 3, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 3 is among the points used.

Default 3.1 Range -1000000000 to 1000000000
Point 4 y (required)
About this input

The y of point 4, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 4 is among the points used.

Default 3.1 Range -1000000000 to 1000000000
Point 9 y (required)
About this input

The y of point 9, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 9 is among the points used.

Default 6 Range -1000000000 to 1000000000
Polynomial degree (required)
About this input

The degree of the polynomial fitted to the points, from 0 (a constant) to 8. Choose it with the degree chips under the plot; the player steps through every degree.

Default 1 Range 0 to 8
Point 7 y (required)
About this input

The y of point 7, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 7 is among the points used.

Default 5.2 Range -1000000000 to 1000000000
Point 8 y (required)
About this input

The y of point 8, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 8 is among the points used.

Default 5.25 Range -1000000000 to 1000000000
Point 21 y (required)
About this input

The y of point 21, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 21 is among the points used.

Default 12 Range -1000000000 to 1000000000
Point 16 y (required)
About this input

The y of point 16, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 16 is among the points used.

Default 9.5 Range -1000000000 to 1000000000
Point 17 y (required)
About this input

The y of point 17, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 17 is among the points used.

Default 10 Range -1000000000 to 1000000000
Point 14 y (required)
About this input

The y of point 14, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 14 is among the points used.

Default 8.5 Range -1000000000 to 1000000000
Point 15 y (required)
About this input

The y of point 15, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 15 is among the points used.

Default 9 Range -1000000000 to 1000000000
Point 2 y (required)
About this input

The y of point 2, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 2 is among the points used.

Default 2.3 Range -1000000000 to 1000000000
Point 20 y (required)
About this input

The y of point 20, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 20 is among the points used.

Default 11.5 Range -1000000000 to 1000000000
Point 18 y (required)
About this input

The y of point 18, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 18 is among the points used.

Default 10.5 Range -1000000000 to 1000000000
Point 19 y (required)
About this input

The y of point 19, from -1,000,000,000 to 1,000,000,000. Drag the point on the plot, or type it in the point's popover. Used only while point 19 is among the points used.

Default 11 Range -1000000000 to 1000000000
Point 16 held out (required)
About this input

Whether point 16 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 17 held out (required)
About this input

Whether point 17 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 14 held out (required)
About this input

Whether point 14 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 15 held out (required)
About this input

Whether point 15 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 2 held out (required)
About this input

Whether point 2 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 20 held out (required)
About this input

Whether point 20 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 18 held out (required)
About this input

Whether point 18 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 19 held out (required)
About this input

Whether point 19 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 13 held out (required)
About this input

Whether point 13 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Challenge number (required)
About this input

Pick a challenge from 1 to 5, or 0 for none. A challenge fixes its own points and settings and leaves one or two controls to you.

Default 0 Range 0 to 5
Number of points (required)
About this input

How many points the fit uses, from 2 to 21. Only the first this many points are used; the others keep their values but are ignored and not checked. Add or remove a point with the buttons on the plot.

Default 8 Range 2 to 21
Basis (required)
About this input

How x enters the polynomial: Scaled (x shifted and scaled so the points span -1 to 1, the default, which keeps the fit well conditioned) or Raw x (powers of x itself, up to degree 5). The curve is the same in both; only the coefficients and the conditioning change.

Default Scaled Allowed Scaled, Raw x
Predicted best degree
When omitted Blank
About this input

Challenge 1 only: your prediction of the degree, from 0 to 8, whose curve would best predict a point it has not seen. Blank until you predict; 0 is a real prediction.

Default Not set Range 0 to 8
Point 11 held out (required)
About this input

Whether point 11 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 12 held out (required)
About this input

Whether point 12 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 1 held out (required)
About this input

Whether point 1 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 10 held out (required)
About this input

Whether point 10 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 12 x (required)
About this input

The x of point 12, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 12 is among the points used.

Default 11 Range -25 to 25
Point 13 x (required)
About this input

The x of point 13, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 13 is among the points used.

Default 12 Range -25 to 25
Point 10 x (required)
About this input

The x of point 10, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 10 is among the points used.

Default 9 Range -25 to 25
Point 11 x (required)
About this input

The x of point 11, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 11 is among the points used.

Default 10 Range -25 to 25
Point 16 x (required)
About this input

The x of point 16, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 16 is among the points used.

Default 15 Range -25 to 25
Point 17 x (required)
About this input

The x of point 17, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 17 is among the points used.

Default 16 Range -25 to 25
Point 14 x (required)
About this input

The x of point 14, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 14 is among the points used.

Default 13 Range -25 to 25
Point 15 x (required)
About this input

The x of point 15, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 15 is among the points used.

Default 14 Range -25 to 25
Point 1 x (required)
About this input

The x of point 1, from -25 to 25. Drag the point on the plot, or type it in the point's popover. Used only while point 1 is among the points used.

Default 0 Range -25 to 25
Point 4 held out (required)
About this input

Whether point 4 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 5 held out (required)
About this input

Whether point 5 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 21 held out (required)
About this input

Whether point 21 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 3 held out (required)
About this input

Whether point 3 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 8 held out (required)
About this input

Whether point 8 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 9 held out (required)
About this input

Whether point 9 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 6 held out (required)
About this input

Whether point 6 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1
Point 7 held out (required)
About this input

Whether point 7 is fitted (0) or held out (1). A held-out point does not pull the curve; its error shows how well the curve predicts a point it has not seen. Tap the point to switch.

Default 0 Range 0 to 1

Outputs

Model Status
About this output

OK, CHECK: (the fit is shown but needs care: too few different x positions, the raw basis limit, nearly dependent columns, a fit too ill-conditioned to trust, or a curve forced through a point so the leave-one-out error cannot be computed) or NOT VALID: (an input cannot be used; the results are empty), with the reason.

No unit declared
Largest Cook's distance
About this output

The largest Cook's distance among the fitted points at the selected degree: how far the fit would move if that point were left out. Blank when none can be computed.

No unit declared
Leave-one-out RMSE
About this output

The leave-one-out error: the root-mean-square error at each fitted point of the curve fitted without that point, from the exact shortcut for least squares (no refits). Blank when the curve is forced through a fitted point.

No unit declared
Normal equations agree to (digits)
About this output

How many significant digits the coefficients from the normal equations share with those from the QR factorisation, as measured (16 when they agree exactly).

No unit declared
Formula module versions
About this output

The formula modules this lab's model uses and their versions.

No unit declared
Model version
About this output

The version of this lab's model.

No unit declared
Held-out points
About this output

The number of points used that are held out.

No unit declared
Fitted points
About this output

The number of points used that are fitted (not held out).

No unit declared
Fitted curves: 101 samples for every degree (blank where a degree is not usable)
About this output

The fitted curve for every degree at 101 evenly spaced x across the plot: x, then one column per degree from 0 to 8. A column is blank when its degree cannot be used. The page draws the selected degree and steps through the others.

No unit declared
Straight-line slope
About this output

The slope of the straight-line (degree 1) fit, in y per unit of x, whatever degree is selected. Blank when a straight line cannot be fitted.

No unit declared
Influential points
About this output

How many fitted points have a Cook's distance of 1 or more at the selected degree (a rule of thumb for an influential point, not a test).

No unit declared
Held-out RMSE
About this output

The root-mean-square error of the curve at the held-out points: how well it predicts points it was not fitted to. Blank with no held-out point.

No unit declared
Normal equations
About this output

OK, or CHECK when the normal equations broke down (a pivot was not positive). Blank when the selected degree cannot be used.

No unit declared
View x to
About this output

The right edge of the plot in x, for drawing only: from the points with a margin, or the challenge's fixed view.

No unit declared
Training RMSE
About this output

The root-mean-square residual over the fitted points at the selected degree: how closely the curve passes the points it was fitted to. It never rises as the degree goes up.

No unit declared
Scaling half-range
About this output

Half the x range of the points used (1 when every x is the same): the scale of the scaled basis. Blank in the raw basis.

No unit declared
View y from
About this output

The bottom edge of the plot in y, for drawing only: from the points with a margin, or the challenge's fixed view.

No unit declared
View y to
About this output

The top edge of the plot in y, for drawing only: from the points with a margin, or the challenge's fixed view.

No unit declared
View x from
About this output

The left edge of the plot in x, for drawing only: from the points with a margin, or the challenge's fixed view.

No unit declared
Degree used
About this output

The degree actually fitted (a challenge may fix it).

No unit declared
Points at the selected degree
About this output

One row per point used: its number, x and y, whether it is fitted or held out, then at the selected degree the fitted value, the residual, the leverage, Cook's distance, the leave-one-out residual, the influential flag and the marker size for the plot.

No unit declared
Points solved
About this output

The number of points actually solved (a challenge may fix it).

No unit declared
Scaling centre
About this output

The centre of the x range of the points used: the shift of the scaled basis. Blank in the raw basis.

No unit declared
R squared
About this output

R squared at the selected degree: the share of the variation of the fitted points' y that the curve explains (centred form). 0 at degree 0; blank when every fitted y is the same.

No unit declared
Residual standard error
About this output

The residual standard error at the selected degree: the square root of the residual sum of squares over the number of fitted points less the number of coefficients. Blank with too few fitted points.

No unit declared
Coefficient 8
About this output

The coefficient of power 8 of the fitted polynomial at the selected degree: of t^8 in the scaled basis (t is x less the scale centre, over the scale half-range), of x^8 in the raw basis. Blank above the selected degree or when that degree cannot be used.

No unit declared
Challenge goal
About this output

What the selected challenge asks.

No unit declared
Challenge feedback
About this output

The prompt while challenge 1 waits for a prediction, then a hint, or the explanation once met.

No unit declared
Leave-one-out pick note
About this output

OK; CHECK when two or more degrees tie within one part in a million (the lowest is shown); CHECK when no degree has a leave-one-out error (the pick is blank).

No unit declared
Challenge result
About this output

No challenge selected, MET or NOT MET.

No unit declared
Challenge score
About this output

100 when the selected challenge is met, else 0.

No unit declared
Challenge measured value
About this output

The value the selected challenge scores: the prediction minus the best degree (1), the held-out error (2), the straight line's slope (3), the straight line's distance from the target (4) or the leave-one-out error (5). Blank while challenge 1 waits for a prediction.

No unit declared
Basis used
About this output

The basis actually used (a challenge may fix it).

No unit declared
AIC
About this output

The Akaike information criterion of the selected fit; lower is better when degrees are compared on the same points. Blank when the residuals are at rounding level.

No unit declared
Adjusted R squared
About this output

R squared adjusted for the number of coefficients, so a higher degree is not rewarded for free. Blank with too few fitted points or when every fitted y is the same.

No unit declared
Best degree by leave-one-out error
About this output

The degree with the lowest leave-one-out error among the degrees that have one; on a tie the lowest such degree.

No unit declared
Held-out pick note
About this output

No points are held out when every point is fitted (the pick is blank); otherwise OK; CHECK when two or more degrees tie within one part in a million (the lowest is shown); CHECK when points are held out but no degree has a held-out error (the pick is blank).

No unit declared
Best degree by held-out error
About this output

The degree with the lowest held-out error among the degrees that have one; on a tie the lowest such degree. Blank with no held-out point.

No unit declared
Condition estimate
About this output

About how much the selected fit can magnify rounding errors in this basis: a condition number estimated after scaling each column, within a factor of the degree + 1 of the usual value. A fit above 1,000,000 is not shown.

No unit declared
Coefficient 4
About this output

The coefficient of power 4 of the fitted polynomial at the selected degree: of t^4 in the scaled basis (t is x less the scale centre, over the scale half-range), of x^4 in the raw basis. Blank above the selected degree or when that degree cannot be used.

No unit declared
Coefficient 3
About this output

The coefficient of power 3 of the fitted polynomial at the selected degree: of t^3 in the scaled basis (t is x less the scale centre, over the scale half-range), of x^3 in the raw basis. Blank above the selected degree or when that degree cannot be used.

No unit declared
Coefficient 2
About this output

The coefficient of power 2 of the fitted polynomial at the selected degree: of t^2 in the scaled basis (t is x less the scale centre, over the scale half-range), of x^2 in the raw basis. Blank above the selected degree or when that degree cannot be used.

No unit declared
Coefficient 7
About this output

The coefficient of power 7 of the fitted polynomial at the selected degree: of t^7 in the scaled basis (t is x less the scale centre, over the scale half-range), of x^7 in the raw basis. Blank above the selected degree or when that degree cannot be used.

No unit declared
Coefficient 6
About this output

The coefficient of power 6 of the fitted polynomial at the selected degree: of t^6 in the scaled basis (t is x less the scale centre, over the scale half-range), of x^6 in the raw basis. Blank above the selected degree or when that degree cannot be used.

No unit declared
Coefficient 5
About this output

The coefficient of power 5 of the fitted polynomial at the selected degree: of t^5 in the scaled basis (t is x less the scale centre, over the scale half-range), of x^5 in the raw basis. Blank above the selected degree or when that degree cannot be used.

No unit declared
Digits lost (QR)
About this output

About how many significant digits the fit loses to rounding when it is solved by orthogonal (QR) factorisation: the power of ten of the condition estimate, rounded.

No unit declared
Digits lost (normal equations)
About this output

About how many digits the normal equations would lose instead: twice the power of ten of the condition estimate, rounded.

No unit declared
Every degree at a glance
About this output

One row per degree from 0 to 8: its state (OK, or why it cannot be used), the training error, the held-out error, the leave-one-out error, adjusted R squared and the condition estimate.

No unit declared
Coefficient 1
About this output

The coefficient of power 1 of the fitted polynomial at the selected degree: of t^1 in the scaled basis (t is x less the scale centre, over the scale half-range), of x^1 in the raw basis. Blank above the selected degree or when that degree cannot be used.

No unit declared
Coefficient 0
About this output

The constant term of the fitted polynomial at the selected degree. Blank when that degree cannot be used.

No unit declared
Different x among the fitted points
About this output

The number of different x positions among the fitted points. A curve of degree d needs at least d + 1.

No unit declared
This page is provided by LogicCommons for informational purposes only. Results are analysis outputs computed from the inputs you supply and are not professional advice. Verify all inputs and results independently.

LogicCommons is in beta. If a result, label, or reference looks wrong, tell us here; we read every message.

Methodology

Purpose and model boundary

This lab fits a least-squares polynomial of degree 0 to 8 to up to 21 points (x, y) that you place and drag on a plot. Each point is either fitted or held out: a held-out point does not pull the curve, and its error shows how well the curve predicts a point it has not seen. The model factorises the fit once, by modified Gram-Schmidt QR, and from that one factorisation returns the curve for every degree at once. For the selected degree it returns the coefficients, the residuals, the training, held-out and leave-one-out errors, R² and adjusted R², each point's leverage and Cook's distance, and a condition estimate with the digits lost by the QR route and by the normal equations. For every degree it returns a state and its errors, and it names the best degree by the leave-one-out error and by the held-out error. The fit runs in one of two bases: Scaled (x shifted and scaled so the points span -1 to 1) or Raw x (powers of x itself, up to degree 5). Five scored challenges go with it.

It is a lab for learning how to choose a model that predicts new points rather than one that only fits the old ones: why the training error always falls as the degree rises while the error on unseen points does not, how one point far from the middle can swing a fit, and why the choice of basis decides how many digits a fit can lose to rounding. It is not a general regression method. It has one input variable, polynomial models only and at most 21 points, and it does not test whether a polynomial is the right model for real measurements.

The model is the calculation authority. The page sends the values you set to the model and draws only what it returns: the curve of every degree, the fitted values and residual sticks, the dot sizes, the held-out rings, the error-against-degree chart with its minimum and the plot window all come from the model's own tables. The page computes no fit, residual, error, leverage or best degree itself.

Inputs and units

Every input is a pure number or a choice; the lab has no physical units. The slope of a straight line is in y per unit of x.

Input Meaning and unit
Number of points n, a whole number from 2 to 21 (default 8): how many points the fit uses. Only the first n points are used; the others keep their values but are ignored and not checked.
Point 1 to 21 x Each from -25 to 25. Defaults 0, 1, 2, ..., 20 (point i at i - 1). The points need not be in x order.
Point 1 to 21 y Each from -1,000,000,000 to 1,000,000,000. Defaults 2.3, 2.3, 3.1, 3.1, 4.35, 4.4, 5.2 and 5.25 for points 1 to 8, then 2 + 0.5·x for points 9 to 21 (6, 6.5, ..., 12).
Point 1 to 21 role 0 = fitted (default) or 1 = held out.
Polynomial degree d, a whole number from 0 (a constant) to 8 (default 1).
Basis Scaled (default) or Raw x. The curve is the same in both; only the coefficients and the conditioning change.
Challenge number 0 for free exploration, or 1 to 5 to load a challenge.
Your prediction: the best degree Blank (not yet predicted) or a whole number from 0 to 8: your answer for challenge 1. 0 is a real prediction. It is read and checked only in challenge 1.

Every input except the prediction is required.

Where each input is set:

  • On the canvas only: every point's x and y (drag the point, in steps of 0.01; arrow keys move the focused point 0.01 and Shift+arrow 0.1; the point's popover takes an exact value), each point's role (tap or click the point, or Space on the focused point), the number of points (the + point and - point buttons, with a live count), the degree (a chip row from 0 to 8 under the plot), the basis (a Scaled / Raw x chip pair) and your prediction (a chip row from 0 to 8, only in challenge 1). None of these is in the input panel. The role taps and the basis chip appear from the Experiment level on.
  • In the input panel: the challenge number only.

Governing relationships

The least-squares fit. With the fitted points only, the model finds the polynomial p(t) = c₀ + c₁·t + c₂·t² + ... + c_d·t^d that makes the sum of the squared residuals e_i = y_i - p(t_i) as small as possible. Held-out points and points beyond the count carry zero weight: they do not move the curve.

The two bases. In the Raw x basis t = x. In the Scaled basis t = (x - c)/s, with c = (x_min + x_max)/2 the centre and s = (x_max - x_min)/2 the half-range of the points used, fitted and held out alike (s is taken as 1 when every x is the same). The fitted points' t then lie within -1 to 1, and toggling a point's role does not move t. The coefficients multiply powers of t in the Scaled basis and powers of x in the Raw x basis. The Raw x basis is limited to degree 5.

The design columns. Column k (k = 0 to 8) holds t^k at each fitted point and 0 elsewhere, built as running products t^k = t^(k-1)·t. D_k is the length (2-norm) of column k.

Modified Gram-Schmidt on the augmented column. The y values of the fitted points ride along as one more column b. For k = 0, 1, ..., 8 in turn:

  1. r_kk is the length of what is left of column k after the earlier steps. The column is usable when the fitted points have at least k + 1 different x positions, D_k > 0, and r_kk > 1×10⁻¹² · D_k (otherwise the columns are nearly dependent).
  2. q_k = (what is left of column k) / r_kk.
  3. For every later column j: r_kj = q_k · (column j), and column j loses r_kj · q_k.
  4. z_k = q_k · b, and b loses z_k · q_k.

The factorisation is nested: its first d + 1 columns are the QR factorisation of the degree-d fit, so one pass serves all nine degrees.

Coefficients. For each degree d whose columns are all usable, back-substitution from i = d down to 0 gives c_i = (z_i - r_i,i+1·c_i+1 - ... - r_i,d·c_d) / r_ii. In the Scaled basis the straight line's slope in x units is c₁/s; in the Raw x basis it is c₁.

Evaluation by Horner's rule. The model evaluates the curve as (((c_d·t + c_(d-1))·t + ...)·t + c₀), highest power first, for the fitted values at every point and for the curve samples.

The condition estimate. Dividing each column of R by its column length D_k gives the column-equilibrated R of the degree-d fit. The condition estimate κ_d is the infinity-norm condition number of that matrix: the largest row sum of its absolute values times the largest row sum of the absolute values of its inverse. It is about the usual 2-norm condition number, within a factor d + 1. From it:

  • digits lost by QR = κ's power of ten, rounded: round(log₁₀ κ);
  • digits lost by the normal equations = twice that power, rounded: round(2·log₁₀ κ).

Which degrees are usable. Degree d is usable when the fitted points have at least d + 1 different x positions (x values count as different only when they are not exactly equal), the basis is not Raw x with d above 5, all of columns 0 to d are usable, and κ_d ≤ 1,000,000. A fit above that cap is too ill-conditioned to trust and is not shown.

Residuals and the rounding floor. For each usable degree, e_i = y_i - p(t_i) at every point used. RSS is the sum of e_i² over the fitted points, and SSE_held the same over the held-out points. When RSS ≤ (1000 · max(1, κ_d) · u)² · Σ y_i² over the fitted points, with u = 2⁻⁵³ (about 1.1×10⁻¹⁶), or when every fitted y is 0, the fit is exact to rounding: RSS and every fitted point's residual read exactly 0. Held-out residuals keep their computed values.

Leverage. A fitted point's leverage is h_i = q_i,0² + q_i,1² + ... + q_i,d², from the rows of the orthonormal columns q. The leverages add up to d + 1 over the fitted points. A point has leverage one when its h_i ≥ 1 - 1×10⁻⁹: the curve is then forced through it.

Leave-one-out error. The residual of point i under the curve fitted without that point is, exactly for least squares, L_i = e_i / (1 - h_i), so no refit is needed. The leave-one-out error is √(Σ L_i² / n_fit), over the n_fit fitted points. It is undefined when any fitted point has leverage one.

Errors and fit statistics. For the selected degree d:

  • training RMSE = √(RSS / n_fit); held-out RMSE = √(SSE_held / n_held), with n_held held-out points;
  • R² = 1 - RSS/TSS, with TSS the sum of squared deviations of the fitted y from their mean (the centred form); R² is 0 at degree 0 and 1 when the rounding floor fires;
  • adjusted R² = 1 - (1 - R²)·(n_fit - 1)/(n_fit - d - 1);
  • residual standard error = √(RSS / (n_fit - d - 1));
  • the Akaike information criterion, AIC = n_fit · ln(RSS / n_fit) + 2·(d + 1).

Cook's distance. For each fitted point, D_i = e_i² · h_i / ((d + 1) · σ² · (1 - h_i)²), with σ the residual standard error: how far the fit would move if that point were left out. A point with D_i ≥ 1 is flagged influential, a rule of thumb rather than a test.

The best degree. Over the degrees that have a leave-one-out error (and separately over those with a held-out error), m is the smallest value, and every degree whose value v satisfies v - m ≤ 1×10⁻⁶ · v ties with it. The best degree is the lowest degree in that tie set.

The normal equations (Advanced). For comparison, the model also solves the same fit the textbook way: it forms the normal equations G·c = h, with G_jk = (column j)·(column k) and h_j = (column j)·b, factorises G = L·Lᵀ by Cholesky, and solves by forward and back substitution. A Cholesky pivot that is not positive is a breakdown. The agreement is the largest coefficient difference over the largest QR coefficient, read as whole digits: round(-log₁₀ of that ratio), from 0 to 16, and 16 when the two agree exactly.

The plot window and the curve samples. In free play the window spans the points used with a margin of 5% of the x range (at least 0.05) on each side and 15% of the y range above and below; in a challenge it is the challenge's own, so a drag never rescales the plot. Each curve is sampled at 101 evenly spaced x across the window, and a sample far outside the window is held one window height beyond its edge.

Calculation sequence

  1. The model checks your values in the order of the status list under Errors and warnings, up to the challenge number and the prediction.
  2. It fixes the values in use: yours, or in a challenge the challenge's own points, roles, count, degree and basis, except the inputs that challenge leaves to you.
  3. It marks the points used, their roles and weights, counts the fitted points, the held-out points and the distinct fitted x positions, and finds the centre and half-range of the scaled basis.
  4. It builds the nine design columns and runs modified Gram-Schmidt on them with the y column carried along.
  5. For every degree it back-substitutes the coefficients, computes the condition estimate and decides whether the degree is usable and its state.
  6. For every usable degree it evaluates the fitted values by Horner's rule, the residuals, the rounding floor, the leverages and the leave-one-out residuals, and the training, held-out and leave-one-out errors.
  7. It picks the best degree by the leave-one-out error and by the held-out error.
  8. At the selected degree it computes the statistics, Cook's distances, the per-point table and the normal-equations comparison.
  9. It sets the plot window and samples every usable degree's curve across it.
  10. It sets the status and, in a challenge, scores the challenge and withholds what that challenge keeps back.

Outputs and interpretation

  • Fit coefficients 0 to 8: of powers of t (Scaled) or of x (Raw x); blank above the selected degree.
  • Training RMSE, held-out RMSE (blank with no held-out point) and leave-one-out RMSE (blank when the curve is forced through a fitted point).
  • R squared and adjusted R squared, which does not reward a higher degree for free. Blank when every fitted y is the same; adjusted R² is also blank with too few fitted points.
  • Best degree by leave-one-out error and best degree by held-out error, each with a note: OK; CHECK: two or more degrees tie (within 1×10⁻⁶ relative); the lowest is shown; or CHECK: no degree has this error (the pick is blank). With every point fitted, the held-out pick is blank and its note reads No points are held out.
  • Straight-line slope: the slope of the degree-1 fit in y per unit of x, whatever degree is selected.
  • Influential points (Cook's distance of 1 or more) and the largest Cook's distance.
  • Fitted points, held-out points and different fitted x positions (a degree-d curve needs at least d + 1).
  • Condition estimate, digits lost by QR and digits lost by the normal equations; the normal-equations agreement in digits and the normal-equations status (OK, or CHECK: the normal equations broke down (a pivot was not positive)); the residual standard error; the AIC (lower is better when degrees are compared on the same points; blank when the residuals are at rounding level).
  • Scale centre and scale half-range of the Scaled basis (blank in Raw x).
  • Settings used: the number of points, degree and basis actually fitted (a challenge may fix them).
  • Fit frames: 101 x positions across the plot and, for each degree from 0 to 8, the curve there; a column is blank when its degree cannot be used.
  • Point table: for each point used, its x, y and role, then at the selected degree its fitted value, residual, leverage, Cook's distance, leave-one-out residual, influential flag and marker size (1 + 2·h for a fitted point, 1 for a held-out point).
  • Degree table: for each degree from 0 to 8, its state (OK, CHECK: too few different x, CHECK: raw basis limit, CHECK: nearly dependent, CHECK: ill-conditioned, or CHECK: leverage 1, no leave-one-out error), its training, held-out and leave-one-out errors, adjusted R² and condition estimate.

Reading the canvas: the plot draws the points, each fitted point as a dot sized by its leverage and each held-out point as a hollow ring, the selected degree's curve, and a residual stick from each point to its fitted value. The player walks the degrees from 0 to 8, one curve a frame, without changing the selected degree. From the Experiment level a chart draws the training, held-out and leave-one-out errors against the degree, with the minimum marked from the model's best degrees; at the Advanced level the degree table adds the condition column and the conditioning results appear. In challenge 4 a target marker is drawn at the goal's point.

What to take from the lab: the training error never rises as the degree rises, so it cannot choose the degree; the error on points the fit has not seen, held out or left out one at a time, can fall and then rise again, and its minimum is the degree that follows the trend without chasing the noise. A point far from the middle of the x range has a long lever: its leverage and Cook's distance are large, and alone it can swing a straight line. The Scaled basis keeps the columns well apart, so a degree high enough for the shape stays well conditioned, while raw x at a high degree is badly conditioned; and the normal equations lose about twice as many digits as QR.

Challenges

Each challenge loads its own points, roles, count, degree and basis and leaves only the controls it names to you. The model scores each one MET (100) or NOT MET (0) and gives a one-line hint while it is not met. A challenge can be met only while its inputs are valid and the selected degree is usable.

  1. Predict the best degree (introductory). Twelve points follow a wavy trend. Look at the curve for each degree, then predict which degree would best predict a point it has not seen. Met when your prediction is in the tie set of the best degree by the leave-one-out error. The value scored is your prediction minus that best degree.
  2. Fit the test, not the training set (introductory). Five of fifteen points are held out. Choose a degree whose curve predicts them with an error of at most 0.38. Met when the held-out RMSE is at most 0.38.
  3. Tame an outlier (intermediate). The point at the far right is an outlier that tilts the line. Drag the free point so the straight line's slope comes back to between 0.45 and 0.55 (the other points rise 0.5 per step). Met when the slope is within 0.05 of 0.5.
  4. Steer the line (intermediate). Drag the free point so the straight line passes within 0.05 of the target marker at x = -2, y = 2. Met when the line's value at x = -2 is within 0.05 of 2; the value scored is that distance.
  5. Well-conditioned and accurate (advanced). Choose a basis and degree whose fit has a condition estimate of at most 1,000 and a leave-one-out error of at most 0.15. Met when both hold.

Challenge 1 holds back the answer until you predict: while your prediction is blank, the leave-one-out and held-out errors, adjusted R², the residual standard error, the AIC, both best degrees and their notes and the value scored are blank, as are the degree table's held-out, leave-one-out and adjusted R² columns and the point table's leave-one-out residuals, and the chart's held-out and leave-one-out lines and minimum marks are hidden. The curves, the coefficients, the training error, R² and the condition estimate stay, and the challenge prompts you to choose a prediction first. Any prediction, 0 included, reveals everything, met or not. Challenge 2 withholds, until it is met, the leave-one-out error, adjusted R², the residual standard error, the AIC, both best degrees and their notes, and the same three degree-table columns; the held-out error of the current degree stays as feedback. Challenge 5 withholds, until it is met, both best degrees and their notes and the degree table's held-out, leave-one-out, adjusted R² and condition columns; the condition estimate, the digits lost and the leave-one-out error of the current choice stay. Challenges 3 and 4 withhold nothing: the slope and the distance are consequences of your own drag.

Validation and status logic

The status reads the first match in the list under Errors and warnings. The NOT VALID checks read the values you entered, inside a challenge too: a blank, text or fraction in a numeric input fails its check, the point checks cover only the first n points, and the prediction is checked only in challenge 1. The CHECK items test the selected degree on the values in effect after a challenge has fixed its own, and apply inside challenges as well. The degree table gives every degree its own state by the same tests in the same order.

Assumptions and limitations

  • One input variable, polynomial models of degree 0 to 8, at most 21 points; x from -25 to 25 and y within ±1,000,000,000. The Raw x basis is limited to degree 5.
  • Two x values count as one position only when they are exactly equal.
  • A fit whose condition estimate exceeds 1,000,000 is not shown. The estimate uses the infinity norm of the column-equilibrated factor and is about the usual 2-norm condition number, within a factor d + 1.
  • A column whose remaining length is at most 1×10⁻¹² of its own length is treated as dependent on the earlier ones.
  • Below the rounding floor, a relative residual under about 1,000 × κ × 1.1×10⁻¹⁶, the residuals of the fitted points read 0.
  • The leave-one-out error uses the exact closed form for least squares; it is undefined when a point has leverage one.
  • Cook's distance of 1 is a rule of thumb for an influential point, not a test.
  • Degrees whose errors lie within one part in a million of each other tie, and the lowest is shown.
  • A value within about one part in a million (relative) of a threshold, such as the condition cap of 1,000,000, a Cook's distance of 1 or a challenge band, may fall either side of it; so may a digits-lost value whose power of ten sits that close to a half.

Restrictions and non-computing states

Under NOT VALID every result and every table is blank except the status and the challenge texts; a selected challenge reads NOT MET with a score of 0.

When the selected degree cannot be used (too few different x positions, the raw basis limit, nearly dependent columns or a fit too ill-conditioned to trust), every result of that degree is blank: its coefficients, statistics, condition estimate and the point table's fitted columns. The degree table and the curve frames still carry every usable degree, so you can see why. When the curve is forced through a fitted point, the fit is returned, but the leave-one-out error, Cook's distances and the leave-one-out residuals are blank.

In challenges 1, 2 and 5 the results listed under Challenges are held back until the challenge allows them.

Errors and warnings

The status messages, first match wins (d is the selected degree):

  • NOT VALID: the number of points must be a whole number from 2 to 21
  • NOT VALID: each point used needs x from -25 to 25 and y from -1000000000 to 1000000000
  • NOT VALID: each point used must be either fitted (0) or held out (1)
  • NOT VALID: the polynomial degree must be a whole number from 0 to 8
  • NOT VALID: choose a basis from the list
  • NOT VALID: the challenge number must be a whole number from 0 to 5
  • NOT VALID: the predicted best degree must be blank or a whole number from 0 to 8: challenge 1 only.
  • CHECK: a degree-d curve needs at least d+1 different x positions among the fitted points (there are m): the fitted points have only m different x positions; the numbers are filled in.
  • CHECK: the raw x basis is limited to degree 5 here; choose degree 5 or less, or the scaled basis
  • CHECK: at degree d the basis columns are nearly dependent (fitted points too close together)
  • CHECK: degree d is too ill-conditioned in this basis to trust; lower the degree or use the scaled basis: the condition estimate is above 1,000,000.
  • CHECK: at degree d the curve is forced through at least one fitted point, so the leave-one-out error cannot be computed: a fitted point has leverage one.
  • OK

References

This laboratory is an educational model of fitting a polynomial of degree 0 to 8 to up to 21 points by least squares, which makes the sum of the squared residuals as small as possible. The columns of the fit are powers of x itself (Raw x) or of a scaled t that maps the active points onto -1 to 1 (Scaled). A modified Gram-Schmidt QR factorisation of these columns, with the y values carried along as one more column, gives the fit of every degree at once; back-substitution gives the coefficients, and Horner's rule evaluates the curve. The condition estimate shows how sensitive the fit is, and solving the normal equations by Cholesky shows how many more digits that route loses; a fit whose condition estimate exceeds 1,000,000 is not shown. Points can be held out to measure the error on points the fit has not seen. The exact leave-one-out error uses each point's residual e and leverage h as e/(1 - h), and Cook's distance combines a point's residual and leverage into one measure of its influence on the fit.

Sources and further reading

  • The QR factorisation, least-squares fitting through it, and the Cholesky factorisation of the normal equations: G. H. Golub and C. F. Van Loan, Matrix Computations, 4th edition, Johns Hopkins University Press, 2013, section 4.2, Positive Definite Systems, section 5.2, The QR Factorization, and section 5.3, The Full-Rank Least Squares Problem. Author's book page
  • The influence of a single point on a least-squares fit, measured by Cook's distance: R. D. Cook, "Detection of influential observation in linear regression", Technometrics 19(1), 1977, pages 15-18. doi:10.1080/00401706.1977.10489493

No table or text from any of these publications is reproduced, and none of their authors or publishers has reviewed or endorses this laboratory.

This laboratory is for learning. Its results hold only within its stated ranges; it fits at most 21 points and does not test whether a polynomial is the right model for real measurements.

Results are informational and not professional advice. See our Terms of Use. Powered by SpreadsheetWeb · About · Privacy · Terms