Sapienza Università di Roma · BSc Mathematics of Artificial Intelligence

Applications of
Machine Learning

Applicazioni Informatiche del Machine Learning

How to build a machine learning system, and how to know whether it works.

Load
48 academic hours · 24 lectures
Year
Third year, BSc
When
Tue & Wed · 12:00–14:00 · from 6 Oct 2026
Where
Aula C · Dip. di Matematica
Teaching language
Italian · materials in English
Lecturer
Fabrizio Silvestri
Google Classroom
Join the class

The organising principle

One topic per lecture, and every lecture stands on its own.

Each lecture is the mathematics, the method, and a notebook that implements it. If you miss a lecture, you read its slides and its notebook and you are caught up — you never have to reconstruct anything from the lecture before it.

Ninety minutes, in four blocks.

The mathematics · 20 min

The one object the method rests on, derived rather than quoted — because the method does not make sense without it, and because the derivations are what you still have in five years when the libraries have changed.

The method · 40 min

How it works, what its hyperparameters do, the conditions under which it fails, and a worked example with real numbers from real data — every figure on every slide reproduced by a script in this repository.

Further ground · 15 min

The variants, when to prefer each, and what practitioners actually reach for — which is not always what the textbook presents first.

The notebook · 5 min

What is in it, what to run, and what to change to see something move. You run it yourself afterwards; the lecture is not a live coding session.

Ten minutes at the top of each lecture place it in the arc: what we can already do, what we cannot, and which of the two today’s method changes.

Working method

You will write machine learning code with an assistant — if not in this course, then in the thesis after it and in the job after that. So the course is explicit about how.

#StepWho
1Specify — the input, the output, the constraint, the checkyou
2Generate — and then stop, before running anythingthe assistant
3Read — as a reviewer, not as an authoryou
4Test — against a case whose answer you already knowyou
5Verify — that the number means what it appears to meanyou

Steps 3–5 are the course. Step 2 is the part that is free.

Where you meet this loop here. The notebooks in this course are written for you and they are correct — nothing in them is wrong on purpose. Every code cell is preceded by the specification that would produce it: the box is step 1, the cell below it is what step 2 returned, and its check line is step 4 written down in advance. Read the box, answer the check in your head, then run the cell.

Why the emphasis on verification

Machine learning fails silently. A bug in a training loop does not crash — it returns a plausible number:

Every one of these runs. Every one produces a number. Each is taught in the lecture where it belongs — leakage in Lecture 2, imbalance in Lecture 3, and all three PyTorch failures — the optimiser pair and batch averaging — in Lecture 10, as a property of the method rather than as a trap.

The notebooks are ours. The textbook supplies the syllabus, not the code. No notebook from the author, or from any other third party, is used in this course. Every one is written for it, is complete and correct, and carries above each cell the specification that would produce it.

Four rules

  1. Never keep code you cannot explain line by line. Part B of the paper puts a cell in front of you and asks what would have to be true for its number to be trusted.
  2. Every number needs a baseline. A metric with nothing to compare it to is decoration.
  3. Every model needs an ablation. Remove a component; show the number moves.
  4. Report the failure cases. A system with no known failure mode has not been tested.

Prerequisites

Short version: the mathematics of a third-year BSc in Mathematics of Artificial Intelligence, and enough Python to read code critically. If you are missing something, none of it takes long to fix — and everything below is a pointer, not a reading list to complete before the first lecture.

A note on scope. Everything taught in this course comes from Chapters 1–16 of the textbook, or — for Lectures 19–22 — from the lecture notes. The material on this page is the opposite: it is what the course assumes you already have, so the resources here necessarily point outside both. None of it is examinable in its own right.

Test yourself in ten minutes

