Concept 1

Introduction to polynomial regression

Polynomial regression is the first major step beyond a straight-line model. It lets linear regression fit curved relationships by giving it transformed input features.

Why do we need it?

Simple linear regression assumes the prediction changes at a constant rate as \(x\) changes:

\[\hat{y}=\beta_0+\beta_1x\]

But many real relationships are not constant-rate relationships. The effect may increase, flatten, reverse, or saturate.

Real-world check

If study hours increase from 1 to 2, and then from 10 to 11, should the score improve by the same amount?

This question reveals why a straight line can be too rigid for many problems.

curved pattern straight-line fit

When the data bends, a straight line may miss the main pattern even if it is mathematically correct.

What is polynomial regression?

Polynomial regression extends linear regression by adding powers of the input feature.

\[\hat{y}=\beta_0+\beta_1x+\beta_2x^2+\beta_3x^3+\cdots+\beta_dx^d\]

The degree \(d\) controls how flexible the curve can be.

Under squared-error loss, the ideal regression prediction is the conditional average of \(y\) at each value of \(x\):

\[\mathbb{E}(y \mid x)\]

That distinction matters because noisy points may sit above or below the underlying average pattern. The fitted curve should usually follow the pattern, not every noisy point.

DegreeModelShape it can learn
1\(\beta_0+\beta_1x\)Straight line
2\(\beta_0+\beta_1x+\beta_2x^2\)One bend, U-shape or inverted U-shape
3\(\beta_0+\beta_1x+\beta_2x^2+\beta_3x^3\)More flexible curve
High degreeMany powers of \(x\)Very flexible, but can overfit noise
Polynomial regression is not a completely new algorithm. It is linear regression applied to engineered features like \(x^2\), \(x^3\), and \(x^4\).

Curve fitting, interpolation, and smoothing

Polynomial regression belongs to a larger family of curve fitting ideas. The important classroom distinction is whether we want an exact fit or an approximate fit.

IdeaMeaningPolynomial regression connection
InterpolationThe curve is forced to pass through known points.Can look perfect on training points but may become unstable between points.
SmoothingThe curve follows the main trend while ignoring some noise.Usually closer to the ML goal when data is noisy.
Least-squares fittingThe model chooses the curve with small total squared vertical errors.This is the usual way polynomial regression learns coefficients.

Fitting choice

If the data contains measurement noise, should our curve interpolate every point or smooth the overall trend?

For prediction, smoothing the trend is usually safer than forcing an exact fit.

How can it be linear and curved?

The model is linear in the coefficients, not necessarily linear in the original input.

\[\hat{y}=\beta_0+\beta_1x+\beta_2x^2\]

The term \(x^2\) creates curvature, but the model still learns coefficients using linear regression methods.

\[\text{linear in coefficients: }\beta_0,\beta_1,\beta_2\]

The effect of \(x\) is no longer constant. For a quadratic model, the slope at a particular \(x\) is:

\[\frac{d\hat{y}}{dx}=\beta_1+2\beta_2x\]

So a one-unit change in \(x\) can have a different impact at low, medium, and high values of \(x\).

This is the key trick: transform the inputs, then fit a linear model in the transformed feature space.

x x, x^2, x^3 new features linear regression on transformed X

Polynomial regression is feature engineering plus linear regression.

Examples where polynomial features help

Experience vs salary

Salary may rise quickly early in a career and later flatten.

Ad spend vs sales

More spend can help at first, but returns may diminish after a point.

Medicine dosage

Response may improve up to a dose, then worsen or saturate.

Feature decision

If adding \(x^2\) improves the fit, should we immediately add \(x^3,x^4,\ldots,x^{20}\)?

This sets up the next part of the story: flexibility can help, but too much flexibility can memorize noise.

Feature scaling becomes important because powers can explode in size. If \(x\) ranges from 1 to 1000, then \(x^2\) ranges up to 1,000,000 and \(x^3\) ranges up to 1,000,000,000.
Overview Next: Simulation