Representation Learning

Dimensionality Reduction Explained

Learn why dimensionality reduction matters, how PCA, t-SNE and UMAP compress many features into fewer, and when to use each technique.

On this page
  1. Why too many dimensions cause trouble
  2. Two broad strategies
  3. Principal component analysis
  4. t-SNE
  5. UMAP
  6. Autoencoders
  7. Choosing a method
  8. Practical cautions
  9. Frequently Asked Questions

Real datasets are often wide. A single record might have dozens, hundreds or thousands of features. Humans can only picture two or three dimensions, and many algorithms struggle as the number of features grows. Dimensionality reduction is the set of techniques for squeezing high-dimensional data into fewer dimensions while keeping what matters.

Done well, it makes data easier to see, faster to process and sometimes easier to model. Done carelessly, it can throw away exactly the signal you needed.

Why too many dimensions cause trouble

As the number of features grows, strange things happen. Data points spread out across an enormous space, and any given region contains very few of them. Distances between points start to look alike, which weakens methods that depend on measuring closeness. This family of problems is often called the curse of dimensionality.

Other practical issues follow:

  • More features mean more computation and memory.
  • Models with many inputs have more room to overfit, especially with limited data.
  • Many features are redundant. Height in centimeters and height in inches carry the same information twice.
  • Visualization becomes impossible beyond three dimensions.

Two broad strategies

There are two main ways to reduce dimensions.

Feature selection keeps a subset of the original features and drops the rest. The features you keep are unchanged, so the result stays easy to interpret.

Feature extraction builds new features by combining the originals. The new features are fewer in number but are mixtures of the old ones, so they are harder to name. The methods below are mostly of this second kind.

Principal component analysis

Principal component analysis, or PCA, is the classic technique. It finds new axes, called principal components, along which the data varies the most. The first component points in the direction of greatest spread, the second captures the most remaining spread at a right angle to the first, and so on.

You then keep only the first few components. Because they capture most of the variation, you lose relatively little information while cutting many dimensions.

from sklearn.decomposition import PCA

pca = PCA(n_components=2)
reduced = pca.fit_transform(X)
print(pca.explained_variance_ratio_)

The explained_variance_ratio_ output shows how much of the original variation each component preserves, which helps you decide how many to keep.

PCA is fast, deterministic and well understood. Its limit is that it is linear. It can only rotate and project the data, so it misses curved or tangled structure. It is also sensitive to feature scale, so standardizing features first is normal practice.

t-SNE

t-SNE is built for visualization. It maps high-dimensional points to two or three dimensions in a way that tries to keep neighbors close. Points that were near each other in the original space tend to stay near each other on the plot, which often reveals clusters beautifully.

Use it with care. The distances between far-apart clusters on a t-SNE plot are not reliable, and cluster sizes can be misleading. Results depend on a setting called perplexity, and different runs can look different. It is excellent for exploration but is not meant to produce features for downstream models.

UMAP

UMAP is a more recent method with a similar purpose. It also preserves local neighborhood structure, but it is usually faster than t-SNE on large datasets and tends to keep more of the global layout. It can also be used to transform new data after it has been fitted, which t-SNE does not do naturally.

Like t-SNE, UMAP has tuning settings that change the picture, so conclusions drawn from a single plot should be checked, not trusted blindly.

Autoencoders

A neural approach uses an autoencoder. It has an encoder that compresses the input into a small vector, and a decoder that tries to rebuild the original from that vector. Training minimizes the rebuilding error. The small middle layer is then a learned, non-linear low-dimensional representation. Autoencoders can capture patterns PCA cannot, at the cost of more tuning and compute.

Choosing a method

A practical guide:

  1. Need a quick, interpretable baseline or preprocessing step? Try PCA.
  2. Need a two-dimensional picture of clusters? Try UMAP or t-SNE.
  3. Have complex, non-linear data and enough examples? Consider an autoencoder.
  4. Need to keep features understandable to stakeholders? Prefer feature selection.

Practical cautions

Always fit the reduction on training data only, then apply it to validation and test data. Fitting on everything leaks information. Scale features before using methods that depend on variance or distance. Check what you lost: compare model performance with and without the reduction, rather than assuming it helped.

Also remember that reduced axes rarely have a plain meaning. If someone asks "what does component 2 represent," the honest answer is usually a weighted mix of several original features.

Frequently Asked Questions

Does dimensionality reduction always improve model accuracy?

No. It can help by removing noise and redundancy, but it can also discard useful signal. The only reliable way to know is to compare results with and without it on held-out data.

What is the difference between PCA and t-SNE?

PCA is a linear method that preserves overall variance and gives reusable, fast projections. t-SNE is a non-linear method focused on preserving local neighborhoods for visualization, and it is not meant for producing general-purpose features.

How many components should I keep?

A common approach is to keep enough components to explain a chosen share of the variance, then check model performance. For plotting, you simply use two or three. The right number depends on your goal.