🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Dimensionality Reduction — PCA, t-SNE, UMAP Complete Guide

Core MLDimensionality Reduction🟢 Free Lesson

Prerequisites

Before diving into Dimensionality Reduction, you should be familiar with:

  • Linear Algebra — vectors, matrices, eigenvectors, eigenvalues
  • Basic Statistics — variance, covariance, correlation
  • Python & NumPy — matrix operations, array manipulation
  • Scikit-learn basics — train_test_split, basic model training

Learning Objectives

By the end of this tutorial, you will be able to:

  1. Explain the curse of dimensionality and why dimensionality reduction matters
  2. Implement PCA for linear dimensionality reduction and understand explained variance
  3. Use t-SNE for intuitive 2D/3D visualization of high-dimensional data
  4. Apply UMAP as a faster alternative to t-SNE with better global structure preservation
  5. Compare PCA, t-SNE, UMAP, and LDA for different use cases
  6. Determine the optimal number of components to retain
  7. Apply dimensionality reduction as a preprocessing step for ML models

Unsupervised Learning

Curse of Dimensionality — When More Features Hurt, Not Help

Dimensionality reduction compresses high-dimensional data into fewer dimensions while preserving the most important structure and variance.

  • PCA — finds orthogonal axes of maximum variance for fast, linear dimensionality reduction
  • t-SNE — preserves local neighborhoods for intuitive 2D and 3D visualization
  • UMAP — faster than t-SNE with better global structure preservation

"Not everything that can be counted counts, and not everything that counts can be counted."

Dimensionality Reduction — Complete Guide

Dimensionality reduction compresses high-dimensional data into fewer dimensions while preserving important information.


Why Reduce Dimensions?

Curse of Dimensionality Visualization

Curse of Dimensionality — Data Sparsity2D SpaceN=10 fills space5D SpaceSame N, sparser10D SpaceSame N, very sparseVolume grows exponentially — distance metrics become meaningless
Curse of DimensionalityBenefits of Reduction
More dimensions = more data neededFaster training
Distances become meaninglessLess overfitting
Models overfitBetter visualization (2D/3D)
Training becomes slowRemoves noise, simpler model

Mathematical Worked Example


PCA (Principal Component Analysis)

PCA Projection Diagram

PCA: Finding Principal ComponentsOriginal 2D DataPC1 (max variance)PC2Projected onto PC11D representation preservingmaximum varianceExplained variance: PC1=72%, PC2=15%
StepDescription
1. Standardize dataZero mean, unit variance
2. Compute covariance matrixC = (1/(n-1)) X^T X
3. Find eigenvectorsPrincipal components (PC1, PC2, ...)
4. Project onto top KReduce dimensionality
ComponentVariance ExplainedAction
PC172%Keep
PC215%Keep
PC38%Keep
PC45%Can drop

PCA Mathematics

The covariance matrix:

Eigendecomposition:

Explained variance ratio:

Mathematical Worked Examples

python
from sklearn.decomposition import PCA

pca = PCA(n_components=2)
X_2d = pca.fit_transform(X)

print(f"Explained variance: {pca.explained_variance_ratio_}")
# [0.72, 0.15] — first 2 components explain 87% of variance

t-SNE

t-SNE Visualization

t-SNE: Preserving Local NeighborhoodsHigh-Dimensional SpaceSimilar points are close in high-D2D EmbeddingClusters preserved in 2D
AspectDetails
Best forVisualization (2D/3D)
Not forFeature reduction for training
How it works1. Compute similarities in high-D (Gaussian) → 2. Compute similarities in low-D (Student-t) → 3. Minimize KL divergence
perplexityNumber of neighbors (5-50)
learning_rateStep size (10-1000)
n_iterNumber of iterations (1000+)

Mathematical Worked Example


UMAP

UMAP vs t-SNE Comparison

