Scribe logoScribeNotes & practice
Sign inStart free
  1. Notes
  2. ›IB Computer Science
  3. ›A4 Machine learning
  4. ›A4.2 Data preprocessing

IB Computer Science · A4 · Machine learning

A4.2 Data preprocessing

Explain why raw data is preprocessed and describe the main techniques for cleaning and transforming it.

  • 4 min read
  • 5 parts
  • 10 questions
  • Draft
  • HL only
Start a Quick 5 on this topic→Jump to the 10 questions
1/5Raw data is rarely ready for a model to use
  1. 1Raw data is rarely ready for a model to use
  2. 2Cleaning removes errors and fills gaps
  3. 3Normalisation puts features on a common scale
  4. 4Categories and unwanted features also need transforming
  5. 5Poor data quality leads to unreliable models
  6. Check your recall
  7. Practice: 10 questions
1

Part 1 of 5: Raw data is rarely ready for a model to use

Suppose a survey records ages, but some people typed ‘twenty’ and others left the box blank. A model cannot learn sensibly from such entries. Data preprocessing is the work of preparing raw data before training.

A model learns from whatever it is given. Poor input gives poor results, often summed up as ‘garbage in, garbage out’. Preprocessing therefore takes up much of a real project.

It has two broad parts. Cleaning fixes problems in the data. Transforming changes its form so that a model can use it.

Key term

data preprocessing

Data preprocessing is the cleaning and transforming of raw data into a form suitable for training a machine learning model.

Part 1 done

2

Part 2 of 5: Cleaning removes errors and fills gaps

Start with cleaning. The first problem is a missing value, an entry with no recorded data. You can delete the affected records, or fill each gap with an estimate such as the mean of that feature.

Duplicate records give some cases extra weight, so remove them. Inconsistent entries, such as ‘UK’ and ‘United Kingdom’, should be made uniform.

An outlier is a value far from the rest. It may be an error, such as a height of 1750 cm, or a rare true case. Check it before removing it.

Common mistake

Do not delete every outlier automatically. A genuine rare case, such as a fraudulent payment, may be exactly what the model needs to learn.

Key terms · tap one for its definition

missing value

A missing value is an entry in a dataset for which no data was recorded.

outlier

An outlier is a data value that lies unusually far from most other values in the dataset.

Part 2 done

Quick check

One question on the part you just read

Easy

State what data preprocessing is.
Show answer and explanation

Answer: A · Worked explanation

Data preprocessing prepares raw data before training, through cleaning and transforming. Testing on unseen cases is evaluation, which comes after training. Collecting data and choosing an algorithm are separate steps, and neither changes the form or quality of data already collected.
3

Part 3 of 5: Normalisation puts features on a common scale

Cleaning leaves valid data, but its scale may still cause trouble. Compare floor area, about 100 m², with number of rooms, about 4. A model that compares distances would be dominated by the larger numbers.

Normalisation rescales a feature to a fixed range, usually 0 to 1. Min–max scaling does this using the smallest and largest values of the feature, xminx_\mathrm{min}xmin​ and xmaxx_\mathrm{max}xmax​: x′=x−xminxmax−xminx' = \frac{x - x_\mathrm{min}}{x_\mathrm{max} - x_\mathrm{min}}x′=xmax​−xmin​x−xmin​​.

Worked example

Min–max scaling

A feature has a smallest value of 50 m250\,\mathrm{m^2}50m2 and a largest value of 250 m2250\,\mathrm{m^2}250m2. Scale a value of 150 m2150\,\mathrm{m^2}150m2 to the range 0 to 1.
  1. 1
    Scaled value = the value minus the smallest, divided by the range.
  2. 2
    Write the equation: x′=x−xminxmax−xminx' = \frac{x - x_\mathrm{min}}{x_\mathrm{max} - x_\mathrm{min}}x′=xmax​−xmin​x−xmin​​.
  3. 3
    Substitute: x′=150 m2−50 m2250 m2−50 m2=100200x' = \frac{150\,\mathrm{m^2} - 50\,\mathrm{m^2}}{250\,\mathrm{m^2} - 50\,\mathrm{m^2}} = \frac{100}{200}x′=250m2−50m2150m2−50m2​=200100​.
  4. 4
    Divide: 100200=0.5\frac{100}{200} = 0.5200100​=0.5.

Answer: The scaled value is 0.5. It has no unit, because the units cancel.

The smallest value always becomes 0 and the largest becomes 1.

Key term

normalisation

Normalisation is the rescaling of a numerical feature to a fixed range, usually 0 to 1, so that features are comparable.

Part 3 done

4

Part 4 of 5: Categories and unwanted features also need transforming

Scaling handles numbers, but data also holds categories such as colour or country. Most algorithms need numbers, and cannot average ‘red’ and ‘blue’. Encoding converts categories into numeric form.