These are not warm-up exercises. Each one is a thing you will actually be asked to do, in the lecture where it appears. Try them before deciding you need to revise anything.

  1. $\mathbf{X}$ is $m \times n$ and $\boldsymbol\theta$ is $n \times 1$. What is the shape of $\mathbf{X}\boldsymbol\theta$, and why is $\mathbf{X}^{\mathsf T}\mathbf{X}$ square?

    Lecture 2, first ten minutes.

  2. Differentiate $\lVert\mathbf{X}\boldsymbol\theta - y\rVert^2$ with respect to $\boldsymbol\theta$. Then say what has to be true of the Hessian for the stationary point to be a minimum.

    Lecture 2. This is the derivation, not a preliminary to it.

  3. When is $\mathbf{X}^{\mathsf T}\mathbf{X}$ not invertible? Answer in terms of the columns of $\mathbf{X}$.

    Lecture 2, and again in Lecture 5 when ridge repairs it.

  4. $A$ and $B$ each have variance $\sigma^2$ and correlation $\rho$. What is $\operatorname{Var}\!\left(\tfrac{A+B}{2}\right)$?

    Lecture 7. This single calculation explains bagging, random forests and extra-trees.

  5. What does a 95% confidence interval mean — and what does it not mean?

    Lecture 2, on the final test score.

  6. a has shape (100, 3), b has shape (3,). What does a - b compute, and what shape comes out? Now b has shape (100,) — what happens?

    Every lecture. Silent broadcasting is silent.

  7. Given a DataFrame df, select the rows where df["x"] > 5, keeping only columns "a" and "b". Then count how many values in "a" are missing.

    Lecture 1, in the notebook.

  8. Read this traceback out loud and say which line of your code caused it, and why:
    ValueError: Input X contains NaN.

    Lecture 2, the first time preprocessing meets a missing value.

Could you do six or more? You are ready; skip the rest of this page. Fewer? Find the matching row below. Nothing here needs more than a few evenings, and none of it needs to be finished before Lecture 1 — the items are listed in the order the course first needs them.

Filling the gaps

Mathematics

What you needFirst neededIf you are missing it
Linear algebra
matrix products, transpose, inverse, rank, column space, orthogonality, positive semi-definiteness, SVD
L2 3Blue1Brown, Essence of Linear Algebra for the geometric intuition — about three hours, and it is the intuition the Lecture 2 derivation assumes.
For depth: MIT 18.06 (Strang).
Multivariable calculus
partial derivatives, gradients, the chain rule, Hessians, convexity
L2 3Blue1Brown, Essence of Calculus, then chapter 5 of Mathematics for Machine Learning (free PDF) for vector calculus in exactly the notation we use.
Probability and statistics
expectation, variance, covariance, correlation, independence, sampling, confidence intervals
L2, L5, L7 Seeing Theory (Brown) is a visual refresher in an afternoon.
For depth: MIT 18.05, or chapter 6 of Mathematics for Machine Learning.

If you are on this degree programme you almost certainly have all three. The self-check above is a faster way to confirm that than reading the list.

Programming

What you needFirst neededIf you are missing it
Python
functions, lists and dicts, comprehensions, imports, reading a traceback
L1 The official Python tutorial, sections 3–6. A weekend from a standing start; an evening if you know another language.
NumPy
arrays, shapes, indexing, axes, and broadcasting
L1 NumPy: the absolute basics, then the broadcasting rules — read that second page twice. It is the single most common source of code that runs and is wrong.
pandas
DataFrame, Series, selection, missing values
L1 10 minutes to pandas. Optimistically named, but an hour genuinely does it.
matplotlib
enough to draw a histogram and a scatter plot
L1 The pyplot tutorial. Twenty minutes; you will not need more than this in the whole course.
Google Colab
running cells, restarting the runtime, reading a traceback
L1 Colab’s own introduction. Ten minutes. Bring a Google account to the first lecture.
scikit-learn
the estimator API — fit, transform, predict
L2 Helpful but not required — taught from scratch in Lecture 2. Lecture 1 fits nothing at all: looking properly at data before modelling it is not a preliminary, it is what decides whether the model can work. If you are curious: Getting started.
PyTorch L10 Not required. Taught from first principles in Lecture 10 — tensors, autograd, and the training loop written out in full before any of it is hidden behind a helper. If you insist: the official basics.

What you also need on the day

What you explicitly do not need

Prior machine learning

Helpful, not assumed. The course starts from a problem and a dataset on the first day and builds everything from there.

Deep learning experience

Parts II–VI assume nothing beyond what Part I established. Neural networks arrive in Lecture 9, once the classical models have been covered properly.

