Concepts / Principal Components and Variance

Principal Components and Variance

Principal components are the main directions of variance in the data, found in turn, with each one orthogonal to the others.

  • Programming

Two Features That Move Together

Imagine a dataset where each data point is described by two features, and the two features tend to rise and fall together. Knowing one of them tells you a lot about the other. That shared movement makes the data harder to describe compactly, because the two features are not independent pieces of information. Principal component analysis, usually shortened to PCA, is a method built to deal with exactly this situation.

The core idea is that PCA does not start by throwing features away. It first rotates the dataset into a new arrangement of axes in which the rotated features are statistically uncorrelated with each other. Only after that rotation does it often select a subset of the new features, ranked by how important they are for explaining the data. The two-part order matters: rotate first, then select.

What do you think happens?

If a dataset has five original features, how many principal components does PCA produce?

  • Three

  • Five

  • Ten

  • It depends on how many points there are

Reveal answer
Answer:

Five

PCA produces as many principal components as there are original features. Those components are new directions, not the original features themselves. Keeping only some of them is what reduces the number of dimensions.

Following a Correlated Point Cloud

Picture the points as a cloud drawn on the original two axes. Because the two features rise and fall together, the cloud is stretched along a tilted direction rather than sitting evenly inside the square the axes form. Each axis on its own only partly describes that tilt, so the axes are correlated.

Once the principal components are found, the data can be re-expressed so that the first principal component lines up with the horizontal axis and the second lines up with the vertical axis. The points themselves do not move relative to each other. Only the coordinate system used to describe them changes.

Feature 1original horizontal axisPC1horizontal axis afterrotationFeature 2original vertical axisPC2vertical axis afterrotationTilted point cloudfeatures covarySame points,uncorrelated axescentered at zerodescribed ondescribed ondescribed ondescribed on
How does the shape of a correlated point cloud change when the axes are rotated so the new features no longer covary?

Two things happen during this rotation. First, the data is centered around zero, because the mean was subtracted before rotating. Second, the two axes in the rotated representation are uncorrelated. In matrix language, the correlation matrix of the transformed data has zeros everywhere except along its diagonal. The diagonal entries describe each axis with itself, so the off-diagonal entries, which would measure a relationship between different axes, all vanish.

Finding Directions of Maximum Variance

PCA's first step is to look for the direction in the data that contains the most information. In plain terms, this is the direction along which the features are most correlated with each other. It is the line through the cloud of points where the points spread out the most, and it captures the largest share of what varies in the data. This first direction is the first principal component.

After finding that first direction, PCA searches for a second direction that contains the most remaining information while being orthogonal to the first, meaning at a right angle to it. In two dimensions there is only one possible perpendicular direction, so the search is trivial. In spaces with more dimensions, many directions can be orthogonal to the ones already chosen, so the choice is more open. The source describes this as potentially infinitely many orthogonal directions in higher-dimensional spaces.

Point cloudoriginal featuresPC1most spread, most variancePC2most remaining varianceFurther componentsone per original featureOrthogonal to PC1right angle constraintsearch for largest spreadconstrain next searchpick direction at right anglerepeat in turn
How does PC1 get chosen as the direction of greatest spread, and how is PC2 then forced to be perpendicular to it while capturing the next most variance?

Two properties of principal components are worth holding onto. First, principal components are orthogonal to each other, so each new direction sits at a right angle to the others. Second, the number of principal components equals the number of original features. A dataset with five features yields five principal components, even though those components are new directions rather than the original features themselves.

Keeping Only Some Components

PCA becomes a dimensionality reduction tool when you keep only some of the principal components. Suppose the data has two dimensions. You can keep the first principal component and discard the second. The result is a one-dimensional description of each point, which is a much smaller representation than the original two-dimensional one.

Points in twodimensionsPC1 and PC2 coordinatesPoints on PC1one coordinate per pointPoints mapped backoriginal feature space,only PC1 informationdiscard PC2undo rotation, add mean
What happens to the points when only the first component is kept and the second is dropped?

