Second half of Core Ia: Introduction To Machine Learning And Statistics.
Same procedure as part 1 with lectures and workshops on Monday and Thursday. There are four notebooks but eight lectures.
Course website: https://miscada-ml-2627.notes.dmaitre.phyip3.dur.ac.uk/
Notebook server: https://miscada-ml-2627.notebooks.danielmaitre.phyip3.dur.ac.uk/
I'm Will Yeadon and will be organising this portion of the course
Can contact me via email will.yeadon@durham.ac.uk
Office is PH333 in Rochester Building






Machine Learning is a subset of artificial intelligence that focuses on enabling computers to learn from data and improve their performance over time without being explicitly programmed.
In short: a career in ML today means turning learning algorithms into reliable, scalable tools — not just developing new maths.



In 1865, Jevons argued that more efficient steam engines could increase total coal use by making steam power cheaper and opening up more uses for it.
Imagine AI halves the time an analyst needs for each analysis. If lower costs triple demand, the numbers could look like this.
| Measure | Before | With AI |
|---|---|---|
| Analyses per month | 100 | 300 |
| Analyst hours per analysis | 2 | 1 |
| Total analyst hours per month | 200 | 300 |
More demand can outweigh the time saved per task. The PwC figures raise the question of whether this mechanism is at work.
Machine learning algorithms can be classified according to:



>
The boundary between the two types can be blurred:
Some problems can be approached using either classification or regression techniques, depending on the desired outcome.


Take one pass through six training examples in order. Each set of brackets marks the examples used together for one training step.
| Mode | Groups of examples | Steps |
|---|---|---|
| Full batch | \((1,2,3,4,5,6)\) | 1 |
| Mini-batch of two | \((1,2)\;\; (3,4)\;\; (5,6)\) | 3 |
| Online, one at a time | \((1)\;\; (2)\;\; (3)\;\; (4)\;\; (5)\;\; (6)\) | 6 |
The parameters stay fixed within each group. They can change before the next group is processed.
The entire training set is used for each iteration of the model optimization.
Advantages:
Disadvantages:
The model is optimized using small subsets (batches) of the training set.
Advantages:
Disadvantages:
The model is updated incrementally as each new training example arrives.
Advantages:
Disadvantages:
We want to identify a flower from two measurements. Let \(x_1\) be its petal length and \(x_2\) its petal width, both in centimetres.
For a binary example, we use two species from the Iris dataset.
We will train on a few labelled flowers and use the learned rule to predict a species from a new pair of measurements.
Each observation has two features \(x=(x_1,x_2)\) and a known species label \(y\).
| Flower | Petal length (cm) | Petal width (cm) | Species | Label |
|---|---|---|---|---|
| A | 1.1 | 0.1 | Setosa | −1 |
| B | 5.1 | 1.6 | Versicolor | +1 |
| C | 1.2 | 0.2 | Setosa | −1 |
For A, the input is \(x=(1.1,0.1)\) and the target is \(y=-1\).
Data from the scikit-learn Iris dataset.
Multiply each feature by its weight, add the results, then add the bias \(b\).
\[ z=w_1x_1+w_2x_2+b=w^\top x+b. \]
The dot product \(w^\top x\) is shorthand for the weighted sum. There is one weight per feature.
Compare the score to zero to get a prediction \(\hat y\).
\[ \hat y=\begin{cases} +1 & \text{if } z\ge 0,\\ -1 & \text{if } z<0. \end{cases} \]
At \(z=0\) the score is tied. Here we assign \(+1\) to a tie when making a prediction.
Suppose we already have \(w=(0.5,1.0)\) and \(b=-3\), so \(z=0.5x_1+x_2-3\).
Flower A has \(x=(1.1,0.1)\). Its score is \(0.5*(1.1)+1.0*(0.1)-3=-2.35\), so we predict setosa.
What score and predicted species does the same rule give flower B at \(x=(5.1,1.6)\)?
\[ z=0.5*(5.1)+1.0*(1.6)-3=2.55+1.6-3=1.15. \]
The score is positive, so \(\hat y=+1\) and we predict versicolor. That matches B's known label.
For \(z=0.5x_1+1.0x_2-3\), the dashed line \(x_2=3-0.5x_1\) is where \(z=0\).
Imagine finding more squares close to B. The filled markers A, B and C are the original flowers. The open markers are hypothetical.
The dashed line now misclassifies several squares. The solid line moves closer to B and separates these points.
Now imagine finding more circles close to A and C. The filled markers are the same three flowers, and the open markers are hypothetical.
Here a line closer to A and C works. Both solid lines fit the original three flowers, yet they predict different labels for points between them.
In our Iris example, increasing \(b\) from \(-3\) to \(-2\) shifts the line from \(x_2=3-0.5x_1\) to \(x_2=2-0.5x_1\).
With more than two features, the same boundary \(w^\top x+b=0\) is called a hyperplane.

