Polynomial Regression
What you'll learn
- Why Polynomial Regression is classified as linear in parameters despite modeling curved relationships.
- How to construct the Vandermonde Design Matrix to map scalar inputs into higher-dimensional feature spaces.
- Step-by-step first-principles derivation of the polynomial Normal Equations .
- A complete, hand-calculated worked numerical example () from raw coordinates to matrix inversion and zero-sum residual verification.
- How interaction terms () capture synergistic rates of change through partial derivatives.
- The combinatorial explosion of feature space () and why high degrees cause rank deficiency.
- How Runge's Phenomenon creates catastrophic boundary oscillations in high-degree fits.
- Why feature standardization (-score scaling) is mathematically mandatory before regularizing with Ridge () or Lasso ().
Explained in detail
1. The Big Picture & Motivation
In standard Ordinary Least Squares (OLS) Linear Regression, we enforce a strict structural constraint: the relationship between predictor and continuous response must be a straight line:
This constraint dictates that the marginal rate of change is constant everywhere: . Whether or , a 1-unit increase in produces the exact same expected change in .
However, natural, physical, and socio-economic systems rarely follow rigid straight lines:
- Kinetic Physics: The braking distance of an automobile grows quadratically with vehicle velocity ().
- Economics: Diminishing marginal utility, where each additional dollar of capital yields progressively smaller marginal output.
- Pharmacology: Dose-response curves, where drug efficacy rises rapidly, plateaus, and eventually becomes toxic at high dosages.
- Education & Cognition: Exam scores versus study hours, where initial study hours provide substantial gains followed by fatigue and performance saturation.
When we fit a straight line to curved data, the model suffers from severe systematic bias (underfitting). The residuals display distinct, non-random U-shaped or cyclical patterns rather than uncorrelated white noise.

Core Motivation: Polynomial Regression broadens the hypothesis class of linear models to fit nonlinear curves by adding powers of original predictors () as new input features, while keeping the estimation problem entirely linear with respect to the unknown weights .
2. What Exactly is a Polynomial?
A polynomial in a single real variable is a mathematical expression composed of variables and coefficients involving only addition, subtraction, multiplication, and non-negative integer exponents:
The highest exponent associated with a non-zero coefficient is called the degree of the polynomial.
- Degree 0 (Constant): — a horizontal flat line (0 turning points).
- Degree 1 (Linear): — a sloped straight line (0 turning points).
- Degree 2 (Quadratic): — a parabola with exactly 1 turning point (vertex / extremum).
- Degree 3 (Cubic): — an S-shaped curve with 1 inflection point and up to 2 turning points.
- Degree 4 (Quartic): — a W or M-shaped curve with up to 3 turning points.

The Flexible Ruler Analogy: Think of polynomial degree as the number of flexible joints in a carpenter's folding ruler. A ruler with 1 segment (degree 1) can only be laid flat as a straight line. Adding joints allows it to bend at 1 point (quadratic), 2 points (cubic), or wiggle through complex shapes. However, too many joints make the ruler floppy and hypersensitive to tiny bumps (overfitting).
A polynomial of degree can have at most turning points (local extrema where the first derivative ). Increasing degree directly dials the mathematical flexibility of the curve.
3. The Fundamental Definition of Linearity in Machine Learning
A common point of confusion for students is why Polynomial Regression is universally classified as a linear model when its graphical prediction curve is obviously curved.
The Golden Rule of Linearity: In statistical machine learning, a model is defined as linear if it is linear in its parameters (coefficients) , regardless of how nonlinear the feature transformations may be!
Consider the univariate quadratic model:
Let us define synthesized feature variables:
Rewriting the equation with these transformed features yields:
This is identical to a standard multiple linear regression model with two predictor variables and !
Because no parameter is multiplied by another parameter (), raised to a power (), or trapped inside a nonlinear function ( or ), the loss surface with respect to remains a strictly convex quadratic bowl. Consequently, the global minimum can be computed in a single step using the analytical OLS normal equations.
4. Mathematical Formulation & The Vandermonde Matrix
Given a dataset of training pairs , a univariate polynomial regression model of degree expresses each observation as:
We assemble all equations into compact matrix-vector notation:
Let us inspect the dimensions of every component:
where the design matrix is the celebrated Vandermonde Design Matrix:
Each row represents an individual sample whose raw scalar value has been mapped into a -dimensional basis vector:
5. First-Principles Derivation of the OLS Normal Equations
We seek the parameter vector that minimizes the Residual Sum of Squares (RSS):
Expressing the norm as a vector inner product and expanding:
Differentiating with respect to the vector :
Setting the gradient to zero vector :
This system is the Polynomial Normal Equations. As long as the dataset contains at least distinct coordinates, the columns of the Vandermonde matrix are linearly independent. The square Gram matrix is strictly positive-definite and invertible:
Geometric Projection & Residual Orthogonality
The fitted vector is the orthogonal projection of target vector onto the polynomial column subspace .
Consequently, the residual vector is strictly perpendicular to every single polynomial power column:
For , this guarantees that the sum of residuals is identically zero () whenever an intercept is included.
6. Model Fitting: Complete Worked Numerical Example
To make the matrix mechanics concrete, let us calculate a complete polynomial regression problem from scratch without rounding.
The Problem Dataset
Suppose an educational researcher examines study time ( in hours) versus examination score ( out of 15) for students:
We wish to fit a degree-2 quadratic polynomial: .
Step 1: Form the Vandermonde Design Matrix
Step 2: Compute the Gram Matrix
Multiplying () by ():
Let's verify the diagonal entries:
Step 3: Compute the Moment Vector
Step 4: Invert
First, compute the determinant of the Gram matrix:
Because , the inverse exists. Computing adjugate cofactors and dividing by :
Step 5: Solve for Optimal Coefficients
Multiplying row by column:
The exact OLS fitted quadratic regression equation is:
Step 6: Prediction, Residual Analysis, and RSS Verification
Let us verify the predictions and sample residuals:

