2.2.6 · D3Linear & Logistic Regression

Worked examples — Polynomial regression

2,580 words12 min readBack to topic

This is a worked-examples workshop for Polynomial regression. The parent note built the theory: transform a feature into powers , then run ordinary linear regression on those new columns. Here we hit every kind of situation that can appear — small quadratics, degenerate data, negative inputs, scaling disasters, over-fitting, real-world word problems, and exam twists — so no scenario ever surprises you.

Four symbols you must have straight before we start (the parent defined them, we re-anchor them here):


The scenario matrix

Every cell below is covered by at least one worked example. If a situation is not in this table, it is a combination of these — you will be able to build it.

# Case class What makes it tricky Example
A Exact quadratic fit, positive 3 params, 3+ clean points Ex 1
B Noisy data, best-fit not exact fit passes near, not through Ex 2
C Negative + zero inputs signs, kills higher powers Ex 3
D Degenerate / singular duplicate or too few points Ex 4
E Scaling catastrophe vs off by orders of magnitude Ex 5
F Over-fit limit () zero train error, wild between points Ex 6
G Real-world word problem choose degree, interpret coefficients Ex 7
H Exam twist: interaction term two features, cross term Ex 8

A — Exact quadratic, clean positive data


B — Noisy data, best-fit only approximate


C — Negative and zero inputs


D — Degenerate input: when can't be inverted


E — The scaling catastrophe


F — The over-fit limit


G — Real-world word problem


H — Exam twist: interaction term


Recall Quick self-test

Which case class has a singular ? ::: Case D — duplicate/too-few distinct -values. Why must you scale before a degree-3 fit? ::: Raw dwarfs , blowing up the condition number of (Case E). When does degree give exactly zero training error? ::: When , where is the number of data points (Case F). What forces in Example 3? ::: The data is symmetric about , so the odd (linear) term cancels.

Read the Hinglish companion: 2.2.06 Polynomial regression (Hinglish).