UMAP vs t-SNE: Key Differencest-SNE* Preserves local structure only* Cannot transform new data* O(n^2) complexity* Non-parametric* Good for visualization only* Cluster sizes may distortUMAP* Preserves local AND global* Can transform new data* O(n) complexity (faster)* Parametric variant available* Good for visualization + ML* Better cluster preservation
AdvantageDetails
Speed10x faster than t-SNE
Global structureBetter preserves global structure
TransformCan transform new data
ClusteringBetter for clustering
python
import umap

reducer = umap.UMAP(n_components=2, n_neighbors=15)
X_2d = reducer.fit_transform(X)

Mathematical Worked Example


Comparison

MethodSpeedLocalGlobalTransform
PCAFastNoYesYes
t-SNESlowYesNoNo
UMAPMediumYesYesYes
LDAFastNoNoYes

When to Use Each Method


Real-World Applications

1. Image Processing — Face Recognition (Eigenfaces)

  • PCA reduces 100x100 pixel face images from 10,000 dimensions to ~100 principal components
  • These "eigenfaces" capture the most variance in facial structure
  • Impact: 99%+ accuracy on face recognition with 100x dimensionality reduction

2. Genomics — Single-Cell RNA Sequencing

  • UMAP/t-SNE visualizes thousands of gene expression values per cell in 2D
  • Identifies cell types, states, and developmental trajectories
  • Impact: Enabled discovery of rare cell types invisible in high-D analysis

3. Natural Language Processing — Word Embeddings Visualization

  • t-SNE/UMAP projects 300-dimensional Word2Vec embeddings to 2D
  • Reveals semantic relationships: king-queen, Paris-France clusters
  • Impact: Intuitive visualization of learned language representations

4. Financial Analysis — Portfolio Risk Visualization

  • PCA identifies dominant risk factors from hundreds of asset returns
  • First 3 components often capture 80%+ of market variance
  • Impact: Simplified risk management and factor-based portfolio construction

5. Healthcare — Patient Stratification

  • UMAP clusters patients by clinical features and biomarkers
  • Identifies disease subtypes and treatment response groups
  • Impact: Enabled personalized treatment plans for cancer patients

6. Manufacturing — Defect Detection

  • PCA reduces sensor data dimensions for anomaly detection
  • Reconstruction error in reduced space flags unusual patterns
  • Impact: 15% improvement in early defect detection rates

Common Mistakes and How to Avoid Them


Interview Questions


Practice Exercise


Comparison Table

MethodSpeedNonlinearTransform NewSupervisedBest For
PCAVery FastNoYesNoPreprocessing, linear data
t-SNESlowYesNoNoVisualization only
UMAPFastYesYesNoVisualization + ML
LDAFastNoYesYesClassification preprocessing
AutoencoderSlow (GPU)YesYesNoComplex nonlinear patterns

Key Formulas Reference

Essential Formulas for Dimensionality Reduction

Covariance Matrix:
Eigendecomposition:
Explained Variance Ratio:
PCA Projection:
KL Divergence (t-SNE):

Key Takeaways


Further Reading

  • "Pattern Recognition and Machine Learning" by Christopher Bishop — Chapter 12 on PCA and kernels
  • "An Introduction to Statistical Learning" by James et al. — Chapter 6 on dimension reduction
  • UMAP documentation — umap-learn.readthedocs.io
  • scikit-learn documentation — Decomposition and Manifold modules
  • "Visualizing Data using t-SNE" by van der Maaten and Hinton — the original t-SNE paper
  • "Understanding Manifold Learning" — excellent blog posts on the mathematics

What to Learn Next

-> Autoencoders Learn the neural network approach to nonlinear dimensionality reduction and representation learning.

-> Clustering Group similar data points using K-Means, DBSCAN, and hierarchical methods.

-> Feature Engineering Create and transform features to improve model performance before dimensionality reduction.

-> Model Evaluation Evaluate whether dimensionality reduction improved or hurt your model's predictive power.

-> Neural Networks Understand the deep learning foundations that autoencoders are built upon.

-> CNNs Apply convolutional architectures to image data where spatial dimensionality matters.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-07

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Machine Learning Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement