Machine Learning · Chapter 10 of 40

Polynomial Regression

POLYNOMIAL REGRESSION fits a curve by adding powers of the feature (x², x³, ...) as extra columns.

Still linear in the coefficients — just uses non-linear features.

Example 1 (python)
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
pf = PolynomialFeatures(degree=2)
X2 = pf.fit_transform(X)
LinearRegression().fit(X2, y)

Add x² features.

Example 2 (python)
# degree=10 -> overfit; keep it low

Higher degree = more risk of overfitting.

Key points

  • Fits curves using x², x³, ...
  • Uses linear regression under the hood.
  • Higher degree = risk of overfitting.
  • Great for non-linear-but-smooth data.
💡 Note: Combine with a Pipeline so you can grid-search the best degree.

📝 Quick Quiz

1. Polynomial regression is:

2. Higher degree usually:

3. PolynomialFeatures creates: