Contents

  • Broad introduction to machine learning topics.
  • Perceptron.

Careers in Machine Learning

  • Most ML careers focus on applying and deploying existing algorithms — building data pipelines, training models, and integrating them into products.
  • Only a small fraction of roles involve inventing new algorithms (e.g. research labs, PhDs).
  • Industry demand remains strong and growing across sectors — from finance and healthcare to logistics and creative industries.
  • Key growth areas include MLOps (infrastructure and deployment), ML engineering (model training and serving), and data science (applied analysis).
  • Generative AI has expanded opportunities — especially in model integration, evaluation, and retrieval‑augmented generation systems.

In short: a career in ML today means turning learning algorithms into reliable, scalable tools — not just developing new maths.

Jevons paradox

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.

MeasureBeforeWith AI
Analyses per month100300
Analyst hours per analysis21
Total analyst hours per month200300

More demand can outweigh the time saved per task. The PwC figures raise the question of whether this mechanism is at work.

W. S. Jevons, The Coal Question (1865), Chapter VII

Learning Modes

Take one pass through six training examples in order. Each set of brackets marks the examples used together for one training step.

ModeGroups of examplesSteps
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.

What grouping changes

  • Full batch. Each step uses information from every example. The first step waits until the whole set has been processed.
  • Mini-batch. Several examples can be processed together, with opportunities to change the model partway through a pass.
  • One at a time. The model can respond as soon as a labelled example is available, which also works when data arrive in a stream.

Perceptron

Classifying Iris flowers

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.

  • Iris setosa has label \(y=-1\).
  • Iris versicolor has label \(y=+1\).

We will train on a few labelled flowers and use the learned rule to predict a species from a new pair of measurements.

Three labelled flowers

Each observation has two features \(x=(x_1,x_2)\) and a known species label \(y\).

FlowerPetal length (cm)Petal width (cm)SpeciesLabel
A1.10.1Setosa−1
B5.11.6Versicolor+1
C1.20.2Setosa−1

For A, the input is \(x=(1.1,0.1)\) and the target is \(y=-1\).

Data from the scikit-learn Iris dataset.

Give each flower a score

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 weights \(w_1,w_2\) control how the features affect the score.
  • The bias \(b\) adds the same offset to every score.

The dot product \(w^\top x\) is shorthand for the weighted sum. There is one weight per feature.

Turn the score into a class

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.

Two predictions by hand

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)\)?

Prediction for flower B

\[ 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.

The decision boundary

For \(z=0.5x_1+1.0x_2-3\), the dashed line \(x_2=3-0.5x_1\) is where \(z=0\).

The three Iris observations and their decision boundary Petal length is on the horizontal axis and petal width is on the vertical axis, both in centimetres. Below the dashed line, flowers A at (1.1, 0.1) and C at (1.2, 0.2) are predicted to be setosa. Above the line, B at (5.1, 1.6) is predicted to be versicolor. 0 1 2 3 4 5 6 0.5 1.0 1.5 2.0 Petal length x₁ (cm) Petal width x₂ (cm) Predict setosa (−1) Predict versicolor (+1) A B C

More squares near B

Imagine finding more squares close to B. The filled markers A, B and C are the original flowers. The open markers are hypothetical.

Hypothetical squares near flower B Filled squares A and C and filled circle B are the original flowers. Some open squares lie close to B and on the circle side of the original dashed line. A solid line shifted towards B separates the labels. Original line One line that fits 0 1 2 3 4 5 6 0.5 1.0 1.5 2.0 Petal length x₁ (cm) Petal width x₂ (cm) A B C

The dashed line now misclassifies several squares. The solid line moves closer to B and separates these points.

More circles near A and C

Now imagine finding more circles close to A and C. The filled markers are the same three flowers, and the open markers are hypothetical.

Hypothetical circles near flowers A and C Filled squares A and C and filled circle B are the original flowers. Some open circles lie close to A and C and on the square side of the original dashed line. A solid line shifted towards A and C separates the labels. Original line One line that fits 0 1 2 3 4 5 6 0.5 1.0 1.5 2.0 Petal length x₁ (cm) Petal width x₂ (cm) A B C

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.

How the boundary moves

  • Weights set the orientation. When \(w\ne 0\), it points perpendicular to the boundary, towards larger scores.
  • Bias shifts the boundary in parallel when the weights are fixed.

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.

Decide whether to update

During training we know the true label \(y\). Multiply the current score by this label to get the signed score \(yz\).

  • \(yz>0\). The score has the correct sign. Keep \(w\) and \(b\).
  • \(yz<0\). The score has the wrong sign. Update \(w\) and \(b\).
  • \(yz=0\). The score is tied. Update \(w\) and \(b\) for either label.

A setosa flower with \(y=-1\) and \(z=-3\) has \(yz=3\), so it needs no update.

The perceptron learning rule

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.

  • For \(y=+1\), add \(x\) to the weights and add 1 to the bias.
  • For \(y=-1\), subtract \(x\) from the weights and subtract 1 from the bias.

An epoch is one pass

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.

The first pass starts at 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\)?

