IB Computer Science Clustering, Association Rules, Reinforcement Learning and Genetic Algorithms: Tutor Prep Guide (k of 3 at SSE 7.942, lift 1.25, discounted return 8.1)
- 2026-11-27
Students hear unsupervised and assume clustering, hear reinforcement and assume more reward is better, and lose marks on both. This lesson pins the four methods down with four tables that can be computed by hand.
01 Prerequisites (3-minute check)
If any of these fails, fix it before the lesson starts.
| Skill | Quick check | Pass mark |
|---|---|---|
| Distance | Two points differ by 1.5 and by 0.4. What is the distance | About 1.55 by Pythagoras |
| Percentages and ratios | What is 300 divided by 600 | 50 per cent |
| Powers | What is 0.9 cubed | 0.729 |
02 Lesson flow (60 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0-8 min | Opening check | Ask how clustering differs from classification | Write an answer, compare at the end |
| 8-22 min | k-means and SSE | k from 1 to 4 takes SSE from 112.747 to 3.067 | Run two iterations, then cost it |
| 22-34 min | Association rules | Support 30.0, confidence 50.0, lift 1.25 | Compute all three |
| 34-48 min | Reinforcement learning | Return 8.1, Q from 4.0 to 4.24 | Discount a return, then update Q |
| 48-57 min | Genetic algorithms | 20 individuals, 1.6 flips, 19,958,400 tours | Name the six parts |
| 57-60 min | Exit check | Collect and mark three items | Work independently |
03 Teaching script (read it out)
Scene 1: Clustering: no labels, so similarity has to be argued through distance and SSE
How is k chosen? Cost the within-cluster sum of squares: k of 1 gives 112.747, k of 2 gives 19.983, k of 3 gives 7.942 and k of 4 gives 3.067. Each extra cluster drops SSE by 82.3, 60.3 and 61.4 per cent, which is no clear elbow, so the number does not decide alone: k of 4 splits the high-hours middle-attendance group into two clusters that mean nearly the same thing and explain nothing new, so 3 wins. That sentence is the exam point: every cluster must be named. Contrast with classification: labels let you mark the answer, clusters do not, so tightness within and separation between are the only arguments.
Student task: draw the three centroids, name the common feature of each cluster, then say which cluster a fourth one would duplicate.
Scene 2: Association rules: three numbers, three denominators, and lift is the one that says useful
Run the same formula on a crime dataset: vandalism in 22 per cent of areas, theft in 30 per cent and both in 12 per cent, giving support 12.0, confidence 54.5 and lift 1.82. Vandalism and theft are positively related at 1.82 times, which is not the same as saying vandalism causes theft. The Apriori idea takes one sentence: count single items, discard those below minimum support, then form pairs only from survivors, which collapses the candidate set. Three item rules exist too, but support falls and small samples make coincidences look like rules. Association rules describe co-occurrence, never causation, and that is the most examined sentence in this topic.
Student task: with the same counts, compute confidence conditioned on bread buyers and on butter buyers, and explain why lift needs no direction.
Scene 3: Reinforcement learning and genetic algorithms: one agent learns by reward, a population searches in parallel
Now the genetic algorithm, six parts: a population of 20 candidates, a fitness function, selection by fitness (four individuals scoring 10, 20, 30 and 40 are chosen with probabilities 10, 20, 30 and 40 per cent), crossover (1010 with 1100 and 0110 with 0111 cut after bit four give 1010 0111), mutation (a random flip, 20 individuals times 8 bits times 0.01 is 1.6 flips per generation) and termination (a generation cap or a fitness plateau). Why bother? Twelve cities give 11 factorial over 2, 19,958,400 distinct tours, and at one microsecond each that is 19.96 seconds; twenty cities give 6.08e+16 tours and 1,929 years, so enumeration is impossible and a population searches in parallel instead. A genetic algorithm promises good enough and fast, never optimal.
Student task: with four individuals and their fitness values, select two parents by roulette (write the cumulative ranges), do one single-point crossover and one mutation, then say why the child may be better or worse.
04 Question types and worked steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Run k-means and decide convergence | Several points, a k and starting centroids | Four steps: assign by distance, average each group, repeat until assignments stop changing, report sizes and centroids | One pass to converge, centroids such as (1.5, 9.1) |
| Choose k from SSE | SSE values for k from 1 to 4 | Three steps: compute each drop, look for an elbow, and if none exists decide by whether each cluster can be named | 112.747 to 3.067, drops of 82.3, 60.3 and 61.4 per cent |
| Compute support, confidence and lift | A transaction total and the counts for two items | Write three formulas separately: support over the total, confidence over the antecedent, lift over the consequent baseline | 30.0, 50.0 and 1.25 |
| Discount a return and update Q | A reward sequence, a discount factor, a learning rate and the best next value | Two steps: power and sum the discount, then substitute into the update for the target and the new Q | Return 8.1, new Q 4.24 |
| Design a genetic algorithm and size the search | A number of cities and a per-tour cost | Four steps: define chromosome and fitness, pick a selection method, set crossover and mutation rates, then size the space to justify approximating | Twelve cities at 19,958,400 tours and 19.96 seconds; twenty cities at 1,929 years |
05 Independent practice (3 questions)
| Question | Answer | What to watch |
|---|---|---|
| Of 1,000 receipts, 600 contain coffee, 400 contain cake and 300 contain both. Find support, confidence and lift, then state a conclusion. | Support 30.0, confidence 50.0, lift 1.25: a positive but weak relation, 25 per cent denser than independence | Whether lift divided by the consequent baseline |
| Rewards of 0, 0 and 10 with a discount factor of 0.9; separately, ten steps of one mark. | The first gives 8.1; the ten step sequence gives 6.5132 | Whether the first discount power is zero rather than one |
| A population of 20 with 8 bit chromosomes and a 0.01 mutation rate: how many flips per generation? And how many distinct tours do twelve cities allow? | 1.6 bit flips; 19,958,400 tours, which is 11 factorial over 2 | Whether the tour count was halved for direction |
06 Common mistakes and what to say
| Mistake | Student writes | Say this |
|---|---|---|
| Treating clustering as classification | Saying clustering sorts students into good and weak groups | Classification has labels to check against; clustering has none and only groups by distance, so you must name each group. The 3, 3 and 6 clusters here are not good or weak, only high hours with high attendance, middling, and low. |
| Confusing lift with confidence | Saying a confidence of 50 per cent is a 50 per cent lift | Confidence 50.0 per cent says half of bread buyers also buy butter, and butter already sells to 40 per cent of baskets, so lift is 0.5 over 0.4, 1.25, only 25 per cent denser than independence. The two do not interchange. |
| Describing reinforcement learning as maximising the immediate reward | Saying the agent always takes the highest immediate score | Immediate greed gets stuck. Rewards of 0, 0 and 10 accumulate to 8.1, while ten steps of one accumulate to 6.5132; the target is cumulative return, which is why there is a discount factor and why exploration matters. |
| Assuming a genetic algorithm finds the optimum | Saying run it long enough and it must find the shortest route | A genetic algorithm is an approximate search that promises good enough. Twenty cities give 6.08e+16 tours, which needs 1,929 years to enumerate, so a population searches in parallel and gives up any guarantee of optimality. |
07 Homework (paper, section and question numbers)
- IB Computer Science chapter index — All chapters in this subject
- Linear regression, classification and evaluation metrics — The previous chapter: r squared, K-NN, entropy, the confusion matrix
- Tutor prep guide index — Matching chapters in other subjects
08 Exit check (last 5 minutes)
| Question | Answer | Decision |
|---|---|---|
| Clustering | k of 3 at SSE 7.942 with three named centroids | No name per cluster means replay act one |
| Association rules | Support 30.0, confidence 50.0, lift 1.25 | A missing meaning for lift of 1 means not yet |
| Reinforcement and genetic | Return 8.1, 1.6 flips per generation | Calling an approximate search optimal means replay act three |
09 Tutor FAQ
Must clustering use k-means?
The guide only asks that clustering groups data by similarity in features and never names an algorithm. k-means is taught because it finishes on the board and shows convergence; hierarchical clustering or DBSCAN need one sentence each, and answering with the two k-means steps is safest.
What does a lift below 1 mean?
It means the pair co-occurs less often than independence predicts, a negative relation. Someone who buys a discounted item may avoid the full-price alternative. This course only needs three sentences: above 1 positive, equal to 1 none, below 1 negative.
How do reinforcement learning and genetic algorithms differ?
Reinforcement learning is one agent acting in an environment step by step and adjusting a policy from cumulative reward; a genetic algorithm evaluates a whole population and replaces generations through selection, crossover and mutation. Ask whether there is an environment reward and whether generations replace each other.
Find a tutor — freeTutor Registration →
A TutorZone lesson-prep guide. Written by the TutorZone team; questions and lesson flow are original and are not taken from any school or publisher material.



