DigiBacc

Practice questions › IB Computer Science › Machine learning › Data preprocessing
IB Computer Science · Machine learning

Data preprocessing practice questions.

30 exam-style questions on Data preprocessing — topic A4.2 of Machine learning in the IB Computer Science syllabus — with answers and explanations. Samples below; the full set is free with an account.

At a glance

About this topic

Syllabus code
A4.2
Subject
IB Computer Science
Topic
A4 · Machine learning
Questions
30 with worked answers
Question types
9 multiple-choice questions · 7 fill-in-the-gap questions · 6 flashcards · 4 true/false questions · 3 matching tasks · 1 structured question
Try it

Sample questions on Data preprocessing

A column of patient weights has 150 empty entries out of 5000 records. Every empty entry is filled with the mean of the values that are present. Which statement about the effect on that column is correct?

  • The mean of the column is unchanged, but its spread is reduced.
  • The mean of the column rises, because further values have been added to it.
  • Both the mean and the standard deviation of the column stay exactly as they were.
  • The spread of the column increases, because 150 identical values have been inserted.

Answer: The mean of the column is unchanged, but its spread is reduced.

Adding 150 copies of the mean cannot move the mean, but each copy sits at distance zero from it, so the standard deviation falls and the column looks more consistent than the measurements really were.

A nominal attribute holding the values 'petrol', 'diesel', 'hybrid' and 'electric' is replaced by the integers 1, 2, 3 and 4. Which problem does this create for the model?

  • The attribute can no longer be stored, because integers occupy more memory than text.
  • The model treats the values as ordered and as equally spaced, which they are not.
  • The attribute now holds four times as many rows as the other attributes in the table.
  • The model cannot accept integers as input and needs the original text to be restored.

Answer: The model treats the values as ordered and as equally spaced, which they are not.

Integers carry an order and a distance, so the encoding silently claims that electric is four times petrol and that hybrid lies between diesel and electric. One-hot encoding avoids the claim by giving every category its own binary column.

A k-nearest neighbours model uses two features: annual income, with values in the tens of thousands, and number of children, from 0 to 5. Why are the features scaled before training?

  • Without scaling the feature with the larger range dominates distance calculations.
  • Scaling deletes the records whose values fall outside the expected range.
  • Scaling converts both features into categories so that they can be encoded as binary columns.
  • Scaling guarantees that the two features become statistically independent of one another.

Answer: Without scaling the feature with the larger range dominates distance calculations.

Income runs into the tens of thousands while the second feature never passes 5, so any distance is decided almost entirely by income. Scaling is about comparability of ranges, not about removing records or creating independence.

A feature has a minimum of 20 and a maximum of 120 across the training set. Calculate the scaled value of an observation of 45 after min-max normalisation to the range 0 to 1.

  • 0.20
  • 0.38
  • 0.25
  • 0.45

Answer: 0.25

Min-max normalisation subtracts the minimum before dividing by the range, so (45 - 20) / (120 - 20) = 25 / 100 = 0.25. Dividing by the maximum alone gives 0.38 and ignores that the scale starts at 20 rather than 0.

An analyst scales every numerical column using the minimum and maximum of the complete dataset, and only afterwards separates the rows into a training set and a test set. Why is this poor practice?

  • The scaled values will all fall outside the range 0 to 1 once the split is made.
  • The training set will hold fewer rows than the test set after the scaling step.
  • Scaling may only be applied once a dataset has already been divided into two parts.
  • Information from the test rows has shaped the training data, so the test score flatters the model.

Answer: Information from the test rows has shaped the training data, so the test score flatters the model.

The minimum and maximum are themselves quantities learned from the data, and taking them from all rows lets the test rows influence training. That is data leakage, and it makes the reported test score too optimistic.

A column of daily temperatures in degrees Celsius holds values between 18 and 34, apart from a single entry of 999 left by a faulty sensor. Which statement about that entry is correct?

  • The median of the column rises sharply while the mean is barely affected.
  • The mean of the column rises noticeably while the median barely moves.
  • Neither the mean nor the median changes, because one value among many is ignored.
  • The mode of the column becomes 999, because that value is the largest one present.

Answer: The mean of the column rises noticeably while the median barely moves.

The mean adds every value, so one extreme entry drags it upwards, whereas the median only depends on the position of the middle value. That is why the median is the safer choice for filling gaps in a column that contains outliers.

That was 6 of 30 Data preprocessing questions.

Practise all 30 free
Exam tips

Command terms in this topic

Keep going

More topics in Machine learning

All of Machine learning →

30 Data preprocessing questions — free with an account. Spaced repetition, streaks and full exam simulations included.

Practise them free

This platform is independently developed and is not endorsed by, affiliated with, or sponsored by the International Baccalaureate Organization. “International Baccalaureate” and “IB” are registered trademarks of the IBO.