TL;DR

  1. Machine learning automates inductive inference: from finitely many examples to a general rule. This only works with an inductive bias (an idea of what we look for) and only if the data contains a signal about the output.
  2. Setup: on . A loss says how expensive an error is. The true risk is . The Bayes risk is the best possible risk, and a function attaining it is a Bayes classifier .
  3. For the 0-1 loss, the Bayes classifier is explicit: iff (Theorem 2). Its error at is .
  4. Surrogate losses (hinge, squared, exponential, logistic) act on a real scoring function . They have different Bayes predictors , but after thresholding at 0 all of them give the 0-1 Bayes classifier: they are classification-calibrated.
  5. For regression with the squared loss, the Bayes predictor is the regression function (Theorem 4), because .
  6. Decision theory: priors only, maximum likelihood, maximum a posteriori, and the Bayes decision rule with costs: predict the label with the smallest conditional risk. For two classes: predict 1 iff . Decision boundaries are the points where the two weighted curves cross.

Exam relevance

  • Real exam, task type “Bayes decision” (4 P): a diagram of class-conditional densities is given. You determine the decision boundaries mathematically for ML, MAP or a cost-sensitive rule, compute the error, and reason backwards: which prior or which cost ratio produces a given boundary. See Reading decision boundaries off a diagram.
  • Mock exam, task 3: cost-sensitive Bayes classification on a discrete : , , the Bayes classifier and its error, the threshold , the smallest prior that flips a decision. See the task on the Bayes classifier.
  • Multiple choice: consistency of definitions (Bayes risk vs. Bayes classifier, ML vs. MAP), which loss gives which Bayes predictor.
  • Sheet 1, Exercise 2 is the same task type as the exam (three classes, prior and loss from a given rule). Exercise 3 is the proof.

Overview: 1. A very short history of AI and ML, 2. Machine learning as inductive inference, 3. The statistical setup: loss, risk, Bayes classifier, 4. Optimal predictions in closed form (0-1 loss, surrogate losses, loss), 5. Statistical and Bayesian decision theory, 6. Reading decision boundaries off a diagram (exam training).

Introduction

A very short history of AI and ML

Slides 4-23

The lecture starts with a short history (for a longer version, see the introduction of Hardt and Recht, Patterns, Predictions, and Actions).

DecadeWhat happened
1950sAI gets “invented” at the Dartmouth Summer Conference (1956). Main paradigm: symbolic AI. Rosenblatt’s perceptron (1957) is the first machine that learns: 400 photosensors, a 20 × 20 pixel image, two classes. Huge optimism (“within ten years a digital computer will be the world’s chess champion”, Simon 1958).
1960sSymbolic AI, ELIZA (1966) mimics a psychotherapist with pattern matching. Minsky and Papert (1969): a single-layer perceptron can only learn linearly separable functions, for example not XOR, and nobody knows how to train multi-layer perceptrons.
1970sAI winter (Lighthill Report, 1973). First steps in statistical pattern recognition: kNN, naive Bayes, Bayesian decision theory, learning from few hand-designed features.
1980sBackpropagation makes multi-layer networks trainable (hand-written digits). Decision trees (ID3).
1990sDeep Blue beats Kasparov (brute-force search, no learning). Modern ML rises: support vector machines, first generalization bounds (VC dimension).
2000sML becomes practical: kernel methods, boosting, random forests and bagging, concentration inequalities and generalization bounds. Spam filtering, recommender systems, bioinformatics. DARPA Grand Challenge (2005), Watson wins Jeopardy (2011).
2010sDeep neural networks: ImageNet with CNNs and GPUs (2012), AlphaGo (2016), transformers (Vaswani et al., 2017).
2020sGenerative AI for images, audio, text and video. Language and foundation models, coding agents.

Several topics of this course appear here: the perceptron (Lecture 2), the VC dimension (Lecture 3), boosting and bagging (Lecture 6) and deep networks in the overparameterized regime (Lecture 8).

What this lecture is about

Slides 28, 30-32

