Polynomial Regression and Basis Expansions
A model can capture a curved relationship while still being linear regression underneath, simply by feeding it transformed copies of the input — $x$, $x^2$, $x^3$ — as extra features; this trick is called a basis expansion.
Prerequisites: The Classical Linear Regression Assumptions
Linear regression can only draw a straight line, but a straight line is a poor fit whenever the true relationship curves — implied volatility against strike, say, which bends into a smile rather than staying flat. The fix doesn't require abandoning linear regression at all: create new features that are transformed copies of the original one — , , and so on — and hand all of them to the exact same linear regression machinery. The model is still, mathematically, a linear combination of features; it's just that some of those features happen to be nonlinear functions of the original input. That's a basis expansion, and polynomial regression is its simplest example.
The analogy: describing a curve with straight rulers of different lengths
Imagine trying to trace a curved coastline using only straight rulers. One ruler alone can't do it. But give yourself a ruler, a ruler-squared "bendable" tool, a ruler-cubed tool, and enough of them stacked with the right weights, you can trace almost any smooth curve — you're not bending any individual tool, you're combining straight, simple pieces in the right proportions. Basis expansion is exactly this: keep the combination step linear (just weighted addition), but make the ingredients being combined (, , , , or anything else) as curved as needed.
The model
Ordinary polynomial regression of degree replaces a single feature with transformed copies:
Plain English: the prediction is a weighted sum of powers of ; the model curves because curve, but fitting it is still ordinary least squares — solve for exactly the way you'd solve for coefficients in plain linear regression, just on an expanded feature matrix that includes the powers as extra columns. More generally, a basis expansion replaces with any set of functions — polynomials, sines and cosines, indicator functions for ranges of — and fits the same way.
Worked example 1: fitting a degree-2 curve by hand
Suppose three data points: , which look like . Expand to features : rows . Solving the resulting linear system exactly (three equations, three unknowns) gives , i.e. — a perfect fit, because three points can always be fit exactly by a degree-2 polynomial (2 degrees of freedom plus intercept equals 3 parameters for 3 points), and the fitting procedure was ordinary least squares the entire time, just on expanded features.
Worked example 2: degree choice and overfitting on noisy data
Now take 10 noisy points scattered around a true relationship (a nearly straight line with small random noise). Fitting degree 1 (a line) gives a smooth fit with modest residuals, say a residual sum of squares (RSS) of 4.2 on held-out data. Fitting degree 9 on the same 10 training points drives training RSS to nearly 0 (a 9-parameter polynomial can pass through 10 points almost exactly) but held-out RSS explodes to something like 340 — the high-degree polynomial oscillates wildly between training points to hit each one exactly, a classic case of a basis expansion rich enough to memorize noise rather than capture the smooth underlying trend.
Adjust the curve's shape parameters here — the same mechanism (a fixed functional family, fit by adjusting coefficients) is what polynomial regression does, except the "coefficients" are chosen by least squares rather than by hand, and adding higher powers gives the fit more independent knobs to bend with.
What this means in practice
Basis expansions are the reason "linear regression" is far more flexible in practice than "fits a straight line" suggests — the same normal-equations machinery, the same interpretable coefficients, the same fast closed-form solve, applied to engineered nonlinear features. Quants use this constantly: fitting an implied-vol smile with a low-degree polynomial in log-moneyness, or capturing a nonlinear factor-return relationship by adding squared or interaction terms to an otherwise linear factor model, all while keeping the estimation, standard errors, and diagnostics of ordinary linear regression.
Polynomial regression and basis expansions keep the model linear in its parameters while making it nonlinear in the original input, by replacing or augmenting with transformed features like , , or other fixed functions, and fitting the coefficients with ordinary least squares.
Higher polynomial degree is not automatically a better fit — degree acts exactly like model complexity in the bias-variance tradeoff, and past a certain point the extra flexibility starts fitting noise rather than signal, especially near the edges of the data range where high-degree polynomials tend to swing wildly (Runge's phenomenon). Choosing the degree by minimizing training error alone will always favor the highest available degree; it must be chosen by cross-validation or a held-out set, the same way any other complexity hyperparameter is chosen.
Related concepts
Practice in interviews
Further reading
- Hastie, Tibshirani & Friedman, The Elements of Statistical Learning, Ch. 5 (2009)