During training we know the true label \(y\). Multiply the current score by this label to get the signed score \(yz\).
A setosa flower with \(y=-1\) and \(z=-3\) has \(yz=3\), so it needs no update.
When \(yz\le 0\), use the current example \(x\) and its true label \(y\) to change the parameters.
\[ w_{\text{new}}=w+\eta yx,\qquad b_{\text{new}}=b+\eta y. \]
The learning rate \(\eta>0\) sets the size of the change. Take \(\eta=1\) for the example that follows.
One epoch means visiting each training example once. We score each example using the current parameters.
Any update takes effect straight away. The next example is scored using the updated \(w\) and \(b\).
A whole pass with no updates means every training example has a score strictly on the correct side of zero.
Start with \(w=(0,0)\), \(b=0\) and \(\eta=1\). In every epoch we visit the flowers in order A, B, C.
We will add one row per visit. Each row gives the score before any update, the changes \(\Delta w,\Delta b\), and the parameters passed on to the next flower.
A has \(x=(1.1,0.1)\) and \(y=-1\). What is its score, and what happens to \(w\) and \(b\)?
A scores \(0\). The tie triggers an update. Since \(y=-1\), subtract \((1.1,0.1)\) from \(w\) and subtract \(1\) from \(b\).
| Visit | Flower | Label | Score before | \(\Delta w\) | \(\Delta b\) | New \(w\) | New \(b\) |
|---|---|---|---|---|---|---|---|
| 1 | A | −1 | 0 | (−1.1, −0.1) | −1 | (−1.1, −0.1) | −1 |
With these new parameters, what score does B at \(x=(5.1,1.6)\) get? B has \(y=+1\).
B scores \((-1.1)(5.1)+(-0.1)(1.6)-1=-6.77\). Its label is \(+1\), so we add \((5.1,1.6)\) to \(w\) and add \(1\) to \(b\).
| Visit | Flower | Label | Score before | \(\Delta w\) | \(\Delta b\) | New \(w\) | New \(b\) |
|---|---|---|---|---|---|---|---|
| 1 | A | −1 | 0 | (−1.1, −0.1) | −1 | (−1.1, −0.1) | −1 |
| 2 | B | +1 | −6.77 | (5.1, 1.6) | +1 | (4.0, 1.5) | 0 |
Will these parameters classify C at \(x=(1.2,0.2)\) correctly? C has \(y=-1\).
C scores \(4.0(1.2)+1.5(0.2)=5.10\). We subtract \((1.2,0.2)\) from \(w\) and subtract \(1\) from \(b\). C's score drops to \(+2.62\), so the model still predicts versicolor.
| Visit | Flower | Label | Score before | \(\Delta w\) | \(\Delta b\) | New \(w\) | New \(b\) |
|---|---|---|---|---|---|---|---|
| 1 | A | −1 | 0 | (−1.1, −0.1) | −1 | (−1.1, −0.1) | −1 |
| 2 | B | +1 | −6.77 | (5.1, 1.6) | +1 | (4.0, 1.5) | 0 |
| 3 | C | −1 | +5.10 | (−1.2, −0.2) | −1 | (2.8, 1.3) | −1 |
What has this change done to the score of flower A?
A was correct after visit 1. Adding B made A's score \(+4.55\), and subtracting C brought it down to \(2.8(1.1)+1.3(0.1)-1=2.21\). A still has the wrong sign and triggers an update at the start of epoch 2.
| Visit | Flower | Label | Score before | \(\Delta w\) | \(\Delta b\) | New \(w\) | New \(b\) |
|---|---|---|---|---|---|---|---|
| 1 | A | −1 | 0 | (−1.1, −0.1) | −1 | (−1.1, −0.1) | −1 |
| 2 | B | +1 | −6.77 | (5.1, 1.6) | +1 | (4.0, 1.5) | 0 |
| 3 | C | −1 | +5.10 | (−1.2, −0.2) | −1 | (2.8, 1.3) | −1 |
| 4 | A | −1 | +2.21 | (−1.1, −0.1) | −1 | (1.7, 1.2) | −2 |
Does B, with \(y=+1\), need an update on this pass?
B scores \(1.7(5.1)+1.2(1.6)-2=8.59\). The score agrees with its label \(+1\), so both changes are zero.
| Visit | Flower | Label | Score before | \(\Delta w\) | \(\Delta b\) | New \(w\) | New \(b\) |
|---|---|---|---|---|---|---|---|
| 1 | A | −1 | 0 | (−1.1, −0.1) | −1 | (−1.1, −0.1) | −1 |
| 2 | B | +1 | −6.77 | (5.1, 1.6) | +1 | (4.0, 1.5) | 0 |
| 3 | C | −1 | +5.10 | (−1.2, −0.2) | −1 | (2.8, 1.3) | −1 |
| 4 | A | −1 | +2.21 | (−1.1, −0.1) | −1 | (1.7, 1.2) | −2 |
| 5 | B | +1 | +8.59 | (0, 0) | 0 | (1.7, 1.2) | −2 |
What score does C get this time, and does it trigger an update?
C scores \(1.7(1.2)+1.2(0.2)-2=0.28\). Its label is \(-1\), so we subtract its features again and lower \(b\) by 1.
| Visit | Flower | Label | Score before | \(\Delta w\) | \(\Delta b\) | New \(w\) | New \(b\) |
|---|---|---|---|---|---|---|---|
| 1 | A | −1 | 0 | (−1.1, −0.1) | −1 | (−1.1, −0.1) | −1 |
| 2 | B | +1 | −6.77 | (5.1, 1.6) | +1 | (4.0, 1.5) | 0 |
| 3 | C | −1 | +5.10 | (−1.2, −0.2) | −1 | (2.8, 1.3) | −1 |
| 4 | A | −1 | +2.21 | (−1.1, −0.1) | −1 | (1.7, 1.2) | −2 |
| 5 | B | +1 | +8.59 | (0, 0) | 0 | (1.7, 1.2) | −2 |
| 6 | C | −1 | +0.28 | (−1.2, −0.2) | −1 | (0.5, 1.0) | −3 |
That ends epoch 2. The next pass will start with \(w=(0.5,1.0)\) and \(b=-3\).
At the start of epoch 3, \(w=(0.5,1.0)\) and \(b=-3\).
What scores will A, B and C get with these parameters? Will any of them trigger an update?
Here are the scores as each flower is visited. Bold scores trigger an update.
| Epoch | A (label −1) | B (label +1) | C (label −1) | Updates |
|---|---|---|---|---|
| 1 | 0 | −6.77 | +5.10 | 3 |
| 2 | +2.21 | +8.59 | +0.28 | 2 |
| 3 | −2.35 | +1.15 | −2.20 | 0 |
On the third pass, all three scores have the correct sign. The final rule is \(z=0.5x_1+x_2-3\), the same one we used earlier.
For the example that triggered the update, the score changes by
\[ \Delta z=(\Delta w)^\top x+\Delta b =\eta y\bigl(x^\top x+1\bigr). \]
Since \(y^2=1\), the change in its signed score is \(\Delta(yz)=\eta\bigl(\lVert x\rVert^2+1\bigr)>0\).
Each update pushes that point's score towards the correct sign. It can take more than one visit to get there.
A larger \(\eta\) makes a larger change to each parameter on an update.
Starting from zero, doubling a fixed \(\eta\) doubles the weights, the bias and the scores at every step for the same example order.
Every score keeps its sign, so the same examples trigger updates and every prediction stays the same.
We can view the bias as the weight on a feature that always equals 1.
\[ \tilde x=(1,x_1,x_2),\qquad \tilde w=(b,w_1,w_2). \]
Then the score is \(z=\tilde w^\top\tilde x\), and an update is \(\tilde w_{\text{new}}=\tilde w+\eta y\tilde x\).
The first component changes by \(\eta y\), just as the bias did before.
In the next sequence, look for a point on the wrong side of the boundary and watch what changes after an update.
On the next slide, use the down arrow to step through the frames.












