Foundations of Regression

Lesson 0

Designing 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:

A program learns from experience E w.r.t. task T and measure P    if its P on T improves with E.\text{A program \textbf{learns} from experience } E \text{ w.r.t. task } T \text{ and measure } P \;\;\text{if its } P \text{ on } T \text{ improves with } E.

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.

sizeprice
loss (the mistake)50.20
knob w (slope)
0.00
knob b (shift)
0.00
step 0

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.

1

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?

2

Choose the target function. What exactly are we trying to learn? Usually an unknown mapping from inputs to outputs.

3

Choose a representation. What family of functions will we search over? A weighted sum of features, a tree, a neural network.

4

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:

f:XYf : \mathcal{X} \to \mathcal{Y}

We never get ff itself, only examples of its behaviour. So we pick a representation, a parameterised guess f^\hat{f}. The simplest useful choice is a weighted sum of the input features:

f^(x)=wx+b\hat{f}(\mathbf{x}) = \mathbf{w}^\top \mathbf{x} + b

To turn "reduce error" into something an algorithm can chase, we need a loss, a single number measuring how wrong f^\hat{f} is on the experience. Squared error is the natural first choice:

L(w,b)=1ni=1n(yif^(xi))2L(\mathbf{w}, b) = \frac{1}{n}\sum_{i=1}^{n}\bigl(y_i - \hat{f}(\mathbf{x}_i)\bigr)^2

The learning algorithm then adjusts w\mathbf{w} and bb to make LL as small as possible. Here is the representation, a line whose slope and intercept are exactly the parameters we tune:

size (inches)price

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:

Loss curve over a single weight w
learning rate η0.060
too slowconvergesovershoots

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:

ParadigmExperience looks likeGoal
SupervisedPairs (x, y), inputs with their labelsLearn the map x → y
UnsupervisedOnly inputs x, no labelsFind structure in the data
ReinforcementActions and rewards from an environmentLearn 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 x\mathbf{x} and its known answer yy:

E={(x1,y1),(x2,y2),,(xn,yn)}E = \{(\mathbf{x}_1, y_1), (\mathbf{x}_2, y_2), \dots, (\mathbf{x}_n, y_n)\}

The task is to learn a function that reproduces yy from x\mathbf{x} 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 yy:

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:

xy
SSR (the loss J)15.8
slope m
3.20
intercept c
-2.00
step 0

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:

Two features → the boundary is a line
boundary angle45°
horizontaldiagonalvertical

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 yy to imitate:

E={x1,x2,,xn}E = \{\mathbf{x}_1, \mathbf{x}_2, \dots, \mathbf{x}_n\}

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.

Iteration 0·k = 3 clusters
unlabeled points — the algorithm sees no colors
Clusters (k)3

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.

Each round: (1) paint every dot with its nearest ✕ centroid, (2) slide each ✕ to the middle of its dots. Repeat until nothing moves.

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.

🏁+1🕳️−1START🤖
Episode 0This run: 0.00
The RL loop
🤖Agentpicks
➡️Actiona move
🌐Environmentgrid updates
🎯Reward+ / − points
↖ reward & new state loop back to the agent ↩
Cumulative reward0.00
Return per episode

Run an episode to log its total reward. Watch the bars climb as the path improves.

No one tells the agent the right move. It tries, collects reward, and shifts toward actions that paid off. Reach the 🏁 for +1, fall in the 🕳️ for −1, and every step costs a little (−0.04) — so shorter, safer paths score higher.

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 choiceIn linear regression
ExperiencePast examples of features paired with a known number
Target functionThe true, unknown map from features to that number
RepresentationA weighted sum of features, w·x + b
Learning algorithmMinimise 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".

Python
First run loads the Python runtime (~10 MB) — takes ~5–10 seconds. Subsequent runs are instant.

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 / 5
the well-posed learning problem: Task T, Performance P, Experience E

You want to predict tomorrow's temperature from years of historical weather records. In Mitchell's framing, what are T, P, and E?


Interview readiness

Q1FundamentalsGoogleAmazonMicrosoft

Define machine learning precisely, then use your definition to explain the difference between supervised, unsupervised, and reinforcement learning.

Test your understanding

Prof is ready

Prof will ask you questions about designing a learning system; supervised, unsupervised, and reinforcement learning — not explain it. You'll be surprised what you don't know until you have to say it.

Finished this lesson?

Read through the lesson first (0/20s).