Software engineering

No production systems, no deployment infrastructure, no build tooling. Notebooks throughout.

Fluent typing

The notebooks are written for you. What is examined is whether you can read them — say what a cell does, what it measures, and what would break if an argument changed.

Calendar

Twenty-four lectures on Tuesdays and Wednesdays, from 6 October 2026 to 12 January 2027.

Days
Tuesday and Wednesday
Hours
12:00–14:00
Room
Aula C · Dipartimento di Matematica “Guido Castelnuovo”
Every lecture in date order, and the days inside the term that carry none.
October 2026
01 What machine learning is, and how we will work
02 The end-to-end project
03 Classification and its metrics
04 Training models
05 Regularisation and the bias–variance trade-off
06 Decision trees
07 Ensembles and random forests
08 Dimensionality reduction and unsupervised learning
November 2026
09 Neural networks, from the perceptron up
10 PyTorch
11 Training deep networks
12 Convolutional networks
13 Transfer learning
14 Detection and segmentation
15 Time series
16 Recurrent networks
December 2026
17 Text
18 Attention and transformers
Immacolata — the university is closed
19 Information retrieval: the lexical foundation
20 Information retrieval: dense retrieval
21 Recommender systems: from ratings to factors
22 Recommender systems: neural, and evaluated honestly
23 Vision transformers and multimodal retrieval
24 Dec – 6 Jan Christmas break
January 2027
24 Generation, retrieval-augmented systems, and where this leaves you

The material is not published in advance. A lecture’s slides, notebook and notes appear on this page at 11:30 on the day that lecture is taught, half an hour before it begins, and stay there for the rest of the course.

Lectures

Twenty-four lectures in six parts. Each lecture’s slides, notebook and notes appear on its own card at 11:30 on the day it is taught.

Part I — Tabular data and classical models

Lectures 1–8 · Chapters 1–8 · runs on CPU
  1. 01

    What machine learning is, and how we will work

    California housing Ch 1–2

    · 12:00–14:00 · Aula C

  2. 02

    The end-to-end project

    California housing Ch 2

    · 12:00–14:00 · Aula C

    Derivation · Least squares and the normal equation

  3. 03

    Classification and its metrics

    MNIST Ch 3

    · 12:00–14:00 · Aula C

    Derivation · Imbalance, and the non-monotonicity of precision

  4. 04

    Training models

    Titanic Ch 4

    · 12:00–14:00 · Aula C

    Derivation · Gradient descent

  5. 05

    Regularisation and the bias–variance trade-off

    Titanic Ch 4

    · 12:00–14:00 · Aula C

    Derivation · The bias–variance decomposition

  6. 06

    Decision trees

    CoverType Ch 5

    · 12:00–14:00 · Aula C

    Derivation · Impurity: Gini and entropy

  7. 07

    Ensembles and random forests

    CoverType Ch 6

    · 12:00–14:00 · Aula C

    Derivation · The variance of an average of correlated predictors

  8. 08

    Dimensionality reduction and unsupervised learning

    Olivetti faces Ch 7–8

    · 12:00–14:00 · Aula C

    Derivation · PCA via the SVD; Johnson–Lindenstrauss

Part II — Neural networks

Lectures 9–11 · Chapters 9–11 · runs on CPU
  1. 09

    Neural networks, from the perceptron up

    Fashion-MNIST Ch 9

    · 12:00–14:00 · Aula C

    Derivation · What a layer computes

  2. 10

    PyTorch

    Fashion-MNIST Ch 10

    · 12:00–14:00 · Aula C

    Derivation · Backpropagation as reverse-mode automatic differentiation

  3. 11

    Training deep networks

    CIFAR-10 Ch 11

    · 12:00–14:00 · Aula C

    Derivation · Variance propagation and weight initialisation

Part III — Computer vision

Lectures 12–14 · Chapter 12 · runs on CPU
  1. 12

    Convolutional networks

    Flowers102 Ch 12

    · 12:00–14:00 · Aula C

    Derivation · Weight sharing, equivariance and memory

  2. 13

    Transfer learning

    Flowers102 Ch 12

    · 12:00–14:00 · Aula C

  3. 14

    Detection and segmentation

    COCO Ch 12

    · 12:00–14:00 · Aula C

    Derivation · IoU’s vanishing gradient; mAP

