/en-tutor-prep-ib-cs-linear-regression-classification-metrics/
/en-tutor-prep-ib-cs-linear-regression-classification-metrics/
General Inquiry: info@TutorZone.com.hk
Office Hours: Monday to Saturday - 9:00 AM to 6:00 PM
WhatsApp Monday to Sunday - 24 hours
Hotline: +852 6828 1809
Instant Support: +852 9061 3106

IB Computer Science Linear Regression, Classification and Evaluation Metrics: Tutor Prep Guide (slope 1.6, r squared 0.64, F1 76.4 per cent)

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.

Objectives — Students can: (1) write the regression equation and explain both numbers, 1.6 marks per extra hour and 50.0 marks at zero hours, including the danger of extrapolating; (2) read the fit from r squared: 0.64 means 64 per cent of the variance is explained, leaving a residual sum of squares of 360, with a mean error of 3.0 marks; (3) compute K-NN: a standardised distance of 0.8333 from a 6 mark gap and a 0.08 attendance gap, with the five nearest neighbours voting 3 to 2 for pass, or 60 per cent; (4) split a decision tree with entropy: parent 0.849, weighted children 0.615, information gain 0.233; (5) compute four metrics from a confusion matrix: accuracy 74.0 per cent, precision 84.0, recall 70.0 and F1 76.4; (6) explain hyperparameters and overfitting: k rising from 1 to 5 adds 3.0 points and rising to 25 loses 6.0 points, while depth 3 leaves a 8.0 point train and test gap and depth 12 leaves 31.0 points.

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

Start from summary statistics for 40 students: a mean of 5.0 hours of study, a mean of 58.0 marks, a sum of squared deviations in hours of 250, a sum of cross products of 400, and a sum of squared deviations in marks of 1000. The slope is 400 over 250, or 1.6: one more hour of study predicts 1.6 more marks. The intercept is the mean mark minus the slope times the mean hours, 58.0 minus 1.6 times 5.0, which is 50.0, the prediction at zero hours. The data only covers one to ten hours, so extending the line to zero is extrapolation and must be said out loud.
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

K-NN starts with scaling, or the largest unit dominates: a 6 mark gap against a standard deviation of 12 is 0.5 standard deviations, a 0.08 attendance gap against 0.12 is 0.67 standard deviations, and the distance is the square root of the squares, 0.8333. The five nearest neighbours sit at 0.42, 0.61, 0.78, 0.9 and 1.12, labelled pass, pass, fail, pass, fail, so the vote is 3 to 2 for pass, 60 per cent. With k equal to 3 only the closest three vote, giving 2 to 1, the same answer with less confidence. An even k can tie at 2 to 2, which is why practice uses odd values. The other exam point is scaling: unscaled, the distance is almost the mark gap and attendance takes no part.
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

Draw the confusion matrix first. Of 100 predictions, 42 failing students are caught, 8 are wrongly flagged, 18 are missed and 32 are correctly cleared. Accuracy is (42 plus 32) over 100, or 74.0 per cent. Precision is 42 over (42 plus 8), 84.0 per cent, answering how many of those you flagged really fail. Recall is 42 over (42 plus 18), 70.0 per cent, answering how many of the true failures you caught. F1 is their harmonic mean, 76.4 per cent, and specificity is 80.0 per cent. The decisive question: always predicting pass scores 60.0 per cent, so 74.0 per cent is only 14.0 points better, and accuracy without the baseline says nothing.
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
Sanity check (teach this): Five checks. First, the slope and intercept must return the mean point: 1.6 times 5.0 plus 50.0 is 58.0, and anything else is a wrong intercept. Second, r squared lies between zero and one and must reconcile with the residual sum: one minus 360 over 1000 is 0.64. Third, entropy lies between zero and one and a split must lower it: 0.615 is below 0.849, so the gain 0.233 is positive, and a negative gain means the split is useless. Fourth, precision and recall divide by different totals: 84.0 per cent divides by the 50 predicted positives and 70.0 per cent by the 60 actual positives, and they match only when FP equals FN. Fifth, accuracy must be compared with the baseline: 74.0 per cent against 60.0 per cent for always passing. The commonest misjudgement is reading r squared as predictive accuracy: one measures variance explained, the other is the language of classification, and they do not convert.

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)

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.

Join as a tutor or coach — academic, music, sports, arts, STEM. Free to register. See how it works →