A reduced representation is one-dimensional, so it cannot be drawn directly in the original two-dimensional space. PCA allows you to map the reduced data back. You undo the rotation and add the mean back to the data. The resulting points are back in the original feature space, but they now carry only the information contained in the first principal component.

Worked example

Reducing a two-feature dataset to one component

A dataset has two correlated features. PCA finds two principal components. You decide to keep only the first one. What is the dimensionality of the reduced description, and what information survives the round trip back to the original space?

  1. 1
    Count the original dimensions

    There are two features, so there are two principal components, one per original feature.

  2. 2
    Keep the most informative direction

    PC1 is the direction of greatest spread. You keep it and discard PC2.

  3. 3
    Describe the reduced data

    Each point now has a single coordinate along PC1, so the reduced description is one-dimensional.

  4. 4
    Map back to the original space

    Undo the rotation and add the mean. The points return to two-dimensional feature space, but they carry only the information in PC1.

Result

The reduced description is one-dimensional. After mapping back, the points lie in the original two-dimensional space but retain only the variation captured by the first principal component.

This round trip is useful for two purposes the source describes. It can remove noise effects from the data, because the discarded directions are removed. It can also help you visualize which part of the information is retained by the principal components you kept.

Mistakes Beginners Make with Components

  • Common mistake

    Thinking PCA simply deletes features

    What it looks like

    Dropping the second principal component as if it were the second original feature.

    Why it fails

    PCA does not start by discarding features. It rotates the data first, and the kept component may run diagonally across the original axes.

    Do this instead

    Think of a kept principal component as a combination of the original features, chosen because it contains the most information.

  • Common mistake

    Assuming the rotated axes are still correlated

    Why it fails

    After rotation the axes are uncorrelated, and the correlation matrix of the transformed data has zeros off the diagonal.

    Do this instead

    Expect zero correlation between different principal component axes in the rotated representation.

  • Common mistake

    Expecting fewer principal components than features

    Why it fails

    PCA produces as many principal components as there are original features. Reduction comes from keeping only some of them, not from the number PCA produces.

  • Common mistake

    Expecting the points to move relative to each other

    Why it fails

    Only the coordinate system changes. The relative positions of the points stay the same.

  • Common mistake

    Expecting the reduced data to plot in the original space directly

    Why it fails

    A one-dimensional reduced representation cannot be drawn in two dimensions as is. It must be mapped back, and then it carries only the kept information.

Components Versus Original Features

Principal components and original features play different roles. The table below contrasts them so you can keep track of which idea applies at each step of PCA.

PropertyOriginal featuresPrincipal components
What they areMeasured properties of each pointNew directions found in the data
Correlation between axesCan be correlatedUncorrelated after rotation
Relation to each otherNot required to be perpendicularOrthogonal to one another
How manyGiven by the datasetEqual to the number of original features
Role in reductionNot selected by PCA itselfSome are kept, the rest discarded

Original features versus principal components

Checking Your Understanding

EASY

A dataset has four original features. How many principal components does PCA produce, and how do they relate to each other? If you keep only the first two, what happens to the dimensionality of the description?

Hints
  • Recall that the number of principal components equals the number of original features.
  • Consider what property the principal components have with respect to each other.
  • Keeping some components reduces the number of dimensions in the description.
MEDIUM

Explain in your own words why PCA rotates the data before selecting components, and why the kept components can be combinations of the original features.

Hints
  • Think about what the rotation makes the axes become.
  • Think about the direction of greatest spread and what it means for the original axes.

Key Takeaways

  • PCA rotates a dataset so that the rotated features are statistically uncorrelated, and it often selects a subset of the new features afterward.
  • Principal components are found in turn as directions of maximum remaining variance, with each one orthogonal to the others.
  • PCA produces as many principal components as there are original features, and keeping only some of them reduces the number of dimensions.
  • Mapping reduced data back to the original space undoes the rotation and retains only the information in the kept components, which can help reduce noise and visualize what is retained.

Related concepts

More concepts starting with P