Part IV — Sequences and language

Lectures 15–18 · Chapters 13–15 · runs on CPU
  1. 15

    Time series

    Chicago transit ridership Ch 13

    · 12:00–14:00 · Aula C

    Derivation · Stationarity, differencing and autocorrelation

  2. 16

    Recurrent networks

    Chicago transit ridership Ch 13

    · 12:00–14:00 · Aula C

  3. 17

    Text

    IMDb Ch 14

    · 12:00–14:00 · Aula C

    Derivation · Softmax, cross-entropy and logits

  4. 18

    Attention and transformers

    IMDb Ch 14–15

    · 12:00–14:00 · Aula C

    Derivation · Scaled dot-product attention

Part V — Information retrieval and recommender systems

Lectures 19–22 · Outside the book · examinable
  1. 19

    Information retrieval: the lexical foundation

    SciFact (BEIR) Outside the book

    · 12:00–14:00 · Aula C

    Derivation · Evaluating a ranking: MRR, AP, NDCG

  2. 20

    Information retrieval: dense retrieval

    SciFact (BEIR) Outside the book

    · 12:00–14:00 · Aula C

  3. 21

    Recommender systems: from ratings to factors

    MovieLens Outside the book

    · 12:00–14:00 · Aula C

    Derivation · Matrix factorisation, and its relation to the SVD

  4. 22

    Recommender systems: neural, and evaluated honestly

    MovieLens Outside the book

    · 12:00–14:00 · Aula C

Part VI — Multimodal models, and closing the course

Lectures 23–24 · Chapters 15–16 · runs on CPU
  1. 23

    Vision transformers and multimodal retrieval

    COCO Ch 15–16

    · 12:00–14:00 · Aula C

    Derivation · The contrastive objective and its temperature

  2. 24

    Generation, retrieval-augmented systems, and where this leaves you

    COCO and the Part V corpora Ch 15–16

    · 12:00–14:00 · Aula C

The mathematics

Each lecture derives the one object its method rests on. Not a parallel theory course: every derivation below does visible work on the method taught beside it, and they are 40% of the written paper.

  1. Least squares and the normal equation · Lecture 2
  2. Imbalance, and the non-monotonicity of precision · Lecture 3
  3. Gradient descent · Lecture 4
  4. The bias–variance decomposition · Lecture 5
  5. Impurity: Gini and entropy · Lecture 6
  6. The variance of an average of correlated predictors · Lecture 7
  7. PCA via the SVD; Johnson–Lindenstrauss · Lecture 8
  8. What a layer computes · Lecture 9
  9. Backpropagation as reverse-mode automatic differentiation · Lecture 10
  10. Variance propagation and weight initialisation · Lecture 11
  11. Weight sharing, equivariance and memory · Lecture 12
  12. IoU’s vanishing gradient; mAP · Lecture 14
  13. Stationarity, differencing and autocorrelation · Lecture 15
  14. Softmax, cross-entropy and logits · Lecture 17
  15. Scaled dot-product attention · Lecture 18
  16. Evaluating a ranking: MRR, AP, NDCG · Lecture 19
  17. Matrix factorisation, and its relation to the SVD · Lecture 21
  18. The contrastive objective and its temperature · Lecture 23
The derivations are cross-referential and the order matters. Lecture 5 completes Lecture 2; Lecture 14 uses Lecture 3; Lecture 21 and Lecture 23 both use Lecture 8; Lecture 20 and Lecture 22 are the same architecture twice; Lecture 23 is evaluated with Lecture 19’s metrics.

Assessment

The written examination carries the mark. The oral is optional, short, and can move that mark in either direction.

Written examination

Two hours, closed book, no formula sheet. Three parts: the derivations, choosing a method for a stated situation, and reading results — as technical exercises, closed choices with their reason, and short open answers.

Marked out of 30, pass at 18. From the written alone, the mark recorded is capped at 27.

Oral examination — optional

Seven to ten minutes. Three questions, on any topic from the course.

No notes, no computer. Open to anyone who passed the written.