Visit 1 updates on a tie

A scores \(0\). The tie triggers an update. Since \(y=-1\), subtract \((1.1,0.1)\) from \(w\) and subtract \(1\) from \(b\).

VisitFlowerLabelScore before\(\Delta w\)\(\Delta b\)New \(w\)New \(b\)
1A−10(−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\).

Visit 2 adds flower B

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\).

VisitFlowerLabelScore before\(\Delta w\)\(\Delta b\)New \(w\)New \(b\)
1A−10(−1.1, −0.1)−1(−1.1, −0.1)−1
2B+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\).

Visit 3 subtracts flower C

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.

VisitFlowerLabelScore before\(\Delta w\)\(\Delta b\)New \(w\)New \(b\)
1A−10(−1.1, −0.1)−1(−1.1, −0.1)−1
2B+1−6.77(5.1, 1.6)+1(4.0, 1.5)0
3C−1+5.10(−1.2, −0.2)−1(2.8, 1.3)−1

What has this change done to the score of flower A?

Visit 4 returns to 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.

VisitFlowerLabelScore before\(\Delta w\)\(\Delta b\)New \(w\)New \(b\)
1A−10(−1.1, −0.1)−1(−1.1, −0.1)−1
2B+1−6.77(5.1, 1.6)+1(4.0, 1.5)0
3C−1+5.10(−1.2, −0.2)−1(2.8, 1.3)−1
4A−1+2.21(−1.1, −0.1)−1(1.7, 1.2)−2

Does B, with \(y=+1\), need an update on this pass?

Visit 5 keeps the parameters

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.

VisitFlowerLabelScore before\(\Delta w\)\(\Delta b\)New \(w\)New \(b\)
1A−10(−1.1, −0.1)−1(−1.1, −0.1)−1
2B+1−6.77(5.1, 1.6)+1(4.0, 1.5)0
3C−1+5.10(−1.2, −0.2)−1(2.8, 1.3)−1
4A−1+2.21(−1.1, −0.1)−1(1.7, 1.2)−2
5B+1+8.59(0, 0)0(1.7, 1.2)−2

What score does C get this time, and does it trigger an update?

Visit 6 corrects flower C

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.

VisitFlowerLabelScore before\(\Delta w\)\(\Delta b\)New \(w\)New \(b\)
1A−10(−1.1, −0.1)−1(−1.1, −0.1)−1
2B+1−6.77(5.1, 1.6)+1(4.0, 1.5)0
3C−1+5.10(−1.2, −0.2)−1(2.8, 1.3)−1
4A−1+2.21(−1.1, −0.1)−1(1.7, 1.2)−2
5B+1+8.59(0, 0)0(1.7, 1.2)−2
6C−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\).

Check one more pass

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?

A pass with no updates

Here are the scores as each flower is visited. Bold scores trigger an update.

EpochA (label −1)B (label +1)C (label −1)Updates
10−6.77+5.103
2+2.21+8.59+0.282
3−2.35+1.15−2.200

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.

Why the update helps

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.

What the learning rate changes

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.

The bias as an extra weight

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.

Watch the boundary move

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.

Linear separability

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.

Linearly separable

Two classes separated by a straight line

Not linearly separable

Two classes that a single straight line cannot separate

When training converges

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.

A trial decision boundary for XOR

In XOR the two inputs are 0 or 1. The label is \(+1\) when exactly one input equals 1, and \(-1\) otherwise.

XOR points and a trial line The positive points are at (0, 1) and (1, 0). The negative points are at (0, 0) and (1, 1). The trial vertical line at x1 equals one half leaves one point of each label on each side. 0 1 1 x₁ x₂ Trial boundary +1 +1 −1 −1

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?

Why a line cannot solve XOR

The two XOR class diagonals share a midpoint A blue segment connects the two positive points at opposite corners. An orange segment connects the two negative points. Both segments pass through the midpoint (one half, one half). 0 1 1 x₁ x₂ Shared midpoint +1 +1 −1 −1

x1 = 0x1 = 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.

Why XOR became a classic example

  • 1958. Frank Rosenblatt published his perceptron model, an early trainable model inspired by the nervous system.
  • 1969. Marvin Minsky and Seymour Papert analysed what perceptrons could represent. XOR became a simple illustration of the limits of a single linear decision rule.
  • 1986. David Rumelhart, Geoffrey Hinton and Ronald Williams showed how backpropagation could train networks with hidden units. A hidden layer can combine threshold decisions to represent XOR.

Rosenblatt (1958) · Minsky and Papert (1969) · Rumelhart, Hinton and Williams (1986)

Two lines can fit the training data

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.

Try one update

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?

The update for the new flower

\(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. \]

Perceptron Summary

  • To predict a class, calculate \(z=w^\top x+b\) and compare it to zero.
  • To learn from an example with \(yz\le 0\), change the weights by \(\eta yx\) and the bias by \(\eta y\).
  • A full pass with no updates means the rule separates the training data.