IB Computer Science Linear Regression, Classification and Evaluation Metrics: Tutor Prep Guide (slope 1.6, r squared 0.64, F1 76.4 per cent)
- 2026-11-27
A student sees 74 per cent accuracy and calls the model good, but always predicting pass already scores 60 per cent. Another quotes r squared 0.64 without knowing where the other 36 per cent went. This lesson turns regression, classification and metrics into arithmetic that finishes on the board.
01 Prerequisites (3-minute check)
If any of these fails, fix it before the lesson starts.
| Skill | Quick check | Pass mark |
|---|---|---|
| Straight-line equations | With a slope of 1.6 and an intercept of 50.0, what score does three hours predict | 54.8 marks |
| Squares and roots | What is the square root of 360.0 divided by 40 | 3.0 |
| Percentages | What percentage of 100 predictions is 74 correct ones | 74 per cent |
02 Lesson flow (60 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0-8 min | Opening check | Ask whether 74 per cent accuracy is good | Write an answer, compare with the baseline at the end |
| 8-26 min | Linear regression | Slope 1.6, intercept 50.0, r squared 0.64 | Write the equation and explain both numbers |
| 26-40 min | K-NN classification | Distance 0.8333, five neighbours at 3 to 2 | Compute the distance, then vote |
| 40-50 min | Decision trees and entropy | Gain 0.233, failure rates 8.0 against 60.0 per cent | Compute entropy and gain |
| 50-57 min | Metrics and hyperparameters | F1 76.4 per cent, the cost of k and of depth | Four metrics from the matrix |
| 57-60 min | Exit check | Collect and mark three items | Work independently |
03 Teaching script (read it out)
Scene 1: Linear regression: one line, two numbers, each with a meaning
The fit is r squared: 400 squared over 250 times 1000 gives 0.64, so study time explains 64 per cent of the variation in marks. The other 36 per cent is the residual sum of squares, 360, which is a mean deviation of 3.0 marks, so a prediction of 54.8 should be read as 54.8 plus or minus 3. Substitute two values to see it: three hours predicts 54.8 and eight hours predicts 62.8. If the student who studied three hours actually scored 60, the residual is plus 5.2: the model under-predicted, and that case is exactly where the class asks which other variable is missing.
Students must separate three things: the slope is the effect per unit, the intercept is the starting point, and r squared is overall explanatory power. High r squared is not causation: more study and higher marks may both follow from family support.
Student task: compute predictions for four students (1, 3, 6 and 9 hours), then write one sentence each on why the prediction is a range rather than a number.
Scene 2: Classification: K-NN votes on distance, a decision tree splits on questions
A decision tree speaks a different language. Of 240 students, 66 failed, 27.5 per cent, and the parent entropy is 0.849. Split on attendance of at least 0.80: the 150 who clear it hold 12 failures (8.0 per cent) with entropy 0.402, and the 90 below it hold 54 failures (60.0 per cent) with entropy 0.971. The weighted child entropy is 0.615 and the information gain is 0.233: the more entropy falls, the more the question is worth. The tree pays for itself in interpretability, because each path is an if-then rule a teacher or doctor can read, and the price is that a deeper tree memorises noise, which is the third act.
Student task: classify the same query with k equal to 1, 3 and 5, write three answers, and explain why they may differ; then split on homework completion and compare the gain.
Scene 3: Metrics and hyperparameters: accuracy is half the story, the matrix is all of it
A hyperparameter is a number you set before training, not something the model learns: k in K-NN, tree depth, learning rate, epochs. Sweep one dataset: k of 1 gives 71.0 per cent, k of 5 gives 74.0 and k of 25 gives 68.0. Too small a k lets every neighbour be noise, so training looks perfect and testing suffers; too large a k drags distant students into the vote and underfits both sets. Depth behaves the same way: depth 3 trains to 82.0 and tests at 74.0, a gap of 8.0 points, while depth 12 trains to 99.0 and tests at 68.0, a gap of 31.0. Overfitting looks like near-perfect training with a falling test score; underfitting is poor on both. The remedies are a held-out validation set, cross-validation, regularisation and pruning, not more depth.
Student task: given a fraud detector claiming 99 per cent accuracy, ask three questions (baseline, precision, recall) and say which metric matters most to a school.
04 Question types and worked steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Predict from a regression equation and explain both parameters | Summary statistics, or the equation itself | Three steps: write y equals slope times x plus intercept, substitute the query, then explain each parameter including the extrapolation warning | Slope 1.6, intercept 50.0, three hours gives 54.8 |
| Judge the fit with r squared and residuals | Either r squared, or the residual and total sums of squares | Compute one minus the residual sum over the total, then the mean error, then say how much is explained and how much is left | r squared 0.64, residual sum 360, mean error 3.0 marks |
| Classify with K-NN and explain k | A few labelled cases, a query point and k | Four steps: standardise, measure distances, take the k nearest, vote; then state what a small k costs | Distance 0.8333; k of 5 gives 3 to 2 |
| Split a tree and compute information gain | Parent and two child nodes with positive and negative counts | Three steps: three entropies, weight by sample share, subtract; then test a second split the same way | Parent 0.849, children 0.615, gain 0.233 |
| Compute four metrics from a confusion matrix | The four counts TP, FP, FN and TN | Write four formulas: accuracy includes TN, precision divides by predicted positives, recall by actual positives, F1 is the harmonic mean | 74.0, 84.0, 70.0 and F1 76.4 per cent |
05 Independent practice (3 questions)
| Question | Answer | What to watch |
|---|---|---|
| The regression is y equals 1.6x plus 50.0 with r squared 0.64. (a) What does six hours predict? (b) What percentage of variance is unexplained? | (a) 59.6 marks; (b) 36 per cent, a residual sum of 360 | Whether r squared was read as a mark error |
| A confusion matrix has TP 42, FP 8, FN 18 and TN 32. Find accuracy, precision, recall and F1. | Accuracy 74.0, precision 84.0, recall 70.0 and F1 76.4 per cent; always passing scores 60.0 per cent | Whether both denominators were placed correctly |
| A parent node holds 240 students with 66 failures; one child has 150 with 12 and the other 90 with 54. Find the weighted entropy and the gain. | Child entropies 0.402 and 0.971, weighted 0.615, gain 0.233 | Whether the weights used sample shares rather than a plain average |
06 Common mistakes and what to say
| Mistake | Student writes | Say this |
|---|---|---|
| Reading r squared as accuracy | Saying r squared 0.64 means a 64 per cent chance of a correct prediction | r squared of 0.64 means 64 per cent of the mark variance is explained by study time and 36 per cent comes from elsewhere. Accuracy belongs to classification and the two do not convert. |
| Running K-NN unscaled | Saying both features are numbers, so the distance is fine | A 6 mark gap is 6 units while a 0.08 attendance gap is 0.08 units, so attendance counts for nothing. Standardise first and the squared shares become 36.0 and 64.0 per cent. |
| Quoting accuracy without the baseline | Saying 74 per cent accuracy makes the model usable | Always predicting pass already gives 60.0 per cent. You gain 14.0 points, but 18 failing students are missed and recall is only 70.0 per cent. State the baseline, then state what you bought. |
| Swapping overfitting and underfitting | Saying training 99 and testing 68 means the model learned too little | Training 99.0 against testing 68.0, a gap of 31.0 points, is memorising the training noise, which is overfitting. Underfitting is poor on both, such as a depth 1 tree scoring about sixty on each. |
07 Homework (paper, section and question numbers)
- IB Computer Science chapter index — All chapters in this subject
- Data preprocessing: cleaning, feature selection and reduction — The previous chapter: three imputations, standardisation, the curse of dimensionality
- Tutor prep guide index — Matching chapters in other subjects
08 Exit check (last 5 minutes)
| Question | Answer | Decision |
|---|---|---|
| Regression | Slope 1.6, intercept 50.0, r squared 0.64 | A missing intercept meaning means replay act one |
| Classification | K-NN distance 0.8333, tree gain 0.233 | Voting with no distance means not yet |
| Metrics | F1 76.4 per cent against a 60.0 per cent baseline | Accuracy alone misses the baseline |
09 Tutor FAQ
Is A4.3 SL or HL?
All of A4.3 is HL only, while A4.1 and A4.4 are for both levels. SL students need the five learning families, the hardware ladder and the ethics debates, but not regression, K-NN, decision trees, entropy, confusion matrices, hyperparameters or overfitting.
Must a decision tree use entropy?
The guide only asks that a tree categorise new data points and never names entropy or the Gini index. Entropy is taught because it can be computed by hand and shows how much uncertainty fell. If a question supplies positive and negative counts, entropy is the safest route; if it supplies Gini values, use those, since both usually pick the same split.
How is k chosen?
Sweep a validation set: k of 1 gives 71.0 per cent, k of 5 gives 74.0 and k of 25 gives 68.0, so 5 wins. In practice use an odd k to avoid ties and start near the square root of the sample size. A larger k smooths the boundary but underfits.
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.