The lecture is rather theoretical. It tries to make the point why and under which assumptions machine learning works or doesn’t work:

  • the statistical setup of machine learning: Bayesian decision theory, convergence, consistency, estimation and approximation error, bias-variance tradeoff
  • the fundamental principles that enable machine learning (learning theory, stability, regularization, aggregation), both in the classical and in the overparameterized regime
  • learning in the interpolation regime and why and when it works
  • practical issues: data, training, validation, benchmarking
  • machine learning and society: fairness, discrimination, explainability, legal frameworks

Not covered: basic ML algorithms (see an introductory ML course), unsupervised learning, reinforcement learning, probabilistic learning, online learning, time series, images and language models.

Required: maths for ML (linear algebra, multivariate calculus with gradients and Hessians, probability theory) and some first ML algorithms. Literature: mainly Hardt and Recht (2022) and Shalev-Shwartz and Ben-David (2014), sometimes Bach (2024), Hastie, Tibshirani and Friedman, Mohri, Rostamizadeh and Talwalkar, Hardt’s book on benchmarks, and Devroye, Györfi and Lugosi (1996).

Machine learning as inductive inference

Deduction vs. induction

Slides 35-39

Deductive inference

Reasoning from one or more general statements (premises) to a logically certain conclusion. If the premises are correct, all conclusions are correct as well.

Example: every person in this room is a student, every student is older than 10 years, so every person in this room is older than 10 years. Mathematics is built on deduction. But deduction has no natural way to deal with uncertainty about the premises.

Inductive inference

Reasoning that constructs or evaluates general propositions derived from specific examples. The conclusion can always be wrong.

Example: in all our experiments, dropped things fall downwards, so we conclude that things always fall downwards. Humans draw such uncertain conclusions from limited experience all the time.

Machine learning (one way to define it)

Machine learning tries to automate the process of inductive inference.

Why should machine learning work at all?

Slides 40-44

Regression example: we are given input-output pairs with , and want to learn a function . What is ?

Five data points on the interval from 0 to 1, rising roughly linearly
Slide 40: the data. What is f(0.4)?
Two guesses: a straight line and a wiggly curve through the same points
Slide 41: two guesses that both fit the data.
Many random points: the data came from a random number generator
Slide 43: the Y values were random numbers.

Both guesses on slide 41 fit the data perfectly. Which one is better cannot be decided from the data alone.

Consequence 1: inductive bias

We need to have an idea what we are looking for. This is called the “inductive bias”. Learning is impossible without such a bias.

Examples: is periodic (daily temperatures), is “simple” (caution, see learning theory later), similar inputs lead to similar outputs.

Now the lecturer reveals that the were produced by a uniform random number generator (slide 43). Then no prediction for is better than any other.

Consequence 2: there must be a signal

We can only learn if there is something we can learn: the input has to contain some signal about the output (Y “has something to do” with X, there is a simple rule that produces the output).

Excursion: inductive bias in animal learning

Slides 45-47

Rats get two kinds of water, one makes them sick.

  • Experiment 1: the two kinds taste differently. Rats learn very fast to avoid the water that makes them sick.
  • Experiment 2: the same taste, but one kind comes with audio-visual stimuli (sounds, light). Rats do not learn to avoid it.

From the point of view of evolution, the taste of food is related to getting sick, sounds are not. The rat has an inductive bias. In psychology this is the Garcia effect (Garcia et al., 1960s).

Bottom line

Machine learning can only work on reasonable data. Any successful learning algorithm has an inherent inductive bias. For some algorithms the bias is obvious, for others it is hard to understand what it is and how to change it. But if the algorithm works, there has to be a bias. The rest of the course makes this precise.

Predicting based on perfect knowledge

The standard statistical setup

Slides 48-54

In this section we assume complete knowledge of the distribution and ask how to derive the best predictions from it (Bach Sec. 2, Devroye et al. Sec. 2, Hastie et al. Sec. 2.4-2.9).

Data spaces and distribution

  • input space , output space (each with a -algebra, which we ignore)
  • a probability distribution on
  • no assumption on the form of , and both inputs and outputs are random quantities

Classifier, prediction function

A function . If is discrete this is classification, if it is regression (other outputs, for example structured prediction, are possible).

Loss function

A function that measures how “expensive” an error is.

  • 0-1 loss for classification: if and otherwise
  • squared loss for regression:

The choice of the loss influences the inductive bias.

Sometimes the loss has to depend on (a wrong medical decision is worse for some patients than for others), and sometimes on the order of and : predicting “healthy” for a sick person is worse than the other way around. Later we often drop and write .

