Skip to content
AriadneTechnology

The Outer Ring · Chamber 1 of 8

What Does It Mean to Learn?

Data, models and loss: the three ingredients hiding inside every machine-learning paper.

20 min 50 XP + 4 questions + 1 challengeVideoMathLabHistory

In this chamber you will

  • Describe the supervised learning setup in symbols
  • Explain what a loss function measures and why squared error is popular
  • Fit a line by hand and feel why we need an algorithm to do it

From rules to examples

For most of computing history, if you wanted a computer to do something, you wrote down the rules. To filter spam you might write: if an email contains "FREE MONEY", send it to junk. That works until spammers start writing "FR3E M0NEY", and then you are writing rules forever.

Machine learning flips the arrangement. Instead of writing rules, we collect examples, such as thousands of emails labelled spam or not spam, and let an algorithm find rules that fit them.

Traditional programming

Rules+Data ProgramAnswers

Machine learning

Data+Answers LearningRules
Machine learning turns the classic arrangement inside out: examples in, rules out.

A definition often attributed to Arthur Samuel captures the spirit: machine learning gives computers the ability to learn without being explicitly programmed. Samuel wrote the phrase "machine learning" into the title of a 1959 paper about his checkers program, which improved by playing against itself until it outplayed its creator.

The three ingredients

Nearly every machine-learning system, from a spam filter to a large language model, is cooked from the same three ingredients.

  1. 1

    Data: examples to learn from

    A dataset of nn examples, each an input xix_i paired with the answer yiy_i we want. This is called supervised learning because every example comes with its answer.

    D={(x1,y1),(x2,y2),…,(xn,yn)}\mathcal{D} = \{(x_1, y_1), (x_2, y_2), \dots, (x_n, y_n)\}
  2. 2

    A model: a function with knobs

    A function fθf_\theta that turns an input into a prediction, written y^=fθ(x)\hat{y} = f_\theta(x) (read "y-hat"). The parameters θ\theta (theta) are its knobs. Different knob settings give different predictions.

  3. 3

    A loss: a score for wrongness

    A number that says how bad the predictions are. Averaged over the dataset, it becomes the quantity we want to make small:

    L(θ)=1n∑i=1nℓ(fθ(xi), yi)\mathcal{L}(\theta) = \frac{1}{n}\sum_{i=1}^{n} \ell\big(f_\theta(x_i),\, y_i\big)

Put them together and "learning" gets a precise meaning. It is a search for the knob settings with the lowest loss:

θ⋆=arg min⁡θ  L(θ)\theta^\star = \argmin_{\theta}\; \mathcal{L}(\theta)

The fourth ingredient, an optimiser that performs that search, is the subject of the next chamber.

A tiny example: coffee and code

Let's make it concrete. We survey eight researchers and record two numbers for each: cups of coffee per day (xx) and lines of code written per day, in tens (yy).

ResearcherCoffee xxCode yy
Ada0.54.4
Grace1.55.2
Alan2.09.6
Katherine3.010.5
Claude3.513.7
Emmy4.513.8
John5.519.2
Hedy6.521.1

A natural first model is a straight line:

y^=w x+b\hat{y} = w\,x + b

It has exactly two parameters. The weight ww sets the slope and the bias bb sets the intercept. Remember those names: every neuron in every neural network has weights and a bias too.

Measuring wrongness

For a single researcher, the squared error measures how far the prediction is from the truth:

ℓ(y^,y)=(y^−y)2\ell(\hat{y}, y) = (\hat{y} - y)^2

Average it over everyone and you get the mean squared error (MSE), the loss for our line:

L(w,b)=1n∑i=1n(wxi+b⏟y^i−yi)2\mathcal{L}(w, b) = \frac{1}{n}\sum_{i=1}^{n}\big(\underbrace{w x_i + b}_{\hat{y}_i} - y_i\big)^2

