2.2.6 · D1Linear & Logistic Regression

Foundations — Polynomial regression

1,970 words9 min readBack to topic

This page assumes you have seen nothing. Every symbol in the parent note is unpacked below, in an order where each piece rests on the one before it. When you finish, re-reading the parent will feel like reading your own handwriting.


0. The picture we keep returning to

Figure — Polynomial regression

Look at the scattered dots. A straight line (blue) is honest but too stiff — it cannot bend to follow the smile-shaped cloud. The pale-yellow curve can bend. Every symbol we define exists to describe, build, or bend that yellow curve.


1. A data point:

Picture: one dot on a graph. Its horizontal position is , its vertical position is . That is the entire meaning — a dot is a pair of numbers.

Why the topic needs it: regression is the craft of guessing from . Without a pair, there is nothing to fit.


2. Many data points: the superscript

The parent writes and with a number in parentheses up high. This is not a power.

Picture: number your dots left to right. Dot 3 has coordinates .

Why the topic needs it: we fit to all the dots at once, so we must be able to point at each one.


3. Multiplying a number by itself: powers

Picture: if is the side of a square, is its area; if is the edge of a cube, is its volume. Bigger exponent ⇒ the number grows faster as grows.

Figure — Polynomial regression

Notice in the figure how (pink) shoots up far steeper than (white). This steepness gap is exactly why feature scaling becomes non-negotiable later.

Why the topic needs it: curves are built by mixing different powers of . The bend comes from and beyond.


4. The polynomial:

Read it left to right:

  • — a plain number, added no matter what is (it lifts the whole curve up/down).
  • — the straight-line part.
  • — the first bend.
  • ...and so on up to degree .

Picture: each term is a "voice" in a choir. controls how loudly the -voice sings; turn it up and the curve bends harder. Silence every voice above and you are back to a straight line.

Why the topic needs it: this sum is the shape of the yellow curve from figure 1.


5. The parameters: (theta)

Picture: a row of volume sliders on a mixing desk. Training = finding the slider positions that make the curve hug the dots best.

Why the topic needs it: the s are the answer we solve for.


6. The hypothesis:

Picture: feed into the machine, out comes a height — that is where the yellow curve sits above that .

Why the topic needs it: it is the curve, written as a function. We compare against the real to see how wrong we are.


7. Turning one input into many: the feature map

The parent writes . Here (Greek "phi") is a recipe.

Picture: one seed () going into a machine that spits out several fruits (). We then treat every fruit as an ordinary, independent input.

Why the topic needs it: this is the whole trick. After , the curved problem looks like a flat multi-feature linear problem — solvable by tools you already own.


8. Vectors, the dot product, and

Picture: two rows of boxes side by side; pair them up, multiply each pair, drop all the products into one bucket and sum. That single sum is the dot product.

Why the topic needs it: it is a compact way to write the whole polynomial. says "dot the knobs with the manufactured features."


9. Stacking every example: the design matrix

Figure — Polynomial regression

The figure colour-codes it: each row (blue band) is one dot's full feature recipe ; each column (pink band) is one feature across all dots.

Why the topic needs it: the normal equation needs every example laid out at once. is that layout.


10. Measuring wrongness: the cost

Picture: for each dot, draw a vertical rubber band from the dot to the curve; its length is the gap. is (half the average of) the squared band lengths. Training = shortening the bands.

Why the topic needs it: we cannot say "hug the dots" to a computer. turns "hug the dots" into a number to minimise.


11. The knob that solves it: normal equation

The parent's uses two new pieces:

  • — a small square grid built from the data (see the worked example in the parent).
  • — the inverse, the matrix version of "divide by."

Why it can go wrong: if features differ wildly in scale (recall figure 2), becomes nearly impossible to invert — this is the numerical instability the parent warns about, and the reason for feature scaling.


How it all fits together

data point x and y

many points indexed i

powers x squared x cubed

polynomial sum of powers

parameters theta the knobs

hypothesis h of x the curve

feature map phi one x into many

dot product theta dot phi

design matrix Phi grid of rows

cost J measures wrongness

normal equation solves for theta

Polynomial regression

Every arrow says "you need the tail before you can understand the head." The whole graph pours into Polynomial regression.


Where these foundations reappear


Equipment checklist

Cover the right side; can you answer before revealing?

What does the superscript in mean?
The index of the -th training example — a label, NOT a power.
Difference between and ?
is example number 2; is times itself.
What is the degree of a polynomial?
The highest power of appearing in the sum.
"Linear in the parameters" means what?
Each enters only by being multiplied and added — never squared or inside a function.
What does the feature map produce?
The list — many features made from one input.
Compute in words.
Multiply matching entries of and , then add them all up (a dot product).
What sits in one row of the design matrix ?
One example's full feature recipe .
What does measure and why square the gaps?
Average squared distance from guesses to true ; squaring makes all errors positive and punishes big misses.
What role does play?
The matrix "divide," letting us solve for .
Why must we scale before high-degree fitting?
Powers like dwarf , making nearly un-invertible and gradient descent unstable.