One-hot encoding gives each category its own column. A 1 marks the category that applies, and 0 fills the rest.

One-hot encoding of colour

ColourRedGreenBlue
Red100
Green010
Blue001
Colour
Red
Red
1
Green
0
Blue
0
Colour
Green
Red
0
Green
1
Blue
0
Colour
Blue
Red
0
Green
0
Blue
1

Feature selection keeps useful features and drops irrelevant ones, such as a customer ID number. Fewer features can shorten training. They can also reduce overfitting, where a model learns quirks of its examples.

Key terms · tap one for its definition

encoding

Encoding is the conversion of categorical data into numeric values that an algorithm can process.

feature selection

Feature selection is the choice of the most relevant features for training, with irrelevant features removed.

Part 4 done

Quick check

One question on the part you just read

Easy

Which example is a missing value?
Show answer and explanation

Answer: C · Worked explanation

A missing value is an entry with no recorded data, like a blank age. An age of 250 is a likely outlier or error. Two identical rows are duplicates. Different spellings of one country are inconsistent entries. Each of these needs a different cleaning step, so they should not be confused.
5

Part 5 of 5: Poor data quality leads to unreliable models

Finally, consider what happens when preprocessing is skipped. Data quality describes how accurate, complete, consistent and relevant a dataset is for its purpose. Each weakness harms a model in a different way.

  • Inaccurate or noisy data teaches false patterns.
  • Missing or unrepresentative data leaves gaps, so the model fails on unseen cases.
  • Inconsistent formats cause records to be misread or ignored.
  • Unscaled features let large numbers dominate the result.
  • Irrelevant features add noise and can encourage overfitting.

Exam tip

When asked about consequences, link each data problem to its effect, such as lower accuracy or unfair predictions.

Apply the same steps to new data at deployment. Otherwise the model receives input in a form it never learned.

Key term

data quality

Data quality is the extent to which a dataset is accurate, complete, consistent and relevant for its intended purpose.

Note read

Check your recall[14 marks]

5 written questions. Answer each one in your head or on paper, then open the mark scheme.

  1. 1.Explain[3 marks]

    Explain why data preprocessing is important in machine learning.

    Show mark schemeHide mark scheme

    Model answer

    A model learns from whatever data it is given, so errors and gaps lead to poor predictions. Cleaning removes problems such as duplicates and missing values. Transforming, for example by scaling, puts the data in a form the model can use properly.

    • 1 mark for stating that a model learns from the data it is given, so poor data gives poor results
    • 1 mark for stating that cleaning removes errors, gaps or duplicates
    • 1 mark for stating that transforming puts data in a suitable form, such as a common scale
  2. 2.Describe[2 marks]

    Describe two ways of handling missing values in a dataset.

    Show mark schemeHide mark scheme

    Model answer

    Delete the records that contain missing values. Alternatively, fill each gap with an estimate, such as the mean of that feature.

    • 1 mark for describing deleting the affected records
    • 1 mark for describing filling gaps with an estimate such as the mean
  3. 3.Determine[3 marks]

    Determine the min–max scaled value of 20 for a feature with a smallest value of 10 and a largest value of 50.

    Show mark schemeHide mark scheme

    Model answer

    x′=x−xminxmax−xmin=20−1050−10=1040=0.25x' = \frac{x - x_\mathrm{min}}{x_\mathrm{max} - x_\mathrm{min}} = \frac{20 - 10}{50 - 10} = \frac{10}{40} = 0.25x′=xmax​−xmin​x−xmin​​=50−1020−10​=4010​=0.25.

    • 1 mark for writing the min–max equation
    • 1 mark for substituting 20, 10 and 50 correctly
    • 1 mark for obtaining 0.25
  4. 4.Outline[2 marks]

    Outline how one-hot encoding represents the colours red, green and blue.

    Show mark schemeHide mark scheme

    Model answer

    Each colour gets its own column. A 1 is placed in the column of the colour that applies, and 0 in the other columns.

    • 1 mark for stating that each category has its own column
    • 1 mark for stating that 1 marks the matching category and 0 marks the others
  5. 5.Discuss[4 marks]

    Discuss the consequences of using poor-quality data to train a model.

    Show mark schemeHide mark scheme

    Model answer

    Inaccurate or noisy data teaches the model false patterns. Missing or unrepresentative data means it fails on cases it has not seen. Inconsistent formats lead to records being misread. Overall, predictions become unreliable and may be unfair.

    • 1 mark for explaining that inaccurate or noisy data teaches false patterns
    • 1 mark for explaining that missing or unrepresentative data causes failure on unseen cases
    • 1 mark for stating that inconsistent formats cause records to be misread or ignored
    • 1 mark for concluding that predictions become unreliable or unfair

Practice this topic

