This page assumes nothing. Before we can even read the Ridge cost function, we must earn every letter in it: what a weight is, what a vector is, what ∑ means, what a transpose does, what a matrix inverse is. Each symbol gets a plain-words meaning, a picture, and a reason the topic needs it. Read top to bottom — every idea rests on the one before.
So there are two different y's to keep straight: y is the truth (given in the data), y^ is our guess (computed from weights). The whole game is making y^ close to y.
Picture a straight line through the origin. The weight w is its slope — how steeply the prediction climbs as the feature grows.
Why the topic needs this: Ridge is entirely a story about keeping w small while y^ stays close to y. If you don't feel w as a slope-dial that can grow dangerously large, the whole "charge a fee for big weights" idea has nothing to grab onto. Look at the red steep line in the figure — that is what "huge weight chasing noise" looks like.
The line in Section 1 was forced through the origin (y^=wx, so x=0⇒y^=0). Real data rarely obeys that: even a house of "zero extra size" has some baseline price. We fix this with one more number.
Why the topic needs this: The parent note says "the bias term w0 is usually not penalized." You cannot understand that sentence without knowing what w0is and why it is special. From here on, assume the data has been centered, so we focus purely on the slope-weights w=(w1,…,wd).
Real problems have many features per example (size and age and location...). We stack the features of one example into a list of numbers called a vector, written in bold: x=(x1,x2,…,xd). Each xj is feature number j, and d is how many features there are.
The weights get their own vector w=(w1,…,wd) — one dial per feature.
Picture w as an arrow in space: in 2 features it's an arrow on a flat page, its two coordinates being w1 (rightward) and w2 (upward). The length of this arrow will turn out to be exactly what Ridge charges you for.
Why the topic needs this: Ridge's penalty is "keep the weight arrow short." You cannot picture "short arrow" without first picturing the arrow.
The parent note is full of ∑. It is just shorthand for repeated addition.
Two uses appear constantly:
Over examplesi=1…n (where n = number of training rows). Here yi = the true answer of the i-th example, and y^i = our prediction for it.
Over featuresj=1…d.
Why the topic needs this: The data-fit term sums an error over all examples (∑i); the penalty sums squared weights over all features (∑j). Mixing them up breaks everything.
Error of one prediction: using the symbols from Section 1, the error on example i is yi−y^i — the gap between the true answeryi and our guessy^i. We square it, (yi−y^i)2, for two reasons: squaring makes it positive (a miss of −3 is as bad as +3), and it punishes big misses much harder than small ones.
Now the star of the show:
Picture the right triangle whose legs are w1 and w2: the hypotenuse is∥w∥, the arrow length. Squaring it is measuring the squared radius of a circle the arrow lives on.
Why the topic needs this: The name "L2" in "L2 regularization" is this norm. The penalty λ∑wj2 is λ∥w∥2 — literally "λ times the squared arrow length." Look at the figure: Ridge charges you the squared radius, so it hates long arrows enormously.
With many features (and data centered so w0=0), the prediction is feature-by-feature multiply, then add:
y^=w1x1+w2x2+⋯+wdxd=∑j=1dwjxj.
This pattern is so common it has a name: the dot product, written w⊤x.
Why the topic needs this: Every appearance of w⊤xi in the parent is "the model's prediction y^i for example i." It's just ∑jwjxij dressed in compact clothing.
Before we build the data table, one tiny piece of notation.
We have n examples, each a feature-vector. Stack them as rows of a table — that table is the design matrix X∈Rn×d, with n rows and d columns.
Picture X as a spreadsheet, y as the answer column beside it, and Xw as the column of guesses you'd write next to them.
Why the topic needs this: The closed-form solution w^=(X⊤X+λI)−1X⊤y is written entirely in these matrix pieces. y−Xw is the column of all errors; ∥y−Xw∥2 is the total squared error ∑i(yi−w⊤xi)2, using the row xi just defined.
Picture a slider: push it right and the weight-arrow is forced shorter and shorter.
Why the topic needs this:λ is the one dial the practitioner sets. Everything Ridge does — cure singularity, trade bias for variance, shrink noisy directions — is controlled by it. Look at how the arrow collapses toward the origin as λ grows.
Everything so far combines into a single number we want to make small: the cost (or loss) J(w).
To find the smallest-J weight, we use two more ideas.
Why the topic needs this: The Ridge cost J is a sum of squares plus λ∥w∥2 — a perfect bowl. That is why solving ∇wJ=0 gives the answer directly, and why a unique closed form even exists.
Test yourself — reveal only after you've answered aloud.
What is a weight w, pictured?
The slope of the prediction line; the dial saying how much a feature matters.
What is the intercept w0 and how does Ridge treat it?
The baseline height of the line (y^ when all features are 0); Ridge does not penalize it — center the data instead.
What is the difference between y and y^?
y is the true answer given in the data; y^ is the model's computed guess at it.
What does bold w represent geometrically?
An arrow in feature-space whose coordinates are the individual weights.
What does the index j range over vs. the index i?
j over features/weights (1…d); i over examples/rows (1…n).
What is xi?
The i-th row of X — the full feature-vector of example i.
What does ∑j=1dwj2 compute?
The squared L2 norm — the squared length of the weight arrow.
Why square the error and the norm?
Squaring makes them positive, punishes big values hard, and stays smooth/differentiable.
What is w⊤xi in words?
The dot product = multiply matching feature-weight pairs and add = the prediction y^i.
What does the transpose ⊤ do?
Tips a column vector onto its side so it can line up and multiply.
What does Rn×d mean?
The set of tables of real numbers with n rows and d columns — i.e. the shape of X.
What are X, y, and Xw?
Data table (rows=examples), true-answer column, and all n predictions at once.
What is the cost function J(w)?
A single number scoring how bad weights w are: total squared error plus λ times squared norm.
Why can the 21 or n1 factor be dropped?
A positive constant times the whole cost doesn't move the minimum; it only rescales λ.
What is the identity matrix I?
The matrix version of 1: ones on the diagonal, zeros elsewhere; multiplying by it changes nothing.
Why does adding λI make X⊤X invertible?
It lifts every diagonal by λ>0, re-inflating squashed directions into a positive-definite matrix.
What does λ control?
The strength of the weight-size fee: 0 = OLS, ∞ = all weights crushed to 0.
Why can we solve Ridge by setting the gradient to zero?
The cost J is convex (one bowl), so the flat spot (∇J=0) is the unique global minimum.
Recall Self-check: the parent's cost function, decoded
J(w)=∑i(yi−w⊤xi)2+λ∑jwj2. Can you now read every symbol? ∑i over examples, yi the true answer, xi example i's row, w⊤xi = dot-product prediction y^i, the square = smooth positive error, λ = fee rate, ∑jwj2 = squared arrow length. If yes — you're ready for the derivation.