How the mark is made The oral moves your written mark, up or down, and the result is final. 28, 29 and 30 exist only through the oral, and lode is a separate decision, from 30.

Sitting it is your choice, made when you see your written mark — and binding once registered. Both are taken in the same session: a written pass does not carry forward.
Why it is built this way. A grade you can improve at no risk is one everybody attempts, which turns the oral into a queue rather than an examination. Making it a real decision — three marks up, three marks down — means the people who sit it are the people with something to show. Nothing about it is hidden: the questions are published, the arithmetic is published, and neither changes after you have decided.

Can a course this applied really have a written examination?

Yes — and this course is better suited to one than most applied courses, for a specific reason.

The competence being built here is not typing. It is judgement about whether a result can be trusted, and that judgement is exercised by reading: reading code you did not write, reading a metric, reading a curve. Reading is paper-native. A written examination tests it more directly than a lab does — at a keyboard a student can arrive at the right answer by running things until they look right, whereas on paper they have to actually know.

Three rules keep it honest.

  1. No question tests API recall. Asking for the arguments of train_test_split would test what a docstring is for. Syntax errors in handwritten code cost nothing; logic errors cost everything.
  2. No question is answerable by reciting a definition. Every one requires applying it to a stated situation.
  3. The paper states what it needs. There is no formula sheet, and none is required: any definition or standard result a question depends on is printed in the question itself. What you are expected to supply is the reasoning, never the recall.

This is why closed book costs you nothing here. Each of the eighteen derivations is one you have performed — and a result you can rebuild in three lines is not a result you need to have memorised.

What a written examination cannot see is whether the reasoning on the page is yours. That is what the oral is for — and it is why it is short, and why it can go to any part of the course.

The written examination

The three parts below are weighted within the paper. The paper carries your mark: up to 27 on its own, and up to 30 if you sit the oral.

Every paper mixes three forms of question, and the parts below say what each one is about rather than what shape it takes: technical exercises worked on the page — a derivation, a gradient, an arithmetic check on a stated table; closed questions, where you choose between two or three stated options; and open questions answered in a few sentences. A closed choice is rarely enough on its own: where a question asks for the reason as well as the choice, both are needed for full marks.

PartWhat it asksWeight
of the paper
Time
A · The derivations Derive, state, apply. The eighteen objects developed in the lectures — the normal equation, the bias–variance decomposition, variance reduction by averaging, reverse-mode differentiation, cross-entropy, NDCG, and the rest. 40% ~48 min
B · Choosing a method A situation in four lines: this data, this constraint, this requirement. Which method, why that one rather than the obvious alternative, and what evidence would make you change your mind. Some questions supply a short code excerpt and ask what it would take for its reported number to be trustworthy. 35% ~42 min
C · Reading results Plots and tables — learning curves, per-fold scores, a confusion matrix, a precision/recall curve, a ranking. Say what they show, what they do not show, and which way the number moves if you change the stated thing. 25% ~30 min
Every exercise in the course, with its solution. Each deck ends with five questions in this style, answered on the following lecture’s deck. All 120 exercises are collected in one place: published once the course has run.

Three specimen questions

One from each part, at the intended level and scale — each is calibrated to the time budget above.

Illustration only. These three show the kind of thing each part asks and roughly how much of it. They are not a template, not a syllabus, and not a promise: the questions on the paper you sit may differ in form, in topic, and in how they are put.

Part A — derive, then apply

Two regressors each have variance $\sigma^2$ and are correlated with coefficient $\rho$.

  1. Show that the variance of their average is $\frac{\sigma^{2}(1+\rho)}{2}$.
  2. Bagging and a random forest differ in one respect. State it, and say which term in your expression it attacks.
  3. An ensemble of one hundred identical trees has $\rho = 1$. What does your expression predict, and is that the right answer?

Part B — choosing a method

A colleague has 4,000 labelled rows and sixty numeric features, many of them near-duplicates of one another. Every prediction has to be justified to a regulator.

  1. Ordinary least squares, ridge, lasso, or a random forest — which do you fit first, and what specifically about the situation decides it?
  2. Name the one piece of evidence that would make you abandon that choice for one of the others.

They send you this program, and the number it printed.

