IB Computer Science Data Preprocessing: Cleaning, Feature Selection and Dimensionality Reduction (7.8 to 4.2 error, 78 fits, curse of dimensionality)
- 2026-11-27
Students think a weak model needs a stronger algorithm, but A4.2 asks something else: clean and scale the same 4,800 rows properly and a plain K-NN beats an uncleaned complex model. This lesson turns preprocessing into four bills you can add up.
01 Prerequisites (3-minute check)
If any of these fails, fix it before the lesson starts.
| Skill | Quick check | Pass mark |
|---|---|---|
| Mean and standard deviation | With a mean of 68.5 and a standard deviation of 12.4, what is the z value of 75 | About 0.52 |
| Percentages | What percentage is 96 out of 4800 rows | Part over whole, times one hundred |
| Distance | Two points differ by 3 and by 4. What is the distance | Five, by Pythagoras |
02 Lesson flow (60 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0-8 min | Opening check | Ask what a model learns when one student appears twice | Write an answer, compare at the end |
| 8-24 min | Cleaning and imputation | 96 duplicates, 288 missing, 1,776 bad formats | Choose a treatment per defect |
| 24-38 min | Three selection strategies | 12 columns kept down to 5, 78 fits against 4,095 | State the difference |
| 38-52 min | Normalisation and standardisation | A 10 mark gap against a 0.1 attendance gap | Compute z values and shares |
| 52-57 min | Curse and reduction | The coefficient falls from 0.476 to 0.059 | State the cost |
| 57-60 min | Exit check | Collect and mark three items | Work independently |
03 Teaching script (read it out)
Scene 1: Cleaning: four defects, four treatments, one principle
Cost the three imputations. Deleting 288 rows throws away 6.0 per cent of the sample, and if the students with missing scores are mostly low scorers, the model never learns about them. Filling the mean of 68.5 is cheapest but flattens the variance and errs by 7.8 marks on average. A simple regression on attendance and homework completion predicts the missing score with an error of 4.2 marks, 46.2 per cent lower. State the principle: ask why the value is missing. If missingness relates to the answer, deletion biases the model, and imputation should add a column flagging that the value was missing.
Finish with normalisation against standardisation. Normalisation maps to zero and one: value minus minimum, over maximum minus minimum, so a 0 to 100 score becomes 0 to 1. Standardisation is value minus mean, over standard deviation, so 75 marks gives (75 minus 68.5) over 12.4, about 0.52, and the output may be negative. With extreme values, standardisation is steadier, and the median and interquartile version is steadier still.
Student task: five defect cases (duplicates, six per cent missing, three date formats, a score of 999, a score of minus five), each with one treatment and one sentence on what goes wrong if nothing is done.
Scene 2: Feature selection: keep the most informative columns, not the fewest
Cost both sides. 4,800 rows times 12 columns times 8 bytes is 460,800 bytes; after de-duplication, 4,704 rows times 5 columns is 188,160 bytes, or 40.8 per cent. Distance computation falls from 12 dimensions to 5 across 11,517,600 pairs of rows.
A dropped column cannot be recovered, so remove the two that can never be used, identifiers and post-hoc fields such as final grade, then let the three strategies argue over the rest. The post-hoc field is the leak that makes a model look perfect in training.
Student task: for 12 named columns, say keep, drop or investigate, and identify which one is target leakage.
Scene 3: Scaling and the curse of dimensionality: when the unit is the whole game
Then dimensions. Scatter 250 random points in a unit cube and measure every pairwise distance. In two dimensions the mean distance is 0.53 with a standard deviation of 0.25, a coefficient of variation of 0.476. In 12 dimensions it is 0.175, in 100 it is 0.059, and in 1,000 it is 0.019. The lower the coefficient, the closer the nearest neighbour comes to the farthest, and the less distance means anything. That is the curse of dimensionality, and it is why K-NN degrades in high dimensions.
Reduction is the countermeasure: compress 100 columns into 10 components that keep most of the variance, and distances regain contrast. The price is that components are no longer the original columns, interpretation weakens, and the projection must be recomputed for new data. The guide states explicitly that principal component analysis and linear discriminant analysis are beyond scope, so the class only needs why we reduce and what reduction costs.
Student task: three sentences on one dataset, each with a number: what happens without scaling, what scaling changes, what reduction trades away.
04 Question types and worked steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Diagnose defects and choose treatments | A table with duplicates, missing values, bad formats and outliers | Four steps: count affected rows, decide whether missingness relates to the answer, choose delete or impute, record before and after counts | 96 duplicates (2.0 per cent), 6.0 per cent missing, 37.0 per cent bad formats |
| Choose a selection strategy | A column count, a row count and whether retraining is affordable | Drop identifiers and leaks first, then pick by cost: filter is fastest, wrapper is most accurate but expensive, embedded finishes inside one training run | 78 forward fits against 4,095 subsets at 12 columns |
| Compute standardisation and shares | Two features with a mean and a standard deviation, and the gaps for one pair of students | Take each z value, square both, then compute the shares. Squaring before adding is the step students skip | 0.81 and 0.83; shares of 48.4 and 51.6 per cent |
| Explain the curse and the cost of reduction | A 12 dimension dataset and a 100 dimension dataset | Distance concentration, then K-NN failure, then reduce or collect more rows, then name the cost to interpretability | The coefficient falls from 0.175 to 0.059 |
05 Independent practice (3 questions)
| Question | Answer | What to watch |
|---|---|---|
| 4,800 rows include 96 exact duplicates. How many rows remain, and what percentage were duplicates? | 4,704 rows, with 2.0 per cent duplicates | Whether duplicates were counted as additions |
| Mean imputation errs by 7.8 marks and regression imputation by 4.2. What percentage better is regression? | 46.2 per cent (a gap of 3.5999999999999996 over the original 7.8) | Whether the original error was the denominator |
| A 10 mark gap (standard deviation 12.4) and a 0.1 attendance gap (standard deviation 0.12): after standardisation, what share of the squared distance does each take? | 48.4 and 51.6 per cent (z values of 0.81 and 0.83) | Whether both values were squared before adding |
06 Common mistakes and what to say
| Mistake | Student writes | Say this |
|---|---|---|
| Treating mean imputation as universal | Saying fill the mean, it is fastest | Filling the mean of 68.5 pulls everyone towards the middle and flattens the variance, with an error of 7.8 marks. Regressing on attendance brings it to 4.2. If missingness relates to the answer, add a flag column as well. |
| Running K-NN without scaling | Saying both features are already numbers, so distance is fine | A 10 mark gap is 10 units and a 0.1 attendance gap is 0.1 units, so the mark gap counts 100.0 times as much and attendance is effectively ignored. Standardise first, then both count about half each. |
| Assuming more features are always better | Saying put all 12 columns in, more data is more accurate | Seven of the twelve columns barely correlate with the answer and only spread the distances: the coefficient falls from 0.476 to 0.059. Five columns keep most of the signal. |
| Deleting missing rows without costing it | Saying drop every row with a gap | Dropping 288 rows loses 6.0 per cent of the sample. If missing scores cluster among low scorers, the model never sees them, so impute and flag instead. |
07 Homework (paper, section and question numbers)
- IB Computer Science chapter index — All chapters in this subject
- Machine learning types and hardware — The previous chapter: five families, labelling cost, the hardware ladder
- Tutor prep guide index — Matching chapters in other subjects
08 Exit check (last 5 minutes)
| Question | Answer | Decision |
|---|---|---|
| Four defects | Duplicates, missing values, formats, outliers | Saying the data is dirty means replay act one |
| Three imputations | Delete, mean at 7.8, regression at 4.2 | No error figures means not yet |
| Standardisation | z values of 0.81 and 0.83, about half each | Dividing by the maximum means normalisation was confused with standardisation |
09 Tutor FAQ
Must PCA be taught?
A4.2.3 states that principal component analysis and linear discriminant analysis are beyond scope. Teach the purpose of reduction, which is fighting the curse, saving memory and allowing visualisation, and its cost, which is that components lose the meaning of the original columns. Eigen-decomposition does not belong in this course.
When do we normalise and when do we standardise?
Both are scaling. Normalisation, or min-max, maps values into a fixed range, which suits bounded features without extremes. Standardisation, or the z score, centres on the mean and scales by the standard deviation, which suits features with outliers or algorithms that assume a normal shape. K-NN, neural networks and gradient descent prefer standardisation.
How do we choose among the three imputations?
Ask about the mechanism. Values missing completely at random may be deleted; values related to other columns call for regression or K-NN imputation; values related to the answer itself require a flag column, or the model confuses missing with low. Here 288 of 4,800 scores are missing (6.0 per cent), so deletion throws away too much and imputation wins.
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.