True risk

Slide 55

True risk (true expected loss)

The expectation is over the random draw of . The goal of machine learning is to use the training data to construct a function whose true risk is as small as possible.

Bayes risk and Bayes classifier

Slide 56

Bayes risk and Bayes classifier

If the infimum is attained, is called the Bayes classifier (or Bayes predictor). It is not necessarily unique.

Trap

is a number (the smallest achievable risk), is a function. only if is a deterministic function of . With overlapping classes, even the Bayes classifier makes errors.

Optimal prediction functions in closed form

Classification under 0-1 loss: the regression function

Slides 57-62

Let on . We describe by two quantities:

Marginal and regression function

  • is the marginal distribution of :
  • the regression function is . For binary classification,

Intuition

If is close to 0 or 1, classifying is easy: almost all points at have the same label. If is close to , both labels are about equally likely at , and every classifier makes many errors there.

Proposition 1 (unique decomposition)

The distribution is uniquely determined by and .

Intuition (discrete case):

The formal proof for the general case is in the first pages of Devroye, Györfi and Lugosi.

Mini example: from a joint table to and

0.100.45
0.300.15

, . , . Backwards: gives the table again.

Explicit form of the Bayes classifier for the 0-1 loss

Slides 63-67

Under the 0-1 loss, the risk counts how often a classifier fails:

The Bayes classifier was defined implicitly as the minimizer. Now consider

Theorem 2 ( is a Bayes classifier)

Consider classification with the 0-1 loss. Let be any (measurable) classifier. Then

So : for the 0-1 loss we have an explicit formula for the Bayes classifier. In practice this does not help, because we do not know .

Consequence: the Bayes error

Step 1 with gives the pointwise error . So

In words: at every , the Bayes classifier loses the smaller of the two joint probabilities.

Exam-style task: Bayes classifier on a discrete input (4 P)

Let and with prior and class conditionals

012
0.10.30.6
0.50.30.2

(a) (1 P, easy) Compute and for all and state the 0-1 Bayes classifier.

(b) (1.5 P, harder) Compute the Bayes error. Then use the loss , with : which classifier is optimal now, and what is its risk?

(c) (1.5 P, backwards) For which values of does the optimal classifier predict 1 at (ties toward 1)?

→ Practice: Mock exam, task 3 (same structure, different numbers). Sheet 1, Exercise 3 for the version.

Other classification losses: scoring functions

Slides 68-73

The 0-1 loss is hard to work with: it is not continuous and not convex, so it cannot be optimized with gradients. So one uses other loss functions. To account for this, the setup changes slightly:

Scoring function

For binary classification with labels , consider a real-valued scoring function and threshold it at 0:

A point is classified correctly iff . The product is the margin.

The Bayes predictor is the scoring function that minimizes the risk, , and the classifier is . With labels the regression function becomes

so and . The 0-1 Bayes classifier is iff iff .

There are many losses in this regime: hinge, squared, exponential, logistic. For binary classification, the cross-entropy loss coincides with the logistic loss.

Loss as a function of y times f(x): the 0-1 loss is a step at 0, hinge, truncated squared, exponential and logistic losses are convex upper bounds that decrease with the margin
Slide 73: losses as functions of the margin y·f(x). Negative margin: wrongly classified, positive margin: correctly classified.

Bayes predictors for various loss functions

Slides 74-78

Bayes predictors (slide 74)

nameloss Bayes predictor classifier
hinge if , if iff
squared iff
exponential iff
logistic iff

Two observations (slide 75)

  • Different losses give different Bayes predictors: they induce different inductive biases, because they prefer slightly different scoring functions.
  • Surprisingly, the thresholded classifiers are all the same and coincide with the Bayes classifier under the 0-1 loss. This property has a name: the loss is classification-calibrated (more later in the course).

Mini example:

Then and .

  • hinge:
  • squared:
  • exponential:
  • logistic:

Four different scores, one label: all are positive, so all predict , like the 0-1 Bayes classifier ().

Left: the losses as functions of the margin. Right: the conditional risk at a point with the chosen η(x), with the minimizer of each loss marked. Move η across 0.5 and watch all minimizers change sign together.

The exponential loss comes back in Lecture 6: AdaBoost minimizes it.

Regression under the squared loss

Slides 79-84

Regression looks similar, with one important difference: can be any real number, so we cannot split into the two cases . Conditional expectations are integrals, not sums. Consider the squared loss and the regression function .

Proposition 3 (decomposition)

An inequality with would be trivial (triangle inequality). The equality is not.

Theorem 4 (explicit form of the optimal solution)

The function minimizes the risk.

Proof: in Proposition 3, the second term does not depend on . The first term is and equals 0 for .

Mini example: Bayes predictor and Bayes risk for the squared loss

with . Given , is 1 or 3 with probability each. Given , is 2 or 6.

  • , : this is .
  • Bayes risk .
  • The constant has risk .

The same result in Sheet 1, Exercise 3: minimize pointwise, gives , and the Bayes risk is : the noise that no predictor can remove.

Statistical and Bayesian decision theory

More than just Bayes classifiers

Slides 85-88

So far we derived the explicit Bayes classifier for particular losses. Now we look at several ways to come up with “perfect classifiers” in a slightly more abstract setting (Hastie Sec. 2.4-2.9, Devroye Sec. 2).

Running example: predict the gender of a person from the body height. We know the class conditional distributions (two bell curves, the female one peaks around 165 cm, the male one around 178 cm). How would you label ?

Approach 1: just look at the priors

Slides 89-90

Decide based on the class priors only: always predict the label of the larger class.

Visually: select the higher bar. This ignores completely (“a bit stupid”). Its error is .

Approach 2: maximum likelihood principle

Slides 91-92

Decide based on the likelihood functions , the class conditional distributions and . Predict the label with the higher likelihood:

Visually: select according to which class-conditional curve is higher. ML ignores the priors.

Approach 3: Bayesian a posteriori criterion

Slides 93-94

Decide based on the posterior distributions (Bayesian maximum a posteriori, MAP). Compute

and predict iff . Visually: select according to which posterior curve is higher. The denominator is the same for both classes, so MAP compares .

MAP = Bayes classifier for the 0-1 loss

The MAP rule is exactly from Theorem 2: predict 1 iff . With a uniform prior, MAP and ML coincide.

Approach 4: take the costs of errors into account

Slide 95

Bayes decision rule

  • A loss says how much we lose by predicting when the true label is .
  • The conditional risk at is the expected loss when predicting (randomness only in the true label of ):
  • Bayes decision rule: select the label for which the conditional risk is minimal.

For two classes write for the loss of predicting when the truth is (correct predictions cost 0). Then is the cost of missing a 1 and the cost of a false 1:

Two-class Bayes decision rule (the one formula for the exam)

Predict 1 iff , equivalently

  • 0-1 loss (): MAP, threshold .
  • additionally uniform prior: ML, likelihood ratio .
  • The decision boundaries are the points where : where the two weighted curves cross.

With the mock exam’s notation , this is .

flowchart LR
  A["priors P(Y)"] --> R1["Approach 1: larger class"]
  B["likelihoods P(X|Y)"] --> R2["Approach 2: maximum likelihood"]
  A & B --> C["posterior P(Y|X) (Bayes rule)"] --> R3["Approach 3: MAP = Bayes classifier for 0-1 loss"]
  C & D["costs ℓ"] --> R4["Approach 4: Bayes decision rule, minimal conditional risk"]

Which way does the boundary move?

Increasing or makes class 1 “cheaper to predict”: the region where we predict 1 grows, and the boundary moves towards class 0. On the slides: with prior the threshold moves from about 172 cm to about 160 cm, and people are called male at smaller heights.

Simulations: the lecturer’s demo

Slides 96-104

The slides show simulations (script demo_bayesian_decision_theory.py) for the stylized model height, gender. Each panel shows: class conditionals , priors , marginal , posteriors , the loss weights, the pointwise risk and the overall risk of a threshold (everybody with height is predicted female).