Both fundamental OLS properties hold to infinite precision:
- Sum of residuals is exactly zero: .
- Residuals are orthogonal to design columns:
- .
- .
7. Interactive Simulation: Degree & Overfitting Explorer
Experiment with polynomial degree and regularization below to see how the hypothesis space transforms:
Figure 3.3: Polynomial Geometry & Bias-Variance Tradeoff
Interactive Polynomial Regression. Increase degree d to expand model capacity. Low degrees (d=1) underfit due to high bias; excessive degrees (d ≥ 6) cause wild boundary oscillations (Runge's Phenomenon) and high variance. Adding Ridge penalty (L₂) shrinks the polynomial coefficients and restores stability.
8. Multivariate Polynomials & Interaction Terms
In practical applications, targets depend on multiple features (e.g. predicting house price from living area and number of bedrooms ).
A standard multiple linear model assumes purely additive effects:
Expanding to degree 2 without interactions captures curvature along individual axes:
However, pure power terms assume that the effect of living area is completely independent of the number of bedrooms . In reality, adding 500 square feet to a 1-bedroom apartment has a vastly different market impact than adding 500 square feet to a 5-bedroom house.
To model this synergy, we include the interaction term :
Partial Derivative Interpretation: Taking the partial derivative with respect to :
The marginal rate of change of with respect to now explicitly depends on the current value of ! When , the features interact synergistically.
9. The Combinatorial Explosion of Feature Space
How many features are created when applying a degree- polynomial expansion to input variables?
Including the constant intercept and all cross-product interaction terms with , the total number of features is given by the combination with repetition formula:
The Curse of Dimensionality: With only original features and degree , the model expands into 3,003 columns! If your training sample size , the matrix is singular and non-invertible, making unregularized OLS mathematically impossible.
10. Bias-Variance Decomposition & Runge's Phenomenon
The polynomial degree acts as the direct complexity dial of the model:
- Underfitting (High Bias, Low Variance, e.g. ): The model is too rigid to capture the true underlying nonlinear curvature.
- Optimal Fit (Balanced, e.g. ): The curve captures the true underlying pattern while smoothing over random noise.
- Overfitting (Low Bias, High Variance, e.g. ): The curve interpolates every training point (), but oscillates violently between points.

Runge's Phenomenon: The Extrapolation Hazard
When fitting high-degree polynomials on equally spaced points, the curve develops violent, high-frequency oscillations near the edges of the interval, known as Runge's Phenomenon.
Never use high-degree polynomials to extrapolate beyond the observed minimum and maximum training range!

Mathematically, the expected prediction error at any query point decomposes into three orthogonal components:
As degree rises:
- decreases monotonically because higher-degree polynomials subsume lower-degree ones.
- explodes because the coefficients become hypersensitive to minor shifts in the sample data.
11. Taming Polynomials: Regularization & Mandatory Scaling
Instead of guessing a single magic degree , a powerful modern strategy is to use a flexible degree (e.g., ) combined with regularization to constrain coefficient magnitudes.

Ridge Regression ( Penalty)
The unpenalized intercept is preserved. In matrix form:
Adding to the diagonal prevents singularity and dampens wild oscillations.
Lasso Regression ( Penalty)
The diamond geometry of the penalty drives non-essential higher-order polynomial coefficients to exact zeros, performing automatic degree selection and interaction pruning!
Why Feature Scaling is Mandatory
If , then:
On unscaled features, the condition number explodes past , causing catastrophic arithmetic roundoff errors. Furthermore, regularizers like would unfairly penalize higher powers simply because their unscaled values are massive.
Always standardize features with -score normalization after polynomial expansion:
Interactive Quiz
🧩
Ready to test yourself?
20 questions · explanations shown after
Teach & Solidify
Teach This: Polynomial Regression
Core Intuition
Polynomial Regression is standard multiple linear regression applied to powers of original features, expanding straight lines into flexible curves while retaining closed-form convex OLS optimization.
Key Concepts to Explain
- 1Linearity in machine learning refers strictly to parameters β, not features; polynomial curves remain linear models.
- 2A polynomial of degree d introduces up to d - 1 local turning points (extrema).
- 3The Vandermonde matrix X maps scalar inputs into higher powers [1, x, x², ..., xᵈ].
- 4High-degree polynomials suffer from Runge's phenomenon (wild boundary oscillations) and catastrophic extrapolation errors.
⚠️ What Most Students Get Confused About
Extrapolating outside the training domain! High-degree polynomials explode toward ±∞ near interval edges. Always bound predictions within observed ranges, standardize features, and apply Ridge or Lasso regularization.
Explain Polynomial Regression in your own words
Imagine you are explaining this idea to a friend or classmate with no math background. Writing it out forces your brain to bridge gaps in your intuition.
Resources & GitHub
Resources & Study Materials
Deepen your understanding with author-prepared study notes, derivation proofs, and curated educational lectures.
Complete 17-page compiled theory reference notes authored by Md. Inzamamul Lohani (Software Engineering, IIT, DU), covering full mathematical proofs, Vandermonde matrices, and worked calculations.
Josh Starmer visually breaks down polynomial degrees, overfitting risks, and choosing optimal complexity.
Quick formula summary covering Vandermonde design matrix, combinatorial explosion (p+d choose d), and regularized Ridge solutions.
Mastered this concept?
Tick this box when you feel confident explaining it.
Topic Resources
Was this clear?