A4.2.3 · Data preprocessing (HL only)
The Importance of Dimensionality Reduction
It's tempting to think a model given more information will always make better predictions. Past a certain point, the opposite happens: extra features actively make a model worse, a genuine problem with a name of its own.
Explainer
Each feature a model is given adds another dimension to the space it's trying to find patterns in. The curse of dimensionality describes the range of genuine problems that show up once a data set has too many dimensions relative to how much data it actually contains.
A school wants to build a model that flags which students are at risk of falling behind, starting with three sensible features: attendance rate, average grade, and number of missed assignments. Someone suggests adding fifty more, locker number, favourite lunch item, hair colour, bus route, in the hope that more detail means a better model. It's the opposite: this is exactly the scenario each problem below plays out against.
Worked example
Seven ways more dimensions hurts
Click each one to see exactly how it shows up once the school's model balloons from 3 features to over 50.
Explainer
Reducing dimensions, keeping what matters
Dimensionality reduction means reducing the number of variables in a data set while preserving the relevant aspects of the data, cutting the trivial 50-feature version back down toward something closer to the original three that actually mattered, without throwing away genuinely useful signal in the process.
Deciding which dimensions to cut can be done manually, using judgement about what's actually likely to matter, or with statistical tools built for exactly this. Two such tools you may see named, principal component analysis (PCA) and linear discriminant analysis (LDA), are beyond the scope of this course, you're not expected to know how either one works, only that dimensionality reduction as a goal exists and why it matters.
Worked example
Reducing dimensions with scikit-learn
You're not expected to know the maths behind a tool like this, only that it exists and roughly what it does: take a data set with a large number of columns and compress it down to a much smaller number of new columns that still capture most of what mattered in the original. This uses scikit-learn, a real, widely used Python library for exactly this kind of task.
import numpy as np from sklearn.decomposition import PCA # A simplified version of the school's data set: 5 students, 6 already-scaled features students = np.array([ [0.92, 0.20, 0.10, 0.30, 0.88, 0.40], [0.61, 0.85, 0.40, 0.10, 0.55, 0.20], [0.78, 0.45, 0.20, 0.20, 0.70, 0.30], [0.45, 0.95, 0.60, 0.05, 0.40, 0.10], [0.88, 0.25, 0.10, 0.30, 0.82, 0.40], ]) print("Original shape:", students.shape) pca = PCA(n_components=2) reduced = pca.fit_transform(students) print("Reduced shape:", reduced.shape) print(np.round(reduced, 2))
Running this prints Original shape: (5, 6) then Reduced shape: (5, 2): six columns per student compressed down to two, chosen by the algorithm to preserve as much of the meaningful variation between students as it can. This isn't wired into this page's own in-browser console: scikit-learn needs roughly 80 MB of supporting libraries to run, far too much to download just for one page, so try this one in your own Python setup instead (pip install scikit-learn numpy).
Check your understanding
After being trained on the school's 50-feature version of the data set, the model correctly flags every at-risk student it was trained on, but performs poorly on the following year's new students. Which problem is this?
Common mistake
RecurringA genuinely documented pattern: candidates assume dimensionality reduction automatically makes a model better, treating "fewer dimensions" as an unconditional improvement. It isn't. The actual goal is simplifying the data while keeping what's genuinely useful in it, and cutting the wrong dimension can throw away information the model actually needed, making it worse, not better.
Treats it as an automatic improvement: "Reducing the number of features will make the model more accurate." States a possible outcome as if it were guaranteed, when a badly chosen reduction can remove a feature the model genuinely relied on.
States the actual trade-off: "Reducing the number of features can simplify the model and reduce overfitting, but only if the removed features weren't actually informative; cutting a genuinely useful feature would make predictions worse, not better." Correctly frames it as a balance to strike, not a guaranteed win.
Revision questions
Past-paper style. Write an answer, then reveal the marking points and mark yourself.
[2]Define the term curse of dimensionality.
Marking points
评分要点
- The curse of dimensionality is the effect that as the number of features grows, the volume of the data space grows exponentially.
- This makes the available data points sparse and the distances between them less meaningful, which weakens many models.
- 维度灾难是指随着特征数量增加,数据空间的体积呈指数增长这一效应。
- 这使得可用的数据点变得稀疏,点之间的距离意义减弱,从而削弱许多模型。
[4]Explain how adding more dimensions to a data set affects data sparsity, and why that matters for a model's predictions.
Marking points
评分要点
- Each extra dimension multiplies the size of the space the data must cover, but the number of data points stays the same.
- So the same points spread ever more thinly and most of the space contains no data at all: the data becomes sparse.
- Models generalise by relying on nearby examples; when every point is far from every other, there is no reliable local evidence, so predictions for new points become unreliable.
- The model also has more freedom to fit noise, so it overfits.
- 每增加一个维度,数据必须覆盖的空间就成倍增大,但数据点的数量不变。
- 于是同样的点越铺越稀,空间的大部分根本没有数据:数据变得稀疏。
- 模型通过依赖邻近样例来泛化;当每个点都远离其他所有点时,就没有可靠的局部证据,于是对新点的预测变得不可靠。
- 模型还有更多自由去拟合噪声,所以会过拟合。
[6]A hospital's patient-readmission model has grown from 5 features to 80. Describe three specific problems this growth could cause, referring to the curse of dimensionality.
Marking points
评分要点
- Sparsity: with 80 features the patient records spread thinly across a vast space, so few patients are genuinely similar and nearest-neighbour style reasoning breaks down.
- Overfitting: the model has many more parameters and ways to fit noise in the training patients that will not repeat, so validation accuracy drops.
- Cost and data need: training is slower, storage larger, and far more patient records are needed to populate an 80-dimensional space adequately.
- Many of the 75 added features are likely irrelevant or redundant, adding noise rather than signal.
- The fix is dimensionality reduction or feature selection to bring the count back down while keeping the informative features.
- 稀疏性:有 80 个特征时,病人记录稀薄地散布在巨大的空间中,真正相似的病人很少,近邻式推理失效。
- 过拟合:模型有多得多的参数和方式去拟合训练病人中不会重现的噪声,所以验证准确率下降。
- 代价与数据需求:训练更慢、存储更大,而且需要多得多的病人记录才能充分填充一个 80 维空间。
- 新增的 75 个特征中许多很可能无关或冗余,增加的是噪声而非信号。
- 解决办法是降维或特征选择,把数量降回来同时保留有信息量的特征。
Flashcards
Active recall for this statement’s key terms.
Keep this statement’s practice with you
Free account: unlock every revision question and flashcard for A4.2.3, and every other IB CS 2027 statement.