best = None
for a in [0.01, 0.1, 1, 10, 100]:
    m = Ridge(alpha=a).fit(X_train, y_train)
    s = root_mean_squared_error(y_test, m.predict(X_test))
    if best is None or s < best[1]:
        best = (a, s)

print(f"best alpha={best[0]}, test RMSE={best[1]:,.0f}")
  1. This program never creates a validation set. Which object is doing that job?
  2. As an estimate of the model’s error on new data, the printed RMSE is (i) too optimistic, (ii) too pessimistic, or (iii) neither. Choose one and give the reason in a sentence.
  3. Rewrite it so the printed number is honest. Two statements is enough.

Every part has a determinate answer — ridge, because the near-duplicate features make $\mathbf{X}^{\mathsf T}\mathbf{X}$ ill-conditioned and the regulator rules out the forest; the test set; (i); a cross-validated search on the training data, scored once on the test set. Nothing here rewards a well-phrased opinion, and none of it can be answered without knowing what a validation set is for.

Part C — reading results

Two teams report the following for the same dataset.

TeamTraining RMSE10-fold CV RMSE
A$0$68,574
B$68,233$68,282
  1. Name each pathology.
  2. Which model is more useful? Explain why that is not the same question as which is better fitted.
  3. One of these is helped by collecting more training data and the other is not. Which, and why?

The oral examination

Optional. Three questions, answered aloud, on any topic the course covered — there is no separate syllabus for it, and no list of questions to learn.

What happens

  • You decide after seeing your written mark. Until then there is nothing to opt into.
  • Three questions, on any topic from the course.
  • Seven to ten minutes, no notes, no computer.

What it is worth

  • Up. The only route to a mark above 27, and to lode.
  • Down. The same conversation can lower it. This is not a formality.
  • Worth sitting from below the cap too — the movement is measured from your mark, wherever it is.

Nothing is collected and nothing is graded as an artefact. The notebooks are examinable as experience: you are expected to be able to account for what they do and why, without the code in front of you.

Rule one is checked twice. Never keep code you cannot explain. Part B of the paper puts a cell in front of every candidate; the oral puts a question in front of the ones who choose it. Both apply to code an assistant wrote for you exactly as they apply to code you typed.

Note what is absent: there are no marks for a notebook that runs. Evidence earns marks.

Textbook and scope

Aurélien Géron, Hands-On Machine Learning with Scikit-Learn and PyTorch, O’Reilly, 2025 — Chapters 1–16, covering Lectures 1–18 and 23–24.

Lectures 19–22 — information retrieval and recommender systems — sit outside the book and are taught from the lecture notes. They are examinable on the same terms as everything else, and for those four lectures the notes below are the primary source — not a supplement to a chapter, because there is no chapter.

Written notes exist for every lecture — the Notes (PDF) button that appears on each card above on the day of its lecture. For the other twenty they set out the lecture’s argument at length beside the chapter it is taught from; the four listed here are the ones with no chapter behind them.

Extended lecture notesDataset
19 · Information retrieval: the lexical foundation SciFact (BEIR)
20 · Information retrieval: dense retrieval SciFact (BEIR)
21 · Recommender systems: from ratings to factors MovieLens 1M
22 · Recommender systems: neural, and evaluated honestly MovieLens 1M
Scope discipline. The examinable surface is Chapters 1–16 plus the notes for Lectures 19–22. Every section of every lecture is marked examinable, not examinable — engineering, or beyond the syllabus, for context, so you never have to guess.

Chapter coverage

ChapterLectures
1 · The machine learning landscape1
2 · End-to-end project1, 2
3 · Classification3
4 · Training models4, 5
5 · Decision trees6
6 · Ensembles and random forests7
7 · Dimensionality reduction8
8 · Unsupervised learning8
9 · Introduction to artificial neural networks9
10 · Building networks with PyTorch10
11 · Training deep networks11
12 · Deep computer vision12, 13, 14
13 · Sequences15, 16
14 · NLP with RNNs and attention17, 18
15 · Transformers18, 23, 24
16 · Vision and multimodal transformers23, 24
Lecture notes · Information retrieval19, 20
Lecture notes · Recommender systems21, 22

Practicalities