Loading
Module 5 of 12

Your First Model: Linear Regression

About 10 minute read

Linear regression is usually the first model anyone learns, and for good reason: it's simple enough to compute by hand on paper, yet it demonstrates the entire "learning loop" from Module 3 concretely.

The model

Linear regression assumes the relationship between an input xx and an output yy can be approximated by a straight line:

y=mx+by = mx + b

mm (the slope) and bb (the intercept) are the model's parameters — the numbers that get adjusted during training. Everything the model "knows" after training is stored in just these two numbers.

Measuring how wrong the line is

For any candidate line, you can measure how well it fits the data by computing the error at each point (actual y minus predicted y), squaring it (so positive and negative errors don't cancel out, and big misses are punished more), and averaging across all points. This is called the Mean Squared Error (MSE), and it's a specific example of a loss function — a number that says "how wrong is the model right now?" Training a model is, mechanically, the process of searching for parameters that make the loss as small as possible.

Fit a line to the data
Drag the sliders to change the line's slope and intercept. Try to get the error (MSE) as low as possible.
y=0.50x+2.0y = 0.50x + 2.0
Mean squared error: 1.22
Key idea: You just did by hand (with sliders) what an algorithm called gradient descent does automatically — nudging the parameters, in the direction that reduces the loss, over and over. Module 8 covers exactly how that automatic nudging works.

Beyond one input

Real problems usually have many features, not just one. Multiple linear regression extends the same idea: y=w1x1+w2x2++wnxn+by = w_1x_1 + w_2x_2 + \ldots + w_nx_n + b. If that formula looks familiar, it should — it's a dot product between a weight vector and a feature vector, plus a bias, which is exactly the formula for a single artificial neuron you'll see in Module 7.

Check your understanding
1. In the linear regression equation y = mx + b, what are m and b called?
2. Why square the errors instead of just averaging the raw differences?
3. Multiple linear regression with many input features is mathematically closest to:
Did you like the lesson? 😆👍
Consider a donation to support our work: