Foundations of Regression
Lesson 0Designing a learning system
The vocabulary and the map you carry into every model you will ever build
Before we write a single line of gradient descent, we need a way to talk about what a learning system even is. This lesson is the on-ramp taken immediately before linear regression. By the end you will be able to look at almost any task, state it as a learning problem, and name which of the three great paradigms it belongs to. When linear regression arrives in the next lesson, it will land not as a new idea but as the first concrete instance of a skeleton you already understand.
What "learning" means, precisely
We use the word "learning" loosely in conversation. To build systems we need it pinned down. The cleanest definition comes from Tom Mitchell, and it is worth committing to memory:
Three letters, one idea. A program learns if, as it gets more experience, it gets measurably better at a task. If performance does not move with experience, nothing was learned, however clever the code looks.
T · Task
What we want done. "Flag spam", "predict a house price", "steer a car".
P · Performance
A number that says how well. Accuracy, mean squared error, total reward.
E · Experience
The data the program learns from. Labeled examples, raw observations, or trial-and-error.
A problem stated with all three filled in is called a well-posed learning problem. Two quick examples:
- Spam filter. T: label an email spam or not. P: fraction of emails classified correctly. E: a pile of emails a human already marked spam or not.
- House-price predictor. T: map a house's features to a price. P: how far off the predicted prices are (squared error). E: past sales with their true prices.
Notice the shape of the loop hiding inside that definition: feed in experience, the system adjusts, performance on the task ticks up, repeat. That loop is the heartbeat of every model in this course.
Designing a learning system: the four choices
Given a well-posed problem, actually building the learner comes down to four design decisions. These are the classic choices, and the punchline of this section is that filling them in is linear regression.
Choose the experience. What data does the system train on, and is the feedback direct (each example carries its right answer) or indirect (a delayed score)? Is the data representative of what the system will meet in the wild?
Choose the target function. What exactly are we trying to learn? Usually an unknown mapping from inputs to outputs.
Choose a representation. What family of functions will we search over? A weighted sum of features, a tree, a neural network.
Choose a learning algorithm. The procedure that tunes the representation's parameters to reduce error on the experience.
Write these out in math and the abstraction becomes concrete. The target function is some true but unknown map from inputs to outputs:
We never get itself, only examples of its behaviour. So we pick a representation, a parameterised guess . The simplest useful choice is a weighted sum of the input features:
To turn "reduce error" into something an algorithm can chase, we need a loss, a single number measuring how wrong is on the experience. Squared error is the natural first choice:
The learning algorithm then adjusts and to make as small as possible. Here is the representation, a line whose slope and intercept are exactly the parameters we tune:
Drag the knob — watch the line tilt and the prediction move.
A 12-inch pizza → predicted $24 · real $15
✗ too high — the rule is too aggressive
And here is the learning algorithm, walking those parameters downhill on the loss until the error bottoms out:
Look at what just happened. Target function: the map from house features to price. Representation: a weighted sum of features. Loss: squared error. Algorithm: nudge the weights downhill. Those four choices, filled in, are linear regression. Everything in the next lesson is the detail of making this one recipe precise. This section is the skeleton; the math there puts flesh on the bones.
Problem-first framing: read the task, then pick the paradigm
A common beginner mistake is to fall in love with an algorithm and go looking for problems to hit with it. Reverse that. Start from the problem, and let its shape route you to a paradigm. Two questions do most of the routing:
Question 1
Is there a labeled answer to imitate? Does each training example come with the "right" output attached?
Question 2
Does the system act over time and get rewarded for the consequences of its actions?
Those two questions split machine learning into its three classic paradigms:
| Paradigm | Experience looks like | Goal |
|---|---|---|
| Supervised | Pairs (x, y), inputs with their labels | Learn the map x → y |
| Unsupervised | Only inputs x, no labels | Find structure in the data |
| Reinforcement | Actions and rewards from an environment | Learn a policy that maximises reward |
The rest of this lesson takes each one in turn.
Supervised learning: learn from labeled examples
This is the paradigm the whole next course lives in, so we foreshadow it hard. In supervised learning the experience is a set of labeled examples, pairs of an input and its known answer :
The task is to learn a function that reproduces from and, crucially, generalises to inputs it has never seen. The label is the teacher: every example silently corrects the model toward the right answer, which is where "supervised" gets its name.
Supervised problems come in two shapes, split entirely by the type of the label :
Regression
Continuous y. Predict a number on a scale: a house price, tomorrow's temperature, a customer's lifetime value.
Classification
Discrete y. Predict a category from a fixed set: spam or not, which digit, which disease.
Regression fits a surface through the data so that, given a new input, you read off a continuous prediction. This is precisely the line-fitting you are about to study in depth:
Classification instead carves the input space into regions, one per class, and predicts by asking which region a point falls in. Same supervised setup, discrete answer:
The mental test is simple. If the label is a number you could sensibly average, it is regression. If it is a name from a finite list, it is classification. "House price" is regression. "Spam or not" is classification.
Unsupervised learning: find structure with no labels
Now remove the teacher. In unsupervised learning the experience is inputs only, with no to imitate:
There is no answer key, so the goal changes from "predict the label" to "discover structure". The workhorse task is clustering: group points that are similar and separate points that are not. A related task is dimensionality reduction, compressing many features into a few that capture the essence.
Press Group below. The algorithm has no colours, no labels, nothing but the geometry of the points, and it invents categories on its own:
🔍 Clustering — Finding Structure Without Labels
No answer key. Press Group and watch k-means invent its own categories from raw dots.
You choose how many groups to look for. There is no “correct” k — different k tells a different story about the same data.
Reveals the hidden groups the data was born from — the “answer key” a supervised model would be handed. Clustering never sees this; it recovers structure from geometry alone.
No labels, no grading — just “which points sit together.” That’s unsupervised learning.
The contrast with the supervised scatter is the whole point. Same kind of cloud of points, but without labels there is no single correct answer to grade against. Is it two clusters or three? Both can be defensible. That is exactly why unsupervised learning is harder to evaluate: with supervised data you compare predictions to known labels and read off an error, but with no ground truth there is nothing to score against directly. You are judging the quality of a discovered structure, not the correctness of a prediction.
Reinforcement learning: learn by acting and being rewarded
The third paradigm looks different from the first two. There is no fixed dataset at all. Instead an agent interacts with an environment: it observes a state, takes an action, and the environment answers with a new state and a reward. Over many rounds the agent learns a policy, a rule mapping states to actions, that maximises the total reward it collects.
🎮 Reinforcement Learning — Learning by Consequence
The agent acts, the world answers with reward. Run a few episodes and watch the path get shorter.
Run an episode to log its total reward. Watch the bars climb as the path improves.
Two flavours make reinforcement learning distinctive, and both are on display above:
- Delayed reward. The payoff for a good move may arrive many steps later. Reaching the goal is worth a lot, but the agent only gets there after a sequence of individually unremarkable moves. Assigning credit backward through that sequence is the core difficulty.
- Exploration versus exploitation. The agent must sometimes try unfamiliar actions to discover something better (explore), and sometimes cash in on what it already knows works (exploit). Lean too far either way and it either never improves or never finds the best route.
This is learning by consequence rather than by imitation. No one hands the agent the right move; it tries, gets scored, and drifts toward whatever paid off. Keep it at this intuition level for now. The vocabulary, agent, environment, state, action, reward, policy, is what you carry forward.
Bridge to regression
Step back and the map is small enough to hold in your head. A learning system is a task, a performance measure, and experience. Building one is four choices: experience, target function, representation, algorithm. And the field splits three ways by the shape of the experience: labeled pairs (supervised), inputs alone (unsupervised), or action and reward (reinforcement).
Linear regression is where we make all of this concrete, and there is a reason we start there rather than with a neural network or a reinforcement agent. It is the simplest representation that actually learns: a straight line. Before you can appreciate why real problems demand curves and depth, you need the line in your hands:
Straight-line accuracy: 100%
Rotate until the line splits the two clusters. One straight cut reaches 100%. This is the world a linear model can fit.
Collapse the four design choices onto that first worked example and the next lesson writes itself:
| Design choice | In linear regression |
|---|---|
| Experience | Past examples of features paired with a known number |
| Target function | The true, unknown map from features to that number |
| Representation | A weighted sum of features, w·x + b |
| Learning algorithm | Minimise squared error, typically by gradient descent |
You already know the skeleton. Next lesson we put the real math on the bones: residuals, the sum of squared errors, the gradients, and the update rule that walks a line onto your data.
A learning system in ten lines of code
Before the quiz, make the abstraction runnable. The snippet below states one learning system in Mitchell's T / P / E terms, then shows the supervised and unsupervised worlds side by side on the same feature. Press Run. Notice that fitting a line drives the performance measure down (learning happened), and that once we hide the labels the only question left is "which points sit together".
Change the n_clusters to 3 and rerun: the unsupervised side happily returns three groups instead of two, with nothing to say which is "right". That missing answer key is the entire difference between the two paradigms.
Check your understanding
1 / 5You want to predict tomorrow's temperature from years of historical weather records. In Mitchell's framing, what are T, P, and E?
Interview readiness
Define machine learning precisely, then use your definition to explain the difference between supervised, unsupervised, and reinforcement learning.