5.6.1 · D1Machine Learning (Aerospace Applications)

Foundations — Linear regression — normal equation, gradient descent derivation

1,923 words9 min readBack to topic

Before you can read the parent note Linear Regression fluently, you must own every symbol it throws at you. This page builds each one from nothing, in an order where each block rests on the one before it. Read top to bottom.


1. A data point

Picture a scatter of dots. Each dot sits at a horizontal position and a height .

Figure — Linear regression — normal equation, gradient descent derivation
  • → how far right the dot is (the thing you know, e.g. altitude).
  • → how far up the dot is (the thing you want to predict, e.g. fuel burn).
  • → the count of dots. If runs then .

Why the topic needs it. Regression's whole job is to summarise all these dots with one rule. Without a symbol for "dot number " we couldn't talk about "all the dots at once."

Read this line
is the input of the fifth data point; the subscript is a label, not exponent.

2. The prediction and the line

A straight line has two knobs:

Figure — Linear regression — normal equation, gradient descent derivation

Why two knobs and not one? With only the line would be forced through the origin ; real data rarely passes through zero, so lets the line slide up or down freely.


3. The error and why we square it

Figure — Linear regression — normal equation, gradient descent derivation

Look at the vertical dashed sticks in the figure — each is one error. We want the total length of all sticks to be small. But there is a trap:

So the quantity we minimise is the sum of squared errors:

The symbol (capital Greek sigma) simply means "add up the thing on the right for ." It is a compact "add them all."

equals
.

4. The cost function

Why the ?

  • The makes it a mean (average), so the score doesn't blow up just because you have more data.
  • The extra is a convenience: when we differentiate, the square brings down a factor of , and the cancels it so formulas stay clean. It never changes where the minimum is.

5. Vectors and matrices — the bulk notation

When there are many inputs and many points, writing sums by hand is unbearable. We pack numbers into grids.

  • → all the inputs of point stacked in a column.
  • → the design matrix: rows (one per point), columns (one per input feature). The symbol just says "a grid of real numbers with rows and columns."
  • → the column of true answers.
  • → the column of weights, one per feature.

Transpose

Matrix-times-vector

This packs all predictions into one object. Row of is exactly . So = the whole column of guesses in one symbol.

The dot product and

The norm

in words
the total squared error of every point at once.

This is the language of Least Squares Estimation and rests on the Matrix Pseudoinverse.


6. Slope, derivative, gradient — the downhill compass

Figure — Linear regression — normal equation, gradient descent derivation

Why the minus sign in gradient descent? The gradient points uphill (toward more cost). We want less cost, so we step the opposite way: . That is the entire logic of .

  • = learning rate: how big a step to take. Too big → overshoot the valley and bounce; too small → crawl. See Feature Scaling for why unequal input sizes force to be tiny.
  • The subscript = iteration number (), a time step, not a power.
  • (epsilon) = a tiny threshold; "stop when the change is smaller than ."
At the minimum the gradient equals
zero (the valley floor is flat).

7. How they fit together

The bowl-shaped has exactly one bottom because it is convex — see Convex Optimization. That guarantee is why both methods reach the same best line.

Data points x_i y_i

Line model y-hat = w x + b

Error y minus y-hat

Square and average = cost J

Vectors and matrices X w y

Norm = length squared

Convex bowl one minimum

Derivative = slope

Gradient = downhill arrow

Normal equation one leap

Gradient descent many steps

Downstream this same machinery grows into Regularization (Ridge, Lasso), Kalman Filtering, and Neural Networks.


Equipment checklist

Cover the right side and answer aloud. If any stalls you, reread that section.

What does the hat in mean?
It is the line's guessed value, not the measured truth.
What are the two knobs of a straight line and what does each do?
the slope (steepness), the bias (vertical shift).
Why do we square errors instead of adding them raw?
So positive and negative misses can't cancel, and so the cost is smooth for calculus.
What does tell you to do?
Add up the following expression for every point from to .
What single number does report?
The average squared error — how bad the current line is.
What is in plain words?
The whole column of predictions for every data point at once.
What does compute?
The sum of squares of the entries — the squared length.
What is a gradient and where does it point?
The vector of all partial slopes; it points toward steepest increase of cost.
Why is there a minus sign in the update ?
We step opposite the uphill gradient to reduce cost.
What is the "bias trick"?
Adding a column of ones to so the first weight becomes automatically.