Eight days
The ice cream seller's eight days: temperature across, ice creams sold up. The goal is a line that passes close to these dots.
The model is a line
Linear regression reads the prediction for each temperature from a line: prediction = w · x + b. For now w = 1.20, b = 10. These two numbers are the model's parameters.
w, the slope
When the temperature rises by 1 degree, the prediction rises by w. In the triangle the temperature rises by 5 degrees and the prediction by 6. The larger w, the steeper the line.
b, the intercept
b is the prediction at zero degrees: where the line crosses the vertical axis, 10. When b changes, the line slides up or down and keeps its slope.
One day's prediction
Day 6 had 26 degrees: the model says 1.20 · 26 + 10 = 41.20, while 48 were actually sold. The red line is the difference, 6.80.
A prediction for tomorrow
Tomorrow is expected to be 27 degrees. The model says 42.40 ice creams. The model can predict for temperatures it never saw in training too.
Which line is better
Move the line by hand: the ring on the vertical axis changes b, the ring at the right end changes w. Some lines pass closer to the dots. The loss function will measure how close.
Why it matters
Linear regression is the simplest learning model, yet it is still used today to predict house prices, demand and costs. Every neuron of a neural network also carries a w · x + b inside.