One-Line Summary: Capturing nonlinear relationships within the linear regression framework by adding polynomial feature terms.
Prerequisites: Linear regression (OLS, normal equations), bias-variance tradeoff, cross-validation, feature engineering basics.
What Is Polynomial Regression?
Suppose you are studying how a car's fuel efficiency changes with engine RPM. At low RPMs efficiency climbs, peaks in a mid-range, and then drops at high RPMs -- a clear curve, not a line. Polynomial regression captures such curvature by adding powers of the predictor as new features. The model remains "linear" in its parameters (and thus solvable by OLS), but the decision boundary in the original feature space is a curve, surface, or higher-dimensional manifold.
For a single predictor and degree , the polynomial regression model is:
This is equivalent to constructing an augmented feature vector and fitting:
which is a standard linear regression in the transformed feature space.
How It Works
Polynomial Feature Expansion
Given the original feature matrix , we construct an expanded matrix that includes all polynomial terms up to degree . For a single feature, the mapping is:
For multiple features , a degree-2 expansion includes:
The number of features in a full degree- expansion of variables is , which grows rapidly. With and , this yields 285 features.
Still Linear in Parameters
A critical insight: despite modeling nonlinear relationships in the original features, polynomial regression is linear in parameters. The coefficient vector enters the model linearly, so the OLS closed-form solution applies directly:
This means all the statistical machinery of linear regression -- confidence intervals, hypothesis tests, -- carries over without modification.
Interaction Terms
Beyond pure powers, interaction terms capture how the effect of one predictor depends on another. For predictors and :
Here represents the change in the slope of with respect to per unit change in . Interaction terms are a special case of the polynomial expansion and are often more interpretable than higher-order pure powers.
Overfitting with High-Degree Polynomials
Polynomial regression vividly illustrates the bias-variance tradeoff:
- Low degree (): High bias, the model cannot capture curvature. Underfitting.
- Moderate degree ( or ): Often the sweet spot -- enough flexibility without excess variance.
- High degree (): The polynomial oscillates wildly between data points (Runge's phenomenon). Training error drops to near zero, but test error explodes.
Mathematically, a degree- polynomial can perfectly interpolate data points, achieving zero training error while being useless for prediction.
Choosing Polynomial Degree via Cross-Validation
The degree is a hyperparameter. The standard approach:
- For each candidate , construct the polynomial features.
- Perform -fold cross-validation, computing the average validation MSE.
- Select the with the lowest CV error, or use the one-standard-error rule to prefer simplicity.
A typical workflow in practice:
| Degree | Training MSE | CV MSE |
|---|---|---|
| 1 | 12.4 | 13.1 |
| 2 | 3.2 | 4.0 |
| 3 | 2.9 | 3.8 |
| 4 | 2.7 | 5.2 |
| 7 | 0.8 | 18.6 |
Here, degree 3 minimizes the CV error; degree 7 badly overfits.
Comparison with Other Nonlinear Approaches
Polynomial regression is not the only way to model nonlinearity:
- Splines (piecewise polynomials): Fit low-degree polynomials on local intervals joined at knots. They avoid the wild oscillations of high-degree global polynomials. Cubic splines with knots use only parameters versus for a degree- polynomial.
- Kernel regression: Uses a kernel function to weight nearby observations, making local predictions. No explicit feature expansion needed, but computationally expensive at prediction time ( per query).
- Basis function expansions: Polynomial features are one choice of basis; others include radial basis functions, Fourier bases, and wavelets, each suited to different kinds of structure in the data.
Practical Example
Modeling the trajectory of a projectile (height as a function of time ):
Physics tells us this should be quadratic (constant gravitational acceleration). Fitting to observed data might yield , where closely matches . A degree-1 model would miss the curvature entirely; a degree-5 model would fit noise in the measurements.
Why It Matters
Polynomial regression is the simplest bridge between linear models and nonlinear modeling. It requires no new estimation machinery -- just feature engineering -- making it easy to implement and interpret. It serves as an important pedagogical tool for understanding overfitting, model complexity, and the bias-variance tradeoff in a concrete setting. In practice, low-degree polynomial terms (especially quadratic and interaction terms) are routinely included in linear models across science and engineering.
Key Technical Details
- The design matrix can become ill-conditioned for high degrees because spans many orders of magnitude. Centering and scaling features (e.g., ) before expansion mitigates this.
- Orthogonal polynomials (Legendre, Chebyshev) provide numerically stable alternatives to raw powers.
- Regularization (Ridge or Lasso) applied to polynomial features controls overfitting more gracefully than simply capping the degree.
- The effective degrees of freedom of a polynomial model equal (including the intercept), directly governing the bias-variance balance.
- For multivariate expansions, use only interaction terms or limit the total degree to avoid combinatorial explosion of features.
Common Misconceptions
- "Polynomial regression is a nonlinear model." It is nonlinear in the features but linear in the parameters. This distinction matters because OLS and all its theory still apply.
- "Higher degree always means better fit." Higher degree reduces training error but typically increases test error beyond a point. This is the classic overfitting trap.
- "Polynomial regression extrapolates well." Polynomials diverge rapidly outside the training range. A degree-5 fit that looks reasonable within can produce absurd predictions at .
- "You need polynomial regression for any nonlinear pattern." Often, a log or square root transformation of or captures the nonlinearity more parsimoniously than adding polynomial terms.
Connections to Other Concepts
linear-regression.md: Polynomial regression is a special case of linear regression applied to an expanded feature space.ridge-and-lasso-regression.md: Regularization is essential when using high-degree polynomial features to prevent overfitting and multicollinearity in the expanded design matrix.bias-variance-tradeoff.md: Polynomial degree directly controls model complexity; increasing it reduces bias but increases variance.cross-validation.md: The primary tool for selecting the polynomial degree hyperparameter.regression-diagnostics.md: Residual plots reveal whether polynomial terms of sufficient degree have been included -- structured patterns in residuals suggest remaining nonlinearity.automated-feature-engineering.md: Polynomial expansion is one of the most common feature engineering techniques.
Further Reading
- Hastie, Tibshirani, and Friedman, "The Elements of Statistical Learning" (2009) -- Chapter 5 on basis expansions and splines contextualizes polynomial regression among broader nonlinear methods.
- Bishop, "Pattern Recognition and Machine Learning" (2006) -- Section 1.1 uses polynomial curve fitting as the motivating example for the entire book.
- James et al., "An Introduction to Statistical Learning" (2013) -- Chapter 7 gives an accessible treatment of polynomial regression and its limitations.