Lecture 1
Introduction to Machine Learning
KU Leuven, campuses Diepenbeek and Geel
Academic year 2026–2027
From a recording, decide whether the bearing is healthy or faulty.
Found early, a worn bearing is replaced at a planned stop, before it breaks the machine.
A person writes the rules.
rules + data → answers
If the vibration amplitude exceeds 7 mm/s, flag the bearing.
The computer finds the rules from examples.
data + answers → rules
Here are 10 000 recordings, each marked healthy or faulty.
A language model reads billions of sentences and adjusts its parameters to predict the next word.
Given "The capital of Belgium is" it predicts "Brussels".
Same idea as this course, at a vastly larger scale: learn once, then predict many times.
Checkpoint
Block 1
| wind speed (m/s) | temperature (°C) | type | power (kW) |
|---|---|---|---|
| 4.2 | 11 | A | 85 |
| 7.9 | 9 | B | 610 |
| 12.5 | 14 | A | 2000 |
| 6.1 | 7 | C | 320 |
Predict the power a turbine delivers from the weather and its type.
One row is a sample \(\vx^{(i)} \in \R^d\).
One column is a feature \(x_j\).
The value to predict is the target \(y^{(i)}\).
\(n\) samples, \(d\) features.
The model only ever sees a vector
\[ \vx \in \R^d \]Choosing this representation is feature engineering, the second box of the workflow.
good → 0, fair → 1, poor → 2
| type | is A | is B | is C |
|---|---|---|---|
| A | 1 | 0 | 0 |
| B | 0 | 1 | 0 |
| C | 0 | 0 | 1 |
The target is a number.
Power output in kW.
The target is a class.
Bearing healthy or faulty.
Today: regression. Lecture 3: classification.
300 measurements: for example 240 for training and 60 for testing, split at random.
Which straight line fits these points best?
To answer, a number is needed that says how wrong a line is: a loss.
Checkpoint
Block 2
For each sample, the error of the line:
\[ r^{(i)} = y^{(i)} - \yhat^{(i)} \]The dashed segments in the figure.
Squared: positive and negative errors do not cancel.
Squared: large errors weigh more than small ones.
Smooth, so it can be differentiated, which the next slides need.
At the bottom of a bowl the slope is zero in every direction.
An alternative that only needs the gradient: gradient descent.
In fog on a mountain: feel the slope under your feet, take a step down, repeat.
input: X, y, learning rate η, steps T
w ← 0
repeat T times:
g ← (2/n) Xᵀ (X w − y)
w ← w − η g
return w
n = len(y)
w = np.zeros(X.shape[1])
for step in range(T):
g = 2 / n * X.T @ (X @ w - y)
w = w - eta * g
| Normal equations | Gradient descent | |
|---|---|---|
| Steps | one | many |
| Cost | grows like \(d^3\) | cheap per step |
| Needs | invertible \(\mX\T\mX\) | a learning rate |
| Other losses | no | yes |
Both minimise the same loss, so both find the same \(\vw\).
\(\yhat = \vw\T\vx\)
a straight line, a plane in more dimensions
\(\frac{1}{n}\sum_i \left(y^{(i)} - \yhat^{(i)}\right)^2\)
mean squared error
normal equations or gradient descent
solve exactly, or walk downhill
Checkpoint
Break
Block 3
with \(x_0 = 1\) for the intercept.
The matrix notation of block 2 pays off here.
Lecture 2 puts features on a common scale before comparing or penalising their weights.
The MSE is in kW², which is hard to read. Its square root is in kW:
An RMSE of 120 kW means typical errors of about 120 kW.
1: perfect predictions.
0: no better than always predicting the mean \(\bar{y}\).
Negative: worse than predicting the mean.
Lecture 2: what happens to both errors when the model becomes very flexible.
Look at the data before fitting. Losses that grow more slowly than the square are less sensitive.
Lecture 2: regularisation stabilises the weights.
A cubic fitted below 11 m/s keeps rising, while the turbine saturates at 2000 kW.
A model is only trusted inside the range of its training data.
Checkpoint
?
what shape of function
?
what counts as wrong
?
how we search
All three books are free to read online.
Polynomial features, overfitting, validation and regularisation.
Regression on a wind turbine power curve, in numpy and scikit-learn.
Bring a laptop and a Google account for Colab.