Revision Notes
IB DP Computer Science (DP Computer Science): Data Preprocessing for Machine Learning (HL) – Revision Notes
Condensed HL notes on data preprocessing for IB DP Computer Science A.4: cleaning, imputation, outliers, scaling, encoding, splitting and a self-test.
- Subject
- Computer Science
- Level
- IB
- Topic
- A.4 – Machine learning
- Author
- Marlbridge Academic Team
- Updated
- Reviewed by
- Harris Khan (what this means)
Aligned to International Baccalaureate IB Diploma Programme Computer Science (DP Computer Science), First assessment 2027. Official subject brief .
Syllabus page (what it covers and how it is assessed): IB Diploma Programme Computer Science.
Found an error? Report a correction.
Need help with this topic? Request a free trial class for IB Diploma Programme Computer Science (DP Computer Science (2014) / DP Computer Science (2027)).
Quick-recall notes for A4.2 Data preprocessing, an HL-only section of A.4 Machine learning (IB DP Computer Science, first assessment 2027). For explanations and worked calculations, use the data preprocessing study guide; for training data, features and labels, see the A.4 Machine learning revision notes.
Key terms
| Term | Meaning |
|---|---|
| Data preprocessing | Preparing raw data before it is used to train a model |
| Data cleaning | Correcting or removing missing, duplicate, inconsistent or invalid data |
| Imputation | Filling in missing values with estimates |
| Outlier | A value far from most of the data; may be an error or a genuine rare case |
| Feature scaling | Putting numeric features on comparable ranges |
| Min-max scaling | (x − min) ÷ (max − min), giving values from 0 to 1 |
| Standardisation | (x − mean) ÷ standard deviation, giving mean 0 and standard deviation 1 |
| Label encoding | Giving each category a number |
| One-hot encoding | One binary column per category |
| Feature selection | Keeping only relevant, non-redundant features |
| Data leakage | Information from outside the training data (for example the test set or the answer) entering training |
| Overfitting | Learning noise in the training data so the model generalises poorly |
| Training / validation / test set | Data to fit the model / tune it / measure final performance |
The four jobs
- Clean: missing values, duplicates, inconsistent formats, invalid values, outliers.
- Transform: scale numeric features; encode categorical ones.
- Select: keep relevant features; remove redundant or leaking ones.
- Split: training, validation, test, each representative.
Missing values: choose the strategy
| Situation | Strategy |
|---|---|
| Few rows affected, plenty of data | Delete those rows |
| Column mostly empty | Delete the feature |
| Numeric, no extreme values | Impute mean |
| Numeric, with extreme values | Impute median |
| Categorical | Impute mode |
| Missingness may be meaningful | Impute and add a “missing” flag |
Calculations to practise
Mean imputation: 16, 17, ?, 19, 18 → (16 + 17 + 19 + 18) ÷ 4 = 17.5.
Median imputation: 12, 14, ?, 15, 90 → known values in order 12, 14, 15, 90; median = (14 + 15) ÷ 2 = 14.5. (The mean, 32.75, is distorted by 90.)
Min-max scaling: 50, 80, 120, 200 → 0, 0.2, 0.467, 1 (min 50, range 150).
Encoding at a glance
| Method | Example (red, green, blue) | Use when |
|---|---|---|
| Label | 0, 1, 2 | Categories have a real order (small, medium, large) |
| One-hot | (1,0,0), (0,1,0), (0,0,1) | No natural order |
Outliers: error or signal?
- Error (typing mistake, faulty sensor) → correct or remove.
- Genuine rare case (fraud, rare disease) → keep; it may be what the model must detect.
- Decide using knowledge of the context.
Feature selection checklist
- Relevant? Keep features that plausibly relate to the prediction.
- Redundant? Drop one of two columns that measure the same thing (height in cm and in inches).
- Leaking? Drop any feature recorded after the outcome or derived from it.
- Available in use? Keep only features that will exist when the model makes real predictions.
Splitting rules
- Split first; compute means, medians, minima and maxima from the training set only.
- Each set should represent all classes and groups; watch out for rare classes.
- Use the test set once, at the end.
Links to ethics
- Deleting rows can remove under-represented groups and introduce bias.
- Removing a sensitive feature does not ensure fairness if a proxy (such as postcode) remains.
- Poor preprocessing produces unreliable decisions about real people.
Exam traps
- ML “normalisation” means scaling; database normalisation (A.3) is different.
- Do not remove all outliers by rule.
- Label encoding unordered categories invents an order.
- Scaling before splitting causes leakage.
- Always tie a technique to the specific data problem in the scenario.
Self-test
- Why does a model trained on uncleaned data perform badly?
- Give two ways to handle missing values.
- When is the median better than the mean for imputation?
- Impute the missing value in 8, 10, ?, 12 using the mean.
- Scale the value 30 in the data set 10, 30, 60 using min-max scaling.
- Why are features scaled?
- What problem does label encoding cause for the categories cat, dog, rabbit?
- One-hot encode the value “dog” for the categories cat, dog, rabbit.
- Give one reason not to remove an outlier.
- What is data leakage?
- State the purpose of the test set.
- How could deleting rows with missing data introduce bias?
Answers:
- It learns errors, duplicates and inconsistencies as if they were real patterns.
- Any two: delete the rows; delete the feature; impute mean, median or mode; add a missing flag.
- When the data contains extreme values, which pull the mean towards them.
- (8 + 10 + 12) ÷ 3 = 10.
- (30 − 10) ÷ (60 − 10) = 20 ÷ 50 = 0.4.
- So that features with large numeric ranges do not dominate those with small ranges.
- It implies an order (rabbit > dog > cat) that does not exist, which can mislead the model.
- (0, 1, 0).
- It may be a genuine rare case, such as fraud, that the model needs to learn.
- Information from outside the training data, such as the test set or the answer itself, influencing training, so performance looks better than it really is.
- To give a final, unbiased estimate of how well the model performs on unseen data.
- If values are more often missing for one group, deleting those rows leaves that group under-represented in the training data.
Related pages
Official syllabus
International Baccalaureate Organization, Diploma Programme Subject Brief – Sciences: Computer science, first assessment 2027, © 2024.
Related resources
-
Study guides
IB DP Computer Science A.4: Machine Learning
Study guide to A.4 Machine learning in IB DP Computer Science: rules versus learning, training data, features, supervised and unsupervised learning, and ethics.
Computer Science · International Baccalaureate · IB
Read guide -
Practice questions
IB DP Computer Science A.4: Machine Learning – Practice Questions
Twelve original questions on rules versus learning, learning types, a trace table, bias, transparency and energy use for IB DP Computer Science A.4.
Computer Science · International Baccalaureate · IB
Try questions -
Revision notes
IB DP Computer Science A.4: Machine Learning – Revision Notes
Recall notes on IB DP Computer Science A.4 Machine learning: rules versus learning, features, labels, learning types, applications and ethics, with a self-test.
Computer Science · International Baccalaureate · IB
Revise topic
Get free revision emails (optional)
Occasional emails with practice questions, worked explanations and links to free resources for the qualification and subjects you choose. No spam, and you can unsubscribe from any email. The free tools on this site never need an email.