Why square the errors? Three good reasons:

  • No cancellation. Every term is positive, so a prediction that's too high can't hide one that's too low.
  • Big mistakes hurt more. An error of 4 costs 16 times as much as an error of 1.
  • It's smooth. Squares are easy to differentiate, which will matter enormously in the next chamber.
Quick check +20 XP

Why not simply average the signed errors, 1n∑i(y^i−yi)\frac{1}{n}\sum_i (\hat{y}_i - y_i), instead of squaring them?

Your turn: fit the line

Time to be the optimiser. Drag the knobs and watch the dashed red residuals, the gaps between prediction and truth. Toggle Squares to see each squared error as an area: the MSE is the average of those areas.

Interactive lab

Fit the line by hand

Each dot is a researcher: x is cups of coffee per day, y is lines of code written (in tens). Turn the two knobs of the model ŷ = w·x + b until the mean squared error is as small as you can make it.
051015202501234567cups of coffee per day (x)lines of code, tens (y)

Mean squared error

14.16

Goal: MSE ≤ 1.47

Your model

ŷ = 1·x + 9

Challenge: Fit the lineGet the mean squared error within 20% of the best possible line.+30 XP

Notice what you just did. You searched a two-dimensional space of settings (w,b)(w, b), and every point in that space had a loss. That surface of losses is called the loss landscape. You explored it with your eyes and hands.

Modern networks have millions or billions of knobs, and nobody can tune those by hand. We need a systematic way to know which way to turn each knob. That is exactly what the gradient gives us, in Chamber 2.

The same calculation takes a few lines of Python with NumPy:

Python
import numpy as np

x = np.array([0.5, 1.5, 2.0, 3.0, 3.5, 4.5, 5.5, 6.5])      # cups of coffee
y = np.array([4.4, 5.2, 9.6, 10.5, 13.7, 13.8, 19.2, 21.1])  # lines of code (tens)

def mse(w, b):
    y_hat = w * x + b                  # the model's predictions
    return np.mean((y_hat - y) ** 2)   # the loss

print(mse(1.0, 9.0))  # 14.16  (a poor guess)
print(mse(3.0, 2.0))  # 1.29   (much better)

Watch: where this is heading

Neural networks use exactly this recipe with a far more flexible model: data, a function with (many) knobs, a loss, and an optimiser. This beautiful visual introduction shows what those knobs look like inside a network.

But what is a neural network?3Blue1Brown · 19 min

The real goal: new data

Here's a subtle point that separates practitioners from scientists. We don't actually care about the loss on our eight researchers. We already know their answers! We care about the ninth researcher, the one we haven't met.

A model that memorises its training data is like a student who memorises the answer key: perfect on the practice exam, lost on the real one. The ability to perform well on unseen data is called generalisation, and measuring it honestly is one of the central themes of this course. You'll learn the tools in Chamber 5 and the discipline in Chamber 7.

Key takeaways

  • Machine learning learns rules from examples instead of hand-writing them.
  • The recipe: data D\mathcal{D}, a model fθf_\theta with parameters θ\theta, a loss L(θ)\mathcal{L}(\theta), and an optimiser that minimises it.
  • Mean squared error averages squared residuals, so errors can't cancel and big mistakes cost more.
  • Learning is optimisation, θ⋆=arg min⁡θL(θ)\theta^\star = \argmin_\theta \mathcal{L}(\theta), but the real goal is performance on new data.

Checkpoint

Prove it to the labyrinth

Answer every question to clear this chamber. First-try answers earn the most XP.

0/3
Question 1 of 3 +20 XP

In supervised learning, what does the training data consist of?

Question 2 of 3 +20 XP

A model predicts y^=7\hat{y} = 7 where the true target is y=4y = 4. What is the squared error ℓ=(y^−y)2\ell = (\hat{y} - y)^2?

Question 3 of 3 +20 XP

Which statement best describes what learning means for a model fθf_\theta?

End of the chamber

Clear this chamber

  • Questions in this chamber (0/4 solved)Next unsolved
  • Bonus: Fit the line (+30 XP)
+50 XPDatasetModelParametersLoss Function