This content can't be printed from the browser. Use Export PDF with Pro for an offline copy.
IB Syllabus Requirements for Data preprocessing
A4.2.1
Why data cleaning matters
A4.2.2
Selecting informative features
A4.2.3
Reducing dimensionality
A4.2.1
WHY DATA CLEANING MATTERS
Data cleaning makes the data a model learns from more consistent and improves its quality. When explaining why it matters, link each cleaning action to the problem it prevents. Unreliable inputs can lead to unreliable patterns and predictions.
Data cleaning means identifying and dealing with errors, inconsistencies and unsuitable entries in a data set.
A model learns from the data it receives, not what that data was meant to represent. Incorrect measurements can distort a relationship. Duplicate records may give some observations too much influence, while inconsistent formats can stop equivalent values from being treated alike. Cleaning can improve model performance, but it doesn't guarantee accurate predictions.
| Data-quality problem | Suitable action | Why the choice matters |
|---|---|---|
| Outliers | Investigate values that are unusually distant from the others. Correct verified errors, but retain genuine unusual observations. Only remove an entry when there is a justified reason. | An extreme value can distort learning, yet a rare observation may still be important. |
| Duplicate data | Remove repeated copies of the same observation, or combine overlapping records into one consistent record. | Repetition can give an observation disproportionate influence. Separate observations are not automatically duplicates just because their measurements are identical. |
| Incorrect data | Check values against permitted ranges, consistency rules or the original source. Correct a value when its correct form can be established. | Even a value with the right data type can be wrong: a negative duration, for example. |
| Irrelevant data | Filter out records or fields that do not belong to the prediction task. | Unrelated information can add noise and increase processing work. |
| Improperly formatted data | Convert equivalent values to a consistent representation, using consistent units and data types. | A duration written as text must be interpreted consistently with numeric durations. |
| Missing data | Choose imputation, deletion or predictive modelling according to the amount and nature of the missing information. | Each treatment preserves or discards different amounts of information and can affect the patterns learned. |
An outlier is an observation that differs markedly from the other observations. Suppose a pump runtime is recorded as 600 minutes among much shorter runs. Check it rather than automatically replacing it: the value could be a recording error, or it could be a genuine long run.
In this invented example, a greenhouse records pump runtime to predict water use. The raw records below include a format inconsistency, a duplicate and a missing value.
| Record identifier | Runtime in minutes | Water use in litres |
|---|---|---|
| R1 | 2 | 8 |
| R2 | 2 min | 10 |
| R3 | 6 | 24 |
| R3 | 6 | 24 |
| R4 | 6 | 26 |
| R5 | Missing | 18 |
Start by converting the text entry for R2 to the numeric value 2, keeping minutes as the consistent unit. Then confirm that the repeated R3 entry represents the same pump run before removing the extra copy. Keep R1 and R2 separate. Equal runtimes do not make them duplicate observations.
There are several ways to handle the missing runtime for R5:
Replacing every missing runtime with 4 creates repeated estimated values; it does not recover the actual measurements. Choose the treatment deliberately, because it changes the data.
Normalization rescales numeric values to a common range, commonly from 0 to 1.
For min–max normalization:
normalized value = (value − minimum) / (maximum − minimum)
Standardization rescales numeric values by subtracting their mean and dividing by their standard deviation. Provided the original standard deviation is not zero, the resulting feature has a mean of 0 and a standard deviation of 1.
standardized value = (value − mean) / standard deviation
These steps matter for models that are sensitive to numerical scale. Without scaling, a feature measured using large numbers can dominate one measured using small numbers, even if it is no more informative. Scaling makes the magnitudes more comparable. It does not correct inaccurate measurements or remove irrelevant features.
After duplicate removal, the four observed runtimes are 2, 2, 6 and 6. The minimum is 2 and the maximum is 6. Their mean is 4, with a population standard deviation of 2.
| Runtime | Normalization calculation | Normalized value | Standardization calculation | Standardized value |
|---|---|---|---|---|
| 2 | (2 − 2) / (6 − 2) | 0 | (2 − 4) / 2 | −1 |
| 2 | (2 − 2) / (6 − 2) | 0 | (2 − 4) / 2 | −1 |
| 6 | (6 − 2) / (6 − 2) | 1 | (6 − 4) / 2 | 1 |
| 6 | (6 − 2) / (6 − 2) | 1 | (6 − 4) / 2 | 1 |
With those same scaling values, the imputed runtime of 4 becomes (4 − 2) / (6 − 2) = 0.5 after normalization, or (4 − 4) / 2 = 0 after standardization. Normalization gives a chosen range. Standardization instead expresses a value's position relative to the mean and spread, without fixing its range.
Terms to use: data cleaning, data quality, model performance, outliers, duplicate data, incorrect data, irrelevant data, improperly formatted data, imputation, deletion, predictive modelling, normalization, standardization.
A4.2.2
SELECTING INFORMATIVE FEATURES
Feature selection identifies which input attributes provide useful information for a prediction task, then retains an appropriate subset. It removes unhelpful or redundant inputs while keeping information that supports model performance.
A feature is an input attribute used by a machine learning model.
Feature selection chooses a subset of the original features judged most informative for the task. It removes whole input attributes. It doesn't change their units or replace missing entries.
Useful features help distinguish outcomes. An irrelevant feature contributes no useful information for the task; a redundant feature repeats information already available from another feature. Removing either can reduce processing and storage requirements and make the model easier to interpret. Remove a genuinely useful feature, though, and predictive performance can fall.
The greenhouse wants to predict water use. It has four complete observations with these candidate inputs:
| Record identifier | Runtime in minutes | Runtime in seconds | Recorded unit | Water use in litres: target |
|---|---|---|---|---|
| R1 | 2 | 120 | minutes | 8 |
| R2 | 2 | 120 | minutes | 10 |
| R3 | 6 | 360 | minutes | 24 |
| R4 | 6 | 360 | minutes | 26 |
Runtime in seconds repeats exactly the information in runtime in minutes. Since the recorded unit is constant, it cannot distinguish these observations. The record identifier tells us which run it is but, in this example, has no meaningful relationship with water use.
A sensible candidate subset would keep runtime in minutes and remove runtime in seconds, recorded unit and record identifier. Water use is the target to predict, not an input feature. Although the table suggests a relationship between runtime and water use, four observations alone do not establish that the resulting model will perform well on other runs.
| Strategy | How it selects features | Strength | Limitation |
|---|---|---|---|
| Filter methods | Assess feature relevance or redundancy from properties of the data, independently of training a particular predictive model. | Usually comparatively quick, so they can screen many features. | A feature that looks weak on its own may be useful in combination with another feature. |
| Wrapper methods | Train and evaluate a model with different feature subsets, then choose a subset according to its performance. | Assess how useful features are for the chosen model, including combinations. | Repeated training and evaluation can require substantial computation. |
| Embedded methods | Select features as part of the model's own training process. | Combine model fitting with feature selection, without requiring a separate search around the model. | Selection depends on the training method and may not suit a different model. |
For the greenhouse, a filter method could identify the constant recorded-unit feature and the duplicated runtime information. To compare candidate subsets, a wrapper method could train and evaluate a model for each. With an embedded method, selection would happen within training itself.
All three strategies serve the same purpose. What differs is how they judge usefulness. The most informative subset depends on the task: keeping fewer features helps only if those retained preserve the information needed for prediction.
Terms to use: feature selection, informative attributes, filter methods, wrapper methods, embedded methods.
A4.2.3
REDUCING DIMENSIONALITY
Dimensionality reduction cuts the number of input variables while keeping the information relevant to the task. It addresses difficulties that can arise when a data set has many features, especially if there are relatively few observations.
A dimension is one feature used to describe an observation. When a data set has many input features, its observations occupy a high-dimensional space.
The curse of dimensionality refers to the difficulties that arise as the number of dimensions increases. More features don't automatically provide more useful information.
Two important consequences are data sparsity and overfitting:
There are other considerations: computational complexity, the effectiveness of distance metrics, data visualization, increases in the required sample size and memory usage. Distances, for example, can become less useful for distinguishing nearby observations from distant ones. Storing and processing additional feature values also requires more resources.
Dimensionality reduction represents data with fewer variables while retaining the aspects relevant to its intended use.
One approach is feature selection, which keeps a subset of the original variables. A lower-dimensional representation may also combine information from existing variables. Fewer columns alone aren't enough: the representation must preserve useful information.
Consider two input variables from the greenhouse observations:
| Record identifier | Runtime in minutes | Runtime in seconds | Water use in litres: target |
|---|---|---|---|
| R1 | 2 | 120 | 8 |
| R2 | 2 | 120 | 10 |
| R3 | 6 | 360 | 24 |
| R4 | 6 | 360 | 26 |
Runtime in seconds is always runtime in minutes multiplied by 60. Keep only runtime in minutes, and the input falls from two dimensions to one without losing the runtime information relevant to predicting water use. The target stays unchanged.
Removing both runtime variables, by contrast, would discard the only useful input relationship shown here. The aim is to remove unnecessary dimensions without removing information the model needs.
| Potential benefit | Why it can help | What must be preserved |
|---|---|---|
| Less opportunity for overfitting | Removing irrelevant inputs leaves fewer opportunities to learn accidental patterns. | Features that carry genuine predictive information. |
| Lower processing and memory requirements | Each observation has fewer input values to store and process. | Enough detail for the intended task. |
| Easier visualization | Fewer dimensions make a representation easier to display and inspect. | Relevant relationships that might otherwise disappear from view. |
Dimensionality reduction doesn't guarantee better accuracy. Reduce too far, and important distinctions between observations can disappear. Its value depends on keeping the information the model requires, not merely making the data set smaller.
Terms to use: dimensionality reduction, variables, relevant aspects of the data, curse of dimensionality, overfitting, computational complexity, data sparsity, distance metrics, data visualization, sample size, memory usage.