IB Computer Science: Model Selection and Comparison — Tutor Lesson Plan (four models, 80.0% to 94.0% accuracy, cost 48 against 33)
- 2026-11-28
Students stop as soon as one model reports the highest accuracy, yet on the same data the simplest model scored only 80.0%, below the 90.0% line you get by answering pass every time. Model selection is a rule-bound comparison, not a race for one number.
01 Prerequisites (3-minute check)
If any of these fails, fix it before the lesson starts.
| Skill | Quick check | Pass mark |
|---|---|---|
| Accuracy | 200 test cases, 182 correct, what is the accuracy? | 91.0% |
| Recall | 20 failing students, 16 caught, what is the recall? | 80.0% |
| Mean | folds of 90.5, 87.5, 92.0, 89.0 and 91.0 | 90.0% |
02 Lesson flow (60 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0-7 min | Opening check | Is a model at 90.0% a good model? | Write an answer first |
| 7-22 min | Four models, one data set | Four confusion matrices, 20 failing cases | Fill the table, compute metrics |
| 22-34 min | Validation and cross-validation | 600, 200 and 200 rows, 5 folds | Compute mean, spread and range |
| 34-46 min | Overfitting and data characteristics | Depths 2 to 16, rows 40 to 800 | Draw two curves, explain the gap |
| 46-54 min | Cost and thresholds | Miss costs 5, false alarm 1 | Price three thresholds |
| 54-60 min | Exit check | Three questions marked on the spot | Work alone |
03 Teaching script (read it out)
Scene 1: Four models, four answers on one data set
Put four confusion matrices on the board: a single threshold on attendance above 0.7 catches 10, raises 30 false alarms and misses 10; the deep tree catches 18, raises 26 and misses 2; K-NN with five neighbours catches 16, raises 14 and misses 4; the network catches 14, raises 6 and misses 6.
Now compute in columns: accuracy 80.0%, 86.0%, 91.0% and 94.0%; precision 25.0%, 40.9%, 53.3% and 70.0%; recall 50.0%, 90.0%, 80.0% and 70.0%; F1 33.3, 56.2, 64.0 and 70.0.
The punchline is the balanced accuracy, the mean of recall and specificity: the network wins on raw accuracy at 94.0% but scores only 83.3% balanced, below the K-NN 86.1%, because it mislabels 6 of the 180 passing students. Its headline is built on the majority class. Ask the class to state which model they would deploy if the school wants to miss no failing student, and which one if the school wants to waste no support place. Both answers are defensible and that is the point of the syllabus statement.
Student task: move the single threshold from 0.7 to 0.5, rewrite the four cells, and say whether accuracy rises or falls and whether recall rises or falls.
Scene 2: Validation, cross-validation and overfitting
Then show why one split is unreliable with 5-fold cross-validation on the 800 training rows: the folds score 90.5%, 87.5%, 92.0%, 89.0% and 91.0%, giving a mean of 90.0%, a standard deviation of 1.6 and a range of 4.5 points. A single 600 over 200 split gave 89.5%, which is 0.5 points away from the mean. Cross-validation costs five fits but every row is validated once, so the mean is far more stable; with a huge model most teams fall back to one validation split or three folds.
The third movement is overfitting with one variable, tree depth: depth 2 gives 78% train and 80% test; depth 4 gives 86% and 89%, the best test result; depth 8 gives 97% and 88%; depth 16 gives 100% and 79%, a gap of 21 points. Draw both curves on one pair of axes: training climbs all the way, test rises then falls, and everything past the crossing is memorisation.
Close on data beating algorithms: going from 40 to 800 training rows lifts the same K-NN from 71.0% to 91.0%, a gain of 20.0 points; adding features from 2 to 40 with the same sample size drops accuracy from 91.0% to 63.5%, a loss of 27.5 points, which is the curse of dimensionality; label noise at 15% leaves 68.0%. More data or fewer irrelevant features usually beats a bigger model.
Student task: given fold scores of 86.0, 88.0, 84.0, 90.0 and 87.0, compute the mean and the range and write one sentence on whether the model is worse than a single split reporting 92.0%.
Scene 3: Choosing a model: problem, cost and price of the method
The second movement is cost. A missed failing student costs 5 units of remedial work, while a false alarm costs 1 unit of an extra class. At threshold 0.7 there are 3 false alarms and 9 misses, a total of 48; at 0.5 there are 6 and 6, total 36; at 0.3 there are 18 and 3, total 33. The default 0.5 is therefore not optimal and 0.3 saves 3. The threshold is a hyperparameter to be chosen, not a factory setting.
The third movement is the price of the method. For 10,000 queries a day, K-NN costs 16.0 ms each because it scans 4,800 stored numbers, which is 160.0 seconds a day; the tree costs 0.02 ms each, 0.2 seconds a day; the network costs 0.1 ms each, 1.0 seconds, but needs 300 seconds to train against 2 for the tree. K-NN trains for nothing and pays at query time; the tree and the network do the opposite, so ask which kind of fast is meant.
Finish on transparency: a single threshold has 2 numbers and can be explained to a parent in one sentence, a tree has 15 nodes and can still be printed as rules, and a network has 257 weights that can only be described as the model judgement. When a school must defend a decision, interpretability is itself a selection criterion.
Student task: for hospital screening, a hundred thousand daily recommendations and a regulated loan decision, write one sentence each on the family, the metric and the reason.
04 Question types and worked steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Four metrics from a confusion matrix | 200 test cases, 16 caught, 14 false alarms, 4 missed | Three steps: complete the four cells, then accuracy as true positives plus true negatives over the total, then precision over predicted positives, recall over actual positives and F1 as their harmonic mean | accuracy 91.0%, precision 53.3%, recall 80.0%, F1 64.0 |
| Compare two models | model A at 94.0% and model B at 91.0% accuracy | Two steps: compute balanced accuracy from recall and specificity, then decide from the cost of each kind of error | A is 94.0% but only 83.3% balanced; B is 86.1% balanced, so B wins under imbalance |
| Choose a threshold | a miss costs 5 and a false alarm costs 1, thresholds 0.7, 0.5 and 0.3 | Three steps: read off false alarms and misses, multiply each by its cost, add | 48, 36 and 33, so choose 0.3 |
| Diagnose overfitting | depth 16 gives 100% train and 79% test | Two steps: compute the gap between train and test, then compare with shallower depths to see whether test has passed its peak | a gap of 21 points past the peak at depth 4, so it is overfitting |
| Match the family to the problem | predict a total score, group unlabelled records, optimise a route, classify images | One line each: continuous values use regression, no labels use clustering, huge search uses a genetic algorithm, images use a convolutional network | regression at r squared 0.71, clustering by the sum of squares, genetic algorithm, CNN |
05 Independent practice (3 questions)
| Question | Answer | What to watch |
|---|---|---|
| 200 test cases with 20 failing. A model catches 18 and raises 26 false alarms. Find the accuracy, the recall and the precision. | accuracy 86.0%, recall 90.0%, precision 40.9% | Complete the true negatives first, then divide by the right denominator |
| Fold scores 90.5, 87.5, 92.0, 89.0 and 91.0. Find the mean and the range, and say whether a single split reporting 93.0% may be quoted as the performance. | mean 90.0%, range 4.5 points; a single split cannot be quoted, report the mean and the spread | Average across folds, never quote the best fold |
| A miss costs 5 and a false alarm costs 1. At 0.5 there are 6 false alarms and 6 misses; at 0.3 there are 18 and 3. Which threshold is cheaper and by how much? | 0.3, at 33 against 36, a saving of 3 | Multiply each count by its own cost before adding |
06 Common mistakes and what to say
| Mistake | Student writes | Say this |
|---|---|---|
| Highest accuracy equals best model | answering that the network at 94.0% must be used | the 94.0% is the overall hit rate. Of the 180 passing students it mislabels 6, so balanced accuracy is only 83.3%, below the K-NN 86.1%. Ask which side the problem must protect before choosing a metric. |
| Using the test set as a validation set | saying that after twelve attempts the test score is 96% | twelve attempts turn the test set into a validation set, so 96% was tuned, not measured. Use the test set once, or report 5-fold cross-validation at 90.0%. |
| Quoting training accuracy | saying that depth 16 at 100% proves a good model | training 100% against test 79% is a gap of 21 points: the tree memorised the training rows. The best test score is at depth 4, 89%. |
| A stronger algorithm must be better | swapping in a neural network whenever accuracy is low | look at the data first: going from 40 to 800 rows already lifts K-NN from 71.0% to 91.0%, while adding features to 40 costs 27.5 points. Data quantity and quality usually beat a bigger model. |
07 Homework (paper, section and question numbers)
- IB Computer Science chapter index — the three questions on this page for homework
- Neural networks and CNNs — previous chapter: how one of the four models is computed
- Linear regression, K-NN and decision trees with metrics — prerequisite: where the four metrics and information gain come from
08 Exit check (last 5 minutes)
| Question | Answer | Decision |
|---|---|---|
| Baseline | pass for everybody 90.0%, threshold model 80.0% | no baseline means restart scene one |
| Metrics | K-NN precision 53.3, recall 80.0, F1 64.0 | swapped denominators mean redo the row |
| Cost | 0.5 gives 36 and 0.3 gives 33 | accuracy alone without cost is not finished |
09 Tutor FAQ
Is there a best algorithm to memorise?
No. A4.3.10 assesses the method of comparison: different algorithms give different results on the same data, so a model is chosen from the nature of the problem, the characteristics of the data and the outcome wanted. None of the four models here wins on every metric, which is exactly what makes the lesson teachable.
How many folds should cross-validation use?
There is no fixed number. Five and ten are the usual choices: more folds mean more training rows per fold and less bias, but more fits. Five folds gave a mean of 90.0% with a standard deviation of 1.6 here, enough to show that a single split is unreliable. Very small samples use leave-one-out.
Why keep a validation set and a test set?
Validation chooses models and tunes hyperparameters and may be reused; test is used once to estimate real performance. Merge them and every extra attempt flatters the reported number, which is what goes wrong in the twelve attempts claim.
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.