The points are linearly separable if a straight line puts all the \(+1\) points strictly on one side and all the \(-1\) points strictly on the other.
For a finite, linearly separable training set, repeated passes with a fixed \(\eta>0\) reach a pass with no updates. This is the perceptron convergence theorem.
When no straight boundary separates the labels, every pass requires at least one update. A limit on the number of epochs gives training a stopping point.
In XOR the two inputs are 0 or 1. The label is \(+1\) when exactly one input equals 1, and \(-1\) otherwise.
The dashed line \(x_1=\tfrac{1}{2}\) leaves one point of each class on either side. Could a line at a different position or angle separate all four points?
| x1 = 0 | x1 = 1 | |
|---|---|---|
| x2 = 1 | +1 | −1 |
| x2 = 0 | −1 | +1 |
Each class occupies opposite corners. If both ends of a segment are on the same side of a line, the entire segment is on that side.
The two class segments share the midpoint \((\tfrac{1}{2},\tfrac{1}{2})\). Any separating line would need to put that point on both sides at once.
Rosenblatt (1958) · Minsky and Papert (1969) · Rumelhart, Hinton and Williams (1986)
Our learned boundary \(0.5x_1+x_2=3\) classifies A, B and C correctly. A rule that predicts versicolor for \(x_1\ge 3\) also gets all three right.
A held-out versicolor flower at \(x=(3.3,1.0)\) gets score \(-0.35\) under our learned rule. The length-only rule classifies it correctly.
Use labelled examples held out of training to measure how well a rule generalises.
Suppose we extend training with another versicolor flower. Its measurements are \(x=(3.5,1.0)\) and its label is \(y=+1\).
Start from \(w=(0.5,1.0)\), \(b=-3\) and \(\eta=1\). What does the model predict? What are \(w\) and \(b\) after the visit?
\(z=0.5(3.5)+1.0-3=-0.25\), so \(\hat y=-1\). The true label is \(+1\), so we add the measurements to \(w\) and add 1 to \(b\).
\[ w_{\text{new}}=(0.5,1.0)+(3.5,1.0)=(4.0,2.0),\qquad b_{\text{new}}=-3+1=-2. \]
In this lecture, we covered the following key concepts in Machine Learning:
Machine Learning is a broad and evolving field that bridges data, algorithms, and real-world applications. Understanding these concepts forms a solid foundation for deeper exploration into modern ML techniques and applications.