THE GENIUS PROJECT
๐Ÿ“ Model deep dive ยท Statistical model 2 of 3

Linear Regression

๐Ÿ•’ About 14 minutes ๐Ÿ“Š Real NCB data ๐ŸŽฎ Drag-the-line game
A hand-drawn line graph on paper with a ruler and a pen

A moving average only ever says "about the same as recently." Linear regression is braver: it draws a straight trend line through the prices and says "this is the direction things are heading, and here is where they will be next." Today you fit that line yourself, by hand, then let the maths find the perfect one.

The one idea

Plot the prices as dots, one per day. Now imagine laying a straight stick across them so it sits as close to all the dots as possible. That stick is your prediction machine: to guess a future day, just read where the stick is above that day. The gap between each dot and the stick is the error, and the best line is the one that makes those gaps smallest overall.

Residual one miss

A residual is the vertical distance from a real dot to your line: how far that one prediction was off. Regression squares every residual (so big misses hurt more) and hunts for the line with the smallest total. That total is drawn live below as you drag.

Fit the line yourself

Drag the two gold handles up and down to tilt and shift the line through NCB's real prices. The coral sticks are your residuals, one per day. Watch the total error at the bottom. When you think you have it, press Snap to best fit and see how close you got to the line the maths would choose.

How to play
  1. Drag the left gold handle and the right gold handle to aim the line through the dots.
  2. Try to make the total coral error as small as you can.
  3. Press Snap to best fit. That is linear regression solving it in one step.
Drag a handle to begin.
$$\hat{p} = a + b \times (\text{day number})$$

\(a\) is where the line starts, \(b\) is its slope (how much the price climbs per day). Regression picks the \(a\) and \(b\) with the smallest total squared error.

โœ‹ Check your understanding
What does "best fit" actually mean here?

What it is great at, and where it slips

๐Ÿ‘ Great for

Things with a steady direction: a bill creeping up month after month, or a stock in a calm uptrend. It also tells you the rate of change.

๐Ÿ‘Ž Slips when

The pattern bends. A straight line cannot follow a curve or a sudden turn, so it over- or under-shoots once the trend breaks.

๐Ÿ’ก Use it on your own light bill

If your electricity use has been climbing (hello, heatwave and more fans running), a trend line captures that rise in a way a plain average cannot. In the bonus light-bill challenge you will fit a regression line to your real bills and read off next month.

๐Ÿง  Recap
  • Linear regression fits a straight trend line and reads the future off it.
  • A residual is one dot's miss; the best fit has the smallest total squared residual.
  • It captures a steady rise or fall, but cannot follow a curve or a sharp turn.

Next: ARIMA, the classic time-series workhorse that blends recent prices and recent misses.