10 quick-fire multiple-choice questions, easy to hard. Tap an answer to see if you're right and the worked explanation. (The written questions with mark schemes are under “Check your recall” above.)

0 right0 of 10 answered

Includes the 2 quick checks in the note above.

3.

Easy[1 mark]

Which technique converts the categories red, green and blue into numbers?
Show answer and explanation

Answer: D · Worked explanation

Encoding turns categories into numeric form, for example with one column per colour. Normalisation rescales numbers that already exist, so it does not convert anything. Outlier removal deletes unusual values, and feature selection chooses which features to keep. None of these converts categories into numbers, so only encoding fits.
4.

Medium[1 mark]

A feature has a smallest value of 20 and a largest value of 120. What is the min–max scaled value of 80?
Show answer and explanation

Answer: B · Worked explanation

Use x−xminxmax−xmin=80−20120−20=60100=0.6\frac{x - x_\mathrm{min}}{x_\mathrm{max} - x_\mathrm{min}} = \frac{80 - 20}{120 - 20} = \frac{60}{100} = 0.6xmax​−xmin​x−xmin​​=120−2080−20​=10060​=0.6. The value 0.67 comes from dividing 80 by 120 and ignoring the smallest value. The value 0.4 comes from subtracting 80 from the largest value instead of the smallest.
5.

Medium[1 mark]

A dataset of 5000 customer records contains 400 exact duplicates. What is the main problem if they are left in?
Show answer and explanation

Answer: C · Worked explanation

Duplicate records repeat the same case, so the model gives that case more influence than it deserves. Different scales call for normalisation, and unconverted categories call for encoding. Duplicates are complete repeated rows, so they do not create missing values.
6.

Medium[1 mark]

Heights in a class are mostly between 150 cm and 190 cm, but one entry is 1750 cm. What is the best first action?
Show answer and explanation

Answer: A · Worked explanation

The 1750 cm entry is probably a typing error, but this should be checked before any change. Deleting all values above 190 cm may throw away genuine tall people. Normalisation does not remove the problem, because the extreme value still sets the largest end of the scale and squeezes the other heights.
7.

Medium[1 mark]

A distance-based model uses age (18 to 70) and income (in the tens of thousands). With no scaling, which feature will mainly drive the results?
Show answer and explanation

Answer: B · Worked explanation

A distance-based model compares raw numbers, so a feature with much larger values dominates the distance. Income does this here. Models do not ignore scale, which is why normalisation is used. Smaller numbers do not carry more weight, so the argument for age is the wrong way round.
8.

Hard[2 marks]

Mean imputation replaces each missing age with the mean age. What is a drawback of this method?
Show answer and explanation

Answer: C · Worked explanation

Mean imputation inserts estimated values. They may differ from the true ages, and many identical values make the feature look less varied than it really is. The method keeps the records rather than deleting them. It does not create categories, and values at the mean are not outliers.
9.

Hard[2 marks]

A team scales its training data, then sends raw unscaled values to the model at deployment. What is the most likely result?
Show answer and explanation

Answer: A · Worked explanation

A model expects input prepared in the same way as its training data. Unscaled values fall outside the range it learned from, so its predictions are likely to be unreliable. Models do not rescale or retrain themselves, and larger values do not improve accuracy.
10.

Hard[2 marks]

Which statement about feature selection is correct?
Show answer and explanation

Answer: B · Worked explanation

Removing irrelevant features, such as an ID number, can cut noise and training time. Dropping useful features would harm accuracy, so improvement is not guaranteed. Feature selection works on columns, whereas deleting records with missing values works on rows, so the two are different processes.

Keep going

Next topicA4.3 Machine learning approachesPrevious topicA4.1 Machine learning fundamentals

More in A4 · Machine learning

  1. A4.1Machine learning fundamentalsNotes · 10 questions
  2. A4.2Data preprocessingNotes · 10 questions· HL only
  3. A4.3Machine learning approachesNotes · 10 questions· HL only
  4. A4.4Ethical considerationsNotes · 10 questions

All IB Computer Science topics →

Draft: written by Scribe and checked automatically, not yet by a subject reviewer.

Practice questions are original, written by Scribe and checked automatically for correctness.

Topic codes follow the official numbering. Not endorsed by IB Diploma Programme or any exam board.

On this page

0/5 read

  1. 1Raw data is rarely ready for a model to use
  2. 2Cleaning removes errors and fills gaps
  3. 3Normalisation puts features on a common scale
  4. 4Categories and unwanted features also need transforming
  5. 5Poor data quality leads to unreliable models
  6. Check your recall
  7. Practice: 10 questions
All coursesScribeHow it worksPricingPrivacyTerms

Notes and questions are written by Scribe in our own words. Topic codes follow the official course numbering so you can find your place. Not produced or endorsed by the IB, College Board, AQA, OCR, Pearson Edexcel or any exam board.

© 2026 Scribe