Polynomial Regression & Linear Assumptions: Curved Fits, Residuals & Homoscedasticity
How adding x², x³ lets a linear model bend around curves, how to read residual plots, and the 4 LINE assumptions of Linear Regression
Polynomial Regression fits curved relationships by expanding raw features into powers (x, x², x³) while still solving a linear model in the weights — and Residual Analysis checks whether a regression model's core LINE assumptions hold.
Real-world phenomena (braking distance vs. speed, diminishing ad returns) are rarely straight lines, and violating Linear Regression assumptions (like non-constant error spread) makes confidence intervals and predictions unreliable.
Residual plots are the X-ray machine of regression — a 2-second scatter plot reveals non-linearity and variance blow-ups that a single RMSE score hides.
Polynomial & interaction terms (PolynomialFeatures(degree=2)) let fast linear models capture non-linear curves at microsecond serving latency.
Checking homoscedasticity and residual normality is mandatory whenever stakeholders need trustworthy p-values or prediction intervals.
Classic question: 'Why is Polynomial Regression still called a linear model, and what does a funnel-shaped residual plot mean?'
In a residual plot (predicted value ŷ on the X-axis, residual y − ŷ on the Y-axis), what does a HEALTHY regression model look like?
- Explain why Polynomial Regression is still mathematically a 'linear model' (linear in the parameters w, non-linear in x).
- Diagnose underfitting (degree 1) vs. sweet-spot fit (degree 2–3) vs. catastrophic overfitting (degree 12+).
- Inspect a Residual Plot (ŷ vs. y − ŷ) to spot curved bias and heteroscedasticity (fan-shaped error spread).
- Recall the 4 LINE assumptions of OLS Linear Regression: Linearity, Independence, Normality of residuals, Equal variance (Homoscedasticity).
You don't need a new algorithm to fit curves! By feeding [x, x², x³] into ordinary Linear Regression, the model stays linear in its weights w while drawing smooth curves in x-space. Just watch the degree — crank it too high and the curve violently wiggles through every noisy dot!
1. The 4 LINE Assumptions of Linear Regression
Think of Linear Regression like a precision scale that promises accurate weights only if you place it on a flat floor, away from wind, and zero it first.
Remember the acronym LINE:
- L — Linearity: The true mean of is a linear function of your (possibly engineered) features. Check: No U-shape in the residual plot.
- I — Independence: Errors are independent across rows (violated in time-series autocorrelation!).
- N — Normality of Residuals: Residuals are roughly bell-shaped (mostly needed for small-sample confidence intervals & p-values, NOT for point prediction).
- E — Equal Variance (Homoscedasticity): Residual spread stays constant across all . If errors fan out like a megaphone (Heteroscedasticity), try
log1p(y)or Weighted Least Squares!
2. Choosing Polynomial Degree Without Overfitting
With original features, degree- PolynomialFeatures creates columns — which explodes rapidly!
- Degree 1: Straight line (high bias if data is curved).
- Degree 2–3: Smooth curves + pairwise interactions (usually the tabular sweet spot).
- Degree 10+: Wild Runge oscillations between points (extreme variance!).
Always pair
PolynomialFeatureswith StandardScaler (since is huge!) and Ridge/Lasso regularization.
The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.
In ML, 'linear' refers to the parameters (weights) , not the raw input . Because is a straight weighted sum of , the loss surface is still a single convex bowl with a unique global minimum!
Diagnose Both Learning Curves & Prescribe the Right ML Fix
x, x²) to capture curves linearly, inspect residual plots for U-shapes or megaphone variance, and always pair polynomial expansion with scaling + Ridge/Lasso.import numpy as np
# Compare Degree-1 (Linear) vs. Degree-2 (Polynomial) Fit + Residual Check
rng = np.random.default_rng(7)
x = np.linspace(-3, 3, 40)
y = 0.8 * x**2 - 1.2 * x + 2.0 + rng.normal(0, 0.4, size=len(x))
for deg in (1, 2, 10):
coeffs = np.polyfit(x, y, deg)
y_hat = np.polyval(coeffs, x)
residuals = y - y_hat
rmse = float(np.sqrt(np.mean(residuals ** 2)))
print(f"Degree {deg:2d} | Train RMSE={rmse:.3f} | Max |residual|={np.abs(residuals).max():.3f}")