Assign each job on the packing line to its field
Our running example: one packing line where apples, bananas, oranges and mangoes arrive on a single belt. Data Science is the umbrella over 3 fields: it “uses Data Mining to discover hidden patterns, Machine Learning to build models, AI to make intelligent decisions”. Data Mining reads the records and returns a description, such as “Apples are usually red and smooth” or “Bananas are yellow and cylindrical”. Machine Learning returns a model: it learns from past sorting mistakes, so a mango wrongly identified as an apple is corrected next time. AI returns a decision: it sees, recognises and sorts the fruit, answering “Which fruit is this?”, like a robot picking apples and oranges.
In plain wordsOne clerk keeps the records, one learns the trade, one runs the belt (basics: Intermediate step 1).
For each job on the packing line, choose the field whose output it is.
- a → Data Mining. The output is a pattern that describes the records; nothing is predicted or done.
- b → Machine Learning. Performance improves from a past mistake: the model is updated by data, not by a programmer.
- c → AI. The system perceives, recognises and acts: the output is a decision a = π(s).
- d → Machine Learning. Choosing f ∈ 𝓗 that minimises errors on labelled data is building a model.
Same fruit, three outputs: a description (mining), a model (ML), a decision (AI). An AI system often uses an ML model, which often starts from mined patterns.
Name T, P and E for the learning sorter
Machine learning “learns from data and improves without being explicitly programmed”. Arthur Samuel (IBM) popularised the term in 1959 with a checkers program that improved by playing itself; in 1957 Frank Rosenblatt had described the perceptron, whose weights are learned rather than typed in. Tom Mitchell's 1997 definition makes the idea testable: a program learns from experience E on tasks T, measured by performance P, if P improves with E.
An explicitly programmed sorter has thresholds a programmer typed in; they never change. A learned sorter chooses its parameters θ from data, so more or newer examples change θ* without anyone editing code. The learning algorithm is still a program; what is not hand-written is the decision rule.
learned: θ* = argminθ (1/n) Σᵢ L(fθ(xᵢ), yᵢ), ŷ = fθ*(x)
In plain wordsA printed map stays as printed; a navigator re-plans when the roads change (basics: Intermediate step 2).
Suppose the sorter is retrained every week. In week 1 it has seen 200 labelled fruit and sorts 82% of a fixed test belt correctly; in week 3 it has seen 600 and sorts 91%. Its code never changed. Which line names T, P and E correctly?
- T is the job that stays fixed: sorting fruit into apple, banana, orange, mango.
- P is a score measured on T with a fixed test belt: 82% in week 1, 91% in week 3.
- E is what grew: the labelled fruit, from 200 to 600.
- P improved with E while the code did not change, so by Mitchell's 1997 definition the sorter learns. Answer A.
Split the fruit table into features x and label y
Supervised learning starts from labeled data, a set of pairs D = {(xᵢ, yᵢ)}, i = 1…n. Each row i is one fruit. Its inputs, the features, form the feature vector xᵢ = (color, shape, size, texture): the 4 features the lecture uses for data mining and clustering, so xᵢ ∈ ℝ⁴ once each is coded as a number. Its output, the label yᵢ, is the “Fruit Type” column. Learning finds f that maps inputs to outputs, f(xᵢ) ≈ yᵢ, so it can label a new fruit. The label is never an input: a new fruit arrives without it (feeding it in is called target leakage). Delete the “Fruit Type” column and the table becomes unlabeled data.
In plain wordsFeatures are the measurements, the label is the answer you want (basics: Intermediate step 3).
| i | color | shape | size | texture | Fruit Type |
|---|---|---|---|---|---|
| 1 | red | round | medium | smooth | apple |
| 2 | yellow | cylindrical | long | smooth | banana |
| 3 | orange | round | medium | dimpled | orange |
Complete the description of the table.
The columns color, shape, size and texture of row i form ; the “Fruit Type” column is ; so xᵢ ∈ ℝ. If the “Fruit Type” column is deleted, the same table is data for learning.
- The four measured columns are the inputs: they form the feature vector xᵢ.
- “Fruit Type” is the answer the model must produce: the label yᵢ.
- There are 4 features (color, shape, size, texture), so xᵢ ∈ ℝ⁴; the label is not counted.
- Without labels there is nothing to supervise with: the table is data for unsupervised learning (clustering, step 6).
Classify the mango with the nearest centroid
Classification predicts a discrete label. The simplest learned classifier stores one centroid per class, the mean of its labelled examples, and gives a new fruit the label of the nearest one, using the Euclidean distance. To work by hand we keep 2 of the 4 features: size (cm) and roundness (0 = long, 10 = round). Centroids learned from the history: apple μ = (8, 9), orange μ = (7, 10), banana μ = (18, 2). There is no mango class yet. Because cm and a 0–10 score have different scales, real systems standardise features first so that one feature does not dominate the distance.
In plain wordsCall the new fruit whatever it most resembles on average (basics: Intermediate step 4).
import numpy as np def fit_centroids(X, y): # mu_c = mean of the rows of X labelled c return {c: X[y == c].mean(axis=0) for c in np.unique(y)} def predict(x, mu): # y_hat = argmin_c ||x - mu_c|| return min(mu, key=lambda c: np.linalg.norm(x - mu[c])) mu = {"apple": np.array([8, 9]), "orange": np.array([7, 10]), "banana": np.array([18, 2])} print(predict(np.array([11, 7]), mu))
A mango arrives with x = (11, 7). Compute its Euclidean distance to the apple centroid μ = (8, 9).
Give 2 decimals · accepted within ±0.01 · unit: feature units
- Differences: 11 − 8 = 3 and 7 − 9 = −2. Squares: 9 and 4. Sum: 13.
- d(x, μapple) = √13 ≈ 3.61.
- For comparison: d(x, μorange) = √((11−7)² + (7−10)²) = √25 = 5.00; d(x, μbanana) = √((11−18)² + (7−2)²) = √74 ≈ 8.60.
- argmin is apple, so the mango is wrongly identified as an apple: exactly the lecture's mistake. With no mango class, no distance can give the right answer.
- Learning from the mistake: add the corrected mango; the new class has μmango = (11, 7), and the next similar mango is now nearest to it.
Sort the questions into classification and regression
Supervised learning has 2 types, told apart by the output. Classification predicts discrete labels: Spam (1), Not Spam (0) in email spam detection, or Cat (1), Dog (2), Bird (3), Fish (4) in animal classification. Regression predicts continuous values: “how much” (a monthly electricity bill) or “how many” (products sold). The numbers in a class code are names, not quantities, so the losses differ: classification counts mistakes (0–1 loss, or cross-entropy on probabilities), regression measures a distance such as the squared error. With k neighbours, classification takes the mode, regression the mean. Averaging Cat (1) and Bird (3) into Dog (2) is the classic error.
regression: ŷ = (1/k) Σi∈Nk(x) yᵢ, L = (y − ŷ)²
In plain wordsIf averaging two answers makes sense it is regression, otherwise classification (basics: Intermediate step 5).
The packing house wants to answer six questions with supervised learning. Mark each one.
- Spam (1) / Not Spam (0): classification (a code for 2 classes).
- Monthly electricity bill, “how much”: regression.
- Boxes of mangoes sold, “how many”: regression.
- Fruit type: classification.
- Cat (1), Dog (2), Bird (3), Fish (4): classification. The numbers have no order or scale, so averaging them is meaningless.
- Weight in grams: regression.
Run one clustering step without labels
Unsupervised learning receives the same fruit without the “Fruit Type” column. Clustering groups the fruit by their features (color, shape, size, texture); humans assign the labels later (“this group is mangoes”). The k-means method alternates two steps: assign each point to its nearest centre, then update each centre to the mean of its points. Each step can only lower the objective J, so k-means stops after finitely many steps, though possibly in a local minimum that depends on the starting centres.
J = Σᵢ ‖xᵢ − μc(i)‖² (never increases)
In plain wordsPut each fruit with the nearest pile, then move each pile's marker to its middle (basics: Intermediate step 6).
| point | size | roundness |
|---|---|---|
| P1 | 7 | 9 |
| P2 | 9 | 8 |
| P3 | 12 | 7 |
| P4 | 16 | 3 |
| P5 | 19 | 2 |
| P6 | 14 | 4 |
Starting centres: μA = (8, 8), μB = (17, 3)
Do the assignment step: select every fruit that joins cluster A (nearest to μA).
Click a point, or Tab to it and press Enter or Space · selected points show ✓
| point | ‖x − μA‖ | ‖x − μB‖ | cluster |
|---|---|---|---|
| P1 (7, 9) | √2 ≈ 1.41 | √136 ≈ 11.66 | A |
| P2 (9, 8) | √1 = 1.00 | √89 ≈ 9.43 | A |
| P3 (12, 7) | √17 ≈ 4.12 | √41 ≈ 6.40 | A |
| P4 (16, 3) | √89 ≈ 9.43 | √1 = 1.00 | B |
| P5 (19, 2) | √157 ≈ 12.53 | √5 ≈ 2.24 | B |
| P6 (14, 4) | √52 ≈ 7.21 | √10 ≈ 3.16 | B |
Cluster A = {P1, P2, P3}. Update step: μA = ((7+9+12)/3, (9+8+7)/3) = (9.33, 8.00); μB = ((16+19+14)/3, (3+2+4)/3) = (16.33, 3.00). A person can now name A “round fruit” and B “long fruit”: the labels come after the grouping.
Your turn: frame the robot picker as reinforcement learning
Reinforcement learning has no answer key. An agent acts in an environment, receives positive or negative rewards, and learns to maximise the long-term cumulative reward. Its 5 key components: State (S), what the agent observes; Action (A), what it does; Reward (R), the immediate feedback; Next State (S'), where the action leads; Policy (π), the rule from states to actions. Formally the agent maximises the expected return, with a discount 0 ≤ γ < 1 so later rewards count less and the sum stays finite. This is the framing of Sutton and Barto's 1998 textbook “Reinforcement Learning: An Introduction”. The lecture's worked example, a child learning to ride a bicycle, has 6 steps.
In plain wordsLearn by trial and error which moves pay off over the whole ride, not just now (basics: Intermediate step 7).
aPut the 6 steps of the bicycle example in order
Use ↑ and ↓ (keyboard: Tab to a button, Enter)
bCompute the robot picker's return
On our packing line a robot arm is the agent. In one short episode it gets R₁ = +1 (picks an apple cleanly), R₂ = −1 (bruises an orange) and R₃ = +10 (fills the crate). The discount is γ = 0.9. Compute G₀.
Give 2 decimals · accepted within ±0.01 · unit: reward points
- (a) State (S): moving slowly, leaning left → Action (A): steer into the lean → Reward (R): stays balanced (+), falling would be (−) → Next State (S'): upright and moving → Policy (π): “when leaning left, steer left” becomes the habit → Learning Process: exploration (try new moves) and exploitation (repeat what worked).
- (b) G₀ = R₁ + γR₂ + γ²R₃ = 1 + 0.9 × (−1) + 0.81 × 10 = 1 − 0.9 + 8.1 = 8.2.
- The undiscounted sum is 1 − 1 + 10 = 10; discounting makes the late +10 worth only 8.1 now.
Update the robot's Q-value after one try
How does the policy π improve? The agent keeps a value Q(S, A): the return it expects after action A in state S. With probability ε it explores (tries a random action, such as a softer grip); otherwise it exploits, taking the action with the highest Q. After each step (S, A, R, S') it moves Q toward a one-step target. Rewriting the update shows why it works: the new Q is a weighted average of the old estimate and the new evidence, with the learning rate α as the weight. This is Q-learning.
target = R + γ · maxa' Q(S', a')
Q(S, A) ← Q(S, A) + α [target − Q(S, A)] = (1 − α) Q(S, A) + α · target
In plain wordsMove your guess part of the way toward what just happened plus what you expect next (basics: Intermediate step 8).
import random def act(Q, s, eps=0.1): if random.random() < eps: # explore return random.choice(list(Q[s])) return max(Q[s], key=Q[s].get) # exploit: argmax_a Q(s, a) def q_update(Q, s, a, r, s_next, alpha=0.5, gamma=0.9): target = r + gamma * max(Q[s_next].values()) Q[s][a] += alpha * (target - Q[s][a]) return Q[s][a]
The robot is in S = “orange at the edge of the belt” with Q(S, grip gently) = 2.0. It grips gently, gets R = +1 and reaches S', where the best value is maxa' Q(S', a') = 4.0. With α = 0.5 and γ = 0.9, set the slider to the new Q(S, grip gently).
- Target = R + γ · maxa' Q(S', a') = 1 + 0.9 × 4.0 = 1 + 3.6 = 4.6.
- Error (temporal difference) = 4.6 − 2.0 = 2.6.
- New Q = 2.0 + 0.5 × 2.6 = 2.0 + 1.3 = 3.3.
- Check with the average form: (1 − 0.5) × 2.0 + 0.5 × 4.6 = 1.0 + 2.3 = 3.3. Gentle gripping now looks better, so exploitation will choose it more often.
Count what you train when fine-tuning a pre-trained model
Transfer learning reuses what a model learned on one task for a related task, the way someone who speaks Spanish learns Italian faster. You start from a pre-trained model: ResNet (He et al.), which won ImageNet in 2015, for images, or BERT (Devlin et al., Google), released in 2018, for language (NLP). To fine-tune, keep the pre-trained weights θ₀ and update only a few layers instead of training from scratch: usually a new output head and, optionally, the top block, with a small learning rate. A dense head from a d-value feature vector to K classes has d × K weights plus K biases. ResNet-50's final feature vector has 2,048 values; the whole network has about 25.6 million parameters.
In plain wordsKeep the trained eyes, teach only the new names (basics: Intermediate step 9).
You freeze all of ResNet-50 and add a new dense head for the 4 fruit types (apple, banana, orange, mango). How many parameters does fine-tuning train?
- Weights: d × K = 2,048 × 4 = 8,192.
- Biases: one per class, K = 4.
- Total trained: 8,192 + 4 = 8,196. Answer B.
- Share of the model: 8,196 ÷ 25,600,000 ≈ 0.03 %. Everything else keeps its pre-trained values; training from scratch would update all ≈ 25.6 million.
Predict how empty the feature space becomes
Every added feature multiplies the space the data must fill. Richard Bellman introduced the term curse of dimensionality in 1957 (Dynamic Programming). Split each feature into just 2 ranges: d features give 2ᵈ cells, so the number of regions doubles with every added dimension, and 10 features give 2¹⁰ = 1,024. The lecture names 4 problems: (1) increased sparsity, as the same examples spread over far more cells; (2) higher computational cost, since each distance needs d terms and keeping the same density needs data growing like 2ᵈ; (3) overfitting risk, as few examples per region let a model fit noise; (4) distance-based issues: in k-NN and clustering “all points appear equally distant”.
In plain wordsThe same crowd in a much bigger building leaves most rooms empty (basics: Intermediate step 10).
The packing house has 64 labelled fruit. With the 4 features and 2 ranges each, the 2⁴ = 16 cells hold 4 fruit each on average. Engineers add 6 sensor readings, giving 10 features and 2¹⁰ = 1,024 cells. Predict the largest possible share of cells that contain at least one fruit.
accepted within ±1 percentage point
- At most one cell per fruit: 64 occupied cells.
- Share = 64 ÷ 1,024 = 0.0625 = 6.25 %; at least 960 cells stay empty. That is increased sparsity.
- With 4 features the share could reach 100 % (16 cells, 64 fruit). The 6 added features multiply the cells by 2⁶ = 64.
- To get back to 4 fruit per cell you would need 4 × 1,024 = 4,096 labelled fruit: 64 times more data, which is also the computational cost and overfitting risk of the curse.
Put it all together: plan the packing line's system
A real project combines everything. Decide from the experience you have: labelled pairs (xᵢ, yᵢ) → supervised (a label → classification, a quantity → regression); points without a label column → unsupervised clustering; rewards for actions → reinforcement learning; a related pre-trained model plus little data → transfer learning. A description of past data is Data Mining; acting on a trained model is AI. Then check the cost: every added feature doubles the cells to fill.
In plain wordsFirst ask what kind of data you have, then what kind of answer you need (basics: Intermediate step 11).
| you have | use |
|---|---|
| (xᵢ, yᵢ), y a label | classification |
| (xᵢ, yᵢ), y a quantity | regression |
| xᵢ only | clustering |
| (S, A, R, S') | reinforcement |
| θ₀ + little data | transfer |
Part A: choose the right approach for each job. Part B: name the problem.
- Pattern in old records → Data Mining (step 1).
- 5,000 labelled photos, predict the type → supervised classification (steps 3–4).
- How many crates → supervised regression (step 5).
- No “Fruit Type” column, named later → unsupervised clustering (step 6).
- +1 / −1 for grips → reinforcement learning (steps 7–8).
- 300 photos, start from ResNet, train only a head → transfer learning (step 9).
- Push each fruit into a crate using the trained model → AI decision (step 1).
- B: “all points appear equally distant” → distance-based issues (step 10).
Every part learns in Mitchell's sense (step 2): T fixed, P measured, E growing.