Equal priors and equal losses: posteriors cross in the middle, the risk curve has its minimum at about 172
Slide 97: equal priors, equal losses. The optimal threshold sits where the posteriors cross.
Prior 0.8 for male and loss 2 for predicting female when the person is male: the optimal threshold moves far to the left
Slide 100: P(m) = 0.8 and calling a male "female" costs 2 (the other error 0.5). The threshold moves far to the left.
SlidePriors Losses , Optimal threshold
970.5, 0.51, 1in the middle (≈ 172 cm)
980.2, 0.81, 1lower (≈ 160 cm): more people are called male
990.5, 0.50.5, 2lower: missing a male is expensive
1000.2, 0.80.5, 2much lower: both effects push the same way
1010.2, 0.82, 0.5back up (≈ 172 cm): prior and costs cancel

On slide 101 the effects cancel exactly: , so the weighted curves are the unweighted ones scaled by the same factor.

Risk of a threshold rule (slides 102-104)

With “predict iff ”, all males below and all females above are misclassified:

where is the loss for predicting when the truth is , and the marginal density.

Trap

The slides write this in short form as and . Written out exactly, the probabilities are joint probabilities, and inside the integral the posterior is weighted with the marginal density . Equivalently, .

The demo of slides 96-104 to play with. Change priors and costs and watch the Bayes, ML and MAP boundaries, the posterior with its threshold and the risk of every threshold. The exam presets use boxes and triangles like in the tasks below.

Reading decision boundaries off a diagram

This section is exam training for the real exam’s Bayes task: you get a diagram of the class-conditional densities (often boxes or triangles, sometimes Gaussians) and have to determine the decision rule mathematically.

Recipe

  1. Read the densities and off the diagram and write them as formulas on each piece where they are non-zero.
  2. Weight them: and . (ML: no weights. MAP: priors only.)
  3. Where only one class has density, predict that class. In the overlap, predict 1 where .
  4. Boundary: solve on the overlap (constant pieces: compare heights; linear pieces: a linear equation; Gaussians with equal variance: a linear equation in after taking logs).
  5. Error of the rule: integrate the smaller weighted curve, (with only, without costs, for the 0-1 error).
  6. Backwards: plug the given boundary into and solve for the unknown prior or cost ratio.

Exam-style task: boxes (4 P)

Box densities: p(x|Y=0) = 1/4 on [0,4], p(x|Y=1) = 1/6 on [2,8]

(a) (1 P, easy) Give the maximum likelihood decision rule.

(b) (1.5 P, harder) Let and use the 0-1 loss. Give the Bayes classifier and its error.

(c) (1.5 P, backwards) For which priors does the 0-1 Bayes classifier predict 1 on ? With a uniform prior instead, which cost ratio achieves the same?

Exam-style task: triangles (4 P)

Triangle densities: p(x|Y=0) on [0,4] with peak 1/2 at 2, p(x|Y=1) on [2,6] with peak 1/2 at 4

(a) (1 P, easy) Write down both densities on the overlap and give the ML boundary.

(b) (1.5 P, harder) Let with the 0-1 loss. Compute the Bayes boundary and the Bayes error.

(c) (1.5 P, backwards) The 0-1 Bayes classifier has its boundary at . Which prior was used?

Exam-style task: Gaussians with equal variance (4 P)

with , , .

(a) (1 P, easy) Give the boundary for the uniform prior and the 0-1 loss.

(b) (1.5 P, harder) Show that in general the boundary is and evaluate it for with the 0-1 loss.

(c) (1.5 P, backwards) With a uniform prior the observed boundary is . What cost ratio was used? Interpret.

Unequal variances

If , the log-likelihood ratio is quadratic in and there can be two boundaries: the class with the wider density wins on both sides. Then no single threshold is optimal. Try the preset “Unequal spreads” in the explorer above.

Exam-style task: three classes (4 P)

Three classes with box densities: on , on , on .

(a) (1 P) Give the ML rule on .

(b) (1.5 P) Priors , , , 0-1 loss. Give the MAP rule.

(c) (1.5 P) With the uniform prior, give a loss that makes the Bayes rule never predict .

Summary

ApproachUsesRule (two classes)Boundary where
1. Priors onlylarger class, alwaysno boundary
2. Maximum likelihoodclass conditionals cross
3. MAP (= 0-1 Bayes classifier),
4. Bayes decision ruleposterior and costs
LossBayes predictorBayes risk
0-1
squared (regression)
hinge, squared, exponential, logistic (scores)see the table abovethresholded: same classifier as 0-1

Self-Test

Multiple Choice

References