Put the fruit plant's jobs in order
A packing plant wants a machine that sorts apples, bananas, mangoes and oranges without a person checking each fruit. Every step of this tutorial works on this plant.
Turning the plant's data into useful answers is Data Science. It is an umbrella over 3 fields: Data Mining discovers hidden patterns, Machine Learning builds models, and AI makes intelligent decisions. In the plant, mining notices that apples are usually red and smooth, the learner improves from its sorting mistakes, and the robot that sees a fruit and answers “Which fruit is this?” is the AI.
Data Mining describes the past, Machine Learning learns from it, AI acts on it. All of them need the raw data first.
Put the plant's four jobs in the order the work happens. Use ↑ and ↓ (Tab to a button, then Enter).
- A model improves from corrected sorting mistakes
- Collect raw data: measure the color, shape, size and texture of every fruit on the belt
- A robot sees the fruit, decides which it is and drops it in the right bin
- Find patterns in past records: “Apples are usually red and smooth”
- Collect raw data. Nothing can be mined, learned or decided before the fruit is measured.
- Data Mining finds patterns (“Apples are usually red and smooth”): it describes the past.
- Machine Learning builds a model that improves from corrected mistakes: it learns from the past.
- AI decides and acts: the robot sorts the fruit.
Tell the features from the label
Each fruit on the belt becomes one row. The plant measures 4 things about it: color, shape, size and texture. Something you can measure is a feature: an input.
The column you want the machine to predict, Fruit Type, is the label: the output. A table whose rows carry their labels is labeled data, and supervised learning learns to map the inputs (features) to the outputs (labels). On a brand-new fruit, the label is exactly what is missing.
| 4 features · inputs | label · output | |||
|---|---|---|---|---|
| color | shape | size | texture | Fruit Type |
| red | round | medium | smooth | Apple |
| yellow | cylindrical | long | smooth | Banana |
| yellow-green | oval | medium | smooth | Mango |
| orange | round | medium | dimpled | Orange |
Data Mining reads patterns from these same columns: “Apples are usually red and smooth”, “Bananas are yellow and cylindrical”.
Complete the description of the plant's table.
Color, shape, size and texture are the ; Fruit Type is the . Because every row includes its Fruit Type, the table is data, which is what learning needs.
- Color, shape, size and texture can be measured on any fruit: they are the 4 features (inputs).
- Fruit Type is the answer to predict: the label (output).
- Every row has its Fruit Type filled in, so the data is labeled.
- Mapping features to known labels is supervised learning.
Spot where the learning happened
Machine learning is a program that learns from data and improves its performance without being explicitly programmed. Arthur Samuel (IBM) popularised the term in 1959 with a checkers program that got better by playing.
In 1997 Tom Mitchell made it precise: a program learns from experience E on tasks T, measured by performance P, if P improves with E. For the plant:
- T · task
- sorting fruit into the four bins
- E · experience
- the sorted and corrected fruit it has already seen
- P · performance
- the percentage of fruit sorted correctly
Last week the plant's model called a mango an apple. A worker moved it to the right bin and the correction was stored. Today the model sorts mangoes correctly. What happened?
- T = sorting fruit, E = the corrected mango example, P = the share of mangoes sorted correctly. P went up as E grew: by Mitchell's 1997 definition, the program learned.
- A new hand-written rule would be explicit programming, the opposite of machine learning.
- Data Mining only describes patterns; it does not change how the sorter behaves next time.
- The robot is the AI part that acts; the improving was done by the Machine Learning model.
Let the data set the cut-off
A programmer writes the rule: “if redness ≥ 6 it is an apple”. A learner is given labelled examples and works the rule out itself.
machine learning: Data + Answers → Rules
A very simple learner on one feature puts its cut-off halfway between the two groups:
When the data change (brighter lamps, a redder harvest), the learner just recomputes. The hand-written rule stays wrong until someone rewrites it.
Today's six labelled fruits (redness, 0–10): apples 8, 7, 7.5 · mangoes 3, 4, 5. What cut-off does the learner find?
accepted within ± 0.05
- Mean apple = (8 + 7 + 7.5) ÷ 3 = 22.5 ÷ 3 = 7.5
- Mean mango = (3 + 4 + 5) ÷ 3 = 12 ÷ 3 = 4
- Cut-off = (7.5 + 4) ÷ 2 = 11.5 ÷ 2 = 5.75: “redness ≥ 5.75 → apple”.
Decide: classify, regress or cluster
supervised learning learns from labeled data and has 2 types. Classification predicts a discrete label, a category: email spam detection uses Spam (1), Not Spam (0); an animal classifier uses Cat (1), Dog (2), Bird (3), Fish (4). Those numbers are only codes. Regression predicts a continuous value: “how much?” (a monthly electricity bill) or “how many?” (products sold).
unsupervised With no label column at all, clustering groups similar examples; people name the groups later.
| Ask | Then it is |
|---|---|
| Labels? yes · answer is a category | classification |
| Labels? yes · answer is an amount | regression |
| Labels? no · find groups | clustering |
The plant's owner also runs an office. Match each job to its task.
- Spam (1) / Not Spam (0): two categories → classification.
- Cat (1), Dog (2), Bird (3), Fish (4): four categories; a Bird is not “one more” than a Dog → classification.
- Electricity bill, how much: a continuous amount → regression.
- Products sold, how many: an amount → regression.
- No Fruit Type column, no labels → clustering (unsupervised).
Your turn: label a new fruit by its nearest neighbour
The nearest-neighbour method plots every labelled fruit as a point (size, redness) and gives a new fruit the label of the closest one. Distance: subtract the sizes, subtract the rednesses, square both, add them, take the square root.
Worked for fruit A: new fruit X = (5, 7), A = (6, 8): d = √((5 − 6)² + (7 − 8)²) = √(1 + 1) = √2 = 1.41.
A new fruit X arrives: size 5, redness 7. Three labelled fruits are on the table.
| fruit | size | redness | label | distance to X |
|---|---|---|---|---|
| A | 6 | 8 | Apple | 1.41 |
| B | 3 | 4 | Mango | (a) ? |
| C | 8 | 3 | Orange | 5.00 |
- (a) d(X, B) = √((5 − 3)² + (7 − 4)²) = √(4 + 9) = √13 = 3.61. Check C the same way: √((5 − 8)² + (7 − 3)²) = √(9 + 16) = √25 = 5.00.
- (b) 1.41 < 3.61 < 5.00, so A is the nearest neighbour and X is labelled Apple.
- (c) The answer is a category, so this is classification. Had we averaged the neighbours' prices instead, it would be regression.
Group fruit that has no labels
A new supplier sends crates with the same 4 features measured but no Fruit Type column: the data is unlabeled. That is unsupervised learning.
Clustering puts fruits whose features are close into the same group, using the distance you computed in step 6. The algorithm only says “these belong together”. A person looks at each group afterwards and assigns the label: “these look like apples”.
Supervised: features → known labels. Unsupervised: features only → groups, named by people later.
The plot shows 8 unlabeled fruits from the new supplier. Click (or Tab + Enter) every fruit that belongs to the same cluster as P1, the ringed one.
selected points turn solid and get a ✓
- P1 = (4, 8). d(P1, P3) = √(1² + 0.5²) = √1.25 ≈ 1.12; d(P1, P4) = √(0.5² + 1²) ≈ 1.12; d(P1, P7) = √(1.5² + 0.2²) = √2.29 ≈ 1.51.
- P5 = (8, 3) is √(4² + 5²) = √41 ≈ 6.40 away; P6 ≈ 6.92, P2 ≈ 7.43 and P8 ≈ 7.66: the other cluster.
- Nobody told the algorithm “apple”. A person looks at the red, small group afterwards and names it.
Name the parts of a reinforcement learner
Some tasks have no answer key, only feedback. In reinforcement learning an agent acts in an environment and receives positive or negative rewards; its goal is to maximise the long-term cumulative reward. Sutton and Barto's 1998 textbook is the standard reference. The 5 key components: State (S), Action (A), Reward (R), Next State (S'), Policy (π).
The lecture's 6 steps: a child on a bicycle is in a State (wobbling, slow), takes an Action (pedal, steer, lean, brake), gets a Reward (balanced: +, falls: −), reaches a Next State, forms a Policy, and improves through the Learning Process: exploration and exploitation.
The plant's picking arm learns the same way as the child on the bicycle. Match each line to its component.
- Arm above a mango on its side: the situation now → State (S).
- Close the gripper: what the agent chooses to do → Action (A).
- +1 / −1: feedback from the environment → Reward (R).
- Mango held and lifted: where the action led → Next State (S').
- “For a fruit on its side, grip at the middle…”: a rule for every such state → Policy (π).
Choose how to reuse a pre-trained model
Someone who speaks Spanish learns Italian much faster than someone starting from nothing: grammar and many words carry over, only the differences need practice.
Transfer learning reuses a pre-trained model, one already trained on a large related task: ResNet for images (it won ImageNet in 2015) or BERT for text (Google, 2018). You keep its layers, add a new output layer for your own classes and fine-tune: update only a few layers on your own data instead of training everything from scratch.
The plant now wants to recognise its 4 fruits from camera photos, but it has only a small set of labelled photos. Which plan is transfer learning done right?
- ResNet (2015) already detects edges, colours, shapes and textures: that knowledge carries over, like Spanish to Italian.
- Its original output layer predicts other classes, so a new 4-class layer (apple, banana, mango, orange) is added and a few layers are updated.
- From scratch wastes that knowledge and needs far more labelled photos; BERT (2018) is pre-trained on text, not images.
Count the cells the data must fill
Every feature is a dimension. To learn well you need examples in every region of the feature space. Split each feature into just 2 ranges (low, high): 1 feature gives 2 cells, 2 features give 2 × 2 = 4, 3 features give 8. The number of regions doubles with every added dimension.
Richard Bellman named this the curse of dimensionality in 1957. It causes 4 problems: (1) increased sparsity, the same examples spread over far more cells; (2) higher computational cost; (3) overfitting risk; (4) distance-based issues: for k-NN and clustering, all points appear equally distant.
The plant keeps adding measurements until each fruit has 10 features, each split into 2 ranges. Set the slider to your prediction of the number of cells, then press Check.
- Each feature has 2 ranges, and every new feature doubles the cells: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1,024.
- So 10 features give 2 × 2 × … × 2 (ten 2s) = 2¹⁰ = 1,024 cells.
- Even a full belt of labelled fruit leaves most of those cells empty: increased sparsity, more computation, a higher overfitting risk, and distances that all look alike.
Put it all together
Nothing new here: this is the whole lecture applied to one plant. For each situation, decide first whether there is a label, a reward, a pre-trained model or just raw data, then whether the answer is a category, an amount or a group. Finally ask whether the plan adds features faster than the data can fill them.
- 1Data Mining · ML · AI
- 2features and labels
- 3T, E, P
- 4rules learned from data
- 5classify · regress · cluster
- 6nearest neighbour
- 7clustering
- 8S, A, R, S', π
- 9pre-trained, fine-tune
- 10curse of dimensionality
Answer all eight, then Check.
- Data Mining: it describes a pattern in past data (step 1).
- Supervised classification: labeled data, the answer is a category (steps 2, 5, 6).
- Supervised regression: “how many” is an amount (step 5).
- Unsupervised clustering: no labels; people name the groups later (step 7).
- Reinforcement learning: rewards, not labels; goal is the cumulative reward (step 8).
- Transfer learning: reuse a pre-trained model and fine-tune (step 9).
- Retrain on newly labelled mangoes: the learned cut-off moves with the data; a hand-written rule does not (steps 3, 4).
- Curse of dimensionality: each extra feature doubles the cells (2¹⁰ = 1,024 for just 10 features), so the data become sparse, computation grows, overfitting risk rises and distances look alike (step 10).
What you can do now
- Distinguish Data Science, Data Mining, Machine Learning and Artificial Intelligence using the fruit-sorting scenariostep 1 · not yet
- Define machine learning as learning from data to improve performance without being explicitly programmedsteps 3, 4 · not yet
- Differentiate supervised learning (classification and regression) from unsupervised learning (clustering) by whether the data is labeledsteps 2, 5, 6, 7 · not yet
- Identify the components of reinforcement learning (State S, Action A, Reward R, Next State S', Policy π) in a worked examplestep 8 · not yet
- Explain how transfer learning reuses and fine-tunes a pre-trained model for a related taskstep 9 · not yet
- Describe the curse of dimensionality and its four problems: sparsity, computational cost, overfitting risk and distance-based issuesstep 10 · not yet
Before the lab: install Anaconda (docs.anaconda.com/anaconda/install/). The tutorial session builds on these ideas with real data.