Machine Learning, FoundationsLesson 66 of 92

Module 7 · Learning without labels, and learning a representation

PCA: fewer columns, and what you gave up

In this lesson

  • 9 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 4 of 10 in this chapter

This chapter’s goalCluster a dataset and defend the number of clusters with more than an elbow plot, reduce dimensionality with PCA and state how much information the reduction discarded, explain what an embedding is as a geometric object, and build a working nearest-neighbour search over pretrained embeddings without a GPU.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:55Not available
Full audiobookNot availableNot available
Cumulative variance explained, two 100-column tables00.5011100Components keptCumulative variance explained—— Highly redundant features– – Largely independent featuresThe redundant table reaches 95 per cent of its variance with 20 components; the independent one needsnearly all hundred, and PCA buys almost nothing. The axis is variance, not usefulness. The target wasnever consulted, and the signal you need can sit in a component this curve tells you to discard.
The redundant table reaches 95 per cent of its variance with 20 components; the independent one needs nearly all hundred, and PCA buys almost nothing. The axis is variance, not usefulness. The target was never consulted, and the signal you need can sit in a component this curve tells you to discard.

Figure

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

The idea

Find the direction in which the data varies most. Call it the first principal component. Then find the direction of greatest remaining variation that is perpendicular to the first. Repeat.

The result is a new set of axes, ordered by how much of the data’s variance each one carries. Keep the first few and you have compressed many columns into a few while losing as little variance as possible.

Python
from sklearn.decomposition import PCA
p = PCA(n_components=0.95).fit(X_scaled)     # keep 95% of variance
p.n_components_                               # how many that took
p.explained_variance_ratio_[:5]

Passing a float between 0 and 1 lets PCA choose the number of components for you, which is usually what you want. “38 components retain 95% of the variance” is a more useful statement than “we kept 10”.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the How a Language Model Actually Works exam.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘PCA: fewer columns, and what you gave up’, in Machine Learning, Foundations. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/machine-learning-foundations/principal-components (Accessed: 29 November 2026).