Dimensionality Reduction: PCA, t-SNE, and UMAP
Learn how to reduce high-dimensional data with PCA, t-SNE, and UMAP. Understand when to use each method, how to interpret results, and avoid common pitfalls.
Dimensionality Reduction: PCA, t-SNE, and UMAP
Dimensionality reduction transforms high-dimensional data into fewer dimensions while preserving as much structure as possible. It is essential for visualization, speeding up ML, and reducing noise.
---
What Is Dimensionality Reduction and Why?
High-dimensional data (many features) causes several problems:
- Curse of dimensionality: Distances become less meaningful; density estimates break down.
- Visualization: We can only plot 2D or 3D; 100+ dimensions are impossible to visualize directly.
- Overfitting: More features than samples increase overfitting risk.
- Computation: Many algorithms scale poorly with dimension.
---
The Curse of Dimensionality
As dimensions increase:
- Data points become sparse — the "volume" grows exponentially.
- Distance ratios converge — nearest and farthest points become similar in distance.
- Clustering and density estimation become unreliable.
---
PCA (Principal Component Analysis)
How It Works: Variance Maximization
PCA finds linear combinations of features (principal components) that capture the most variance. The first PC has the highest variance, the second (orthogonal to the first) has the next highest, and so on.
Choosing the Number of Components
- Scree plot: Plot explained variance vs component number. Look for the "elbow" where adding components adds little.
- Cumulative variance: Retain enough components to reach 90–95% cumulative explained variance.
- Task: For visualization, use 2–3. For ML features, use enough to retain most variance without overfitting.
Interpreting Loadings
Loadings show how much each original feature contributes to each component. High absolute loading = strong influence. Use loadings to name and interpret components.
Scree Plot
A scree plot displays eigenvalue or explained variance per component. The steep drop and subsequent flattening suggest a natural number of components.
| Approach | When to Use |
|---|---|
| Retain 90–95% variance | General-purpose feature reduction |
| Elbow in scree plot | When clear elbow exists |
| Fixed 2–3 components | Visualization only |
| Cross-validation | When using reduced features for ML |
t-SNE (t-Distributed Stochastic Neighbor Embedding)
How It Works: Neighbor Preservation
t-SNE models pairwise similarities in high dimensions and minimizes the mismatch with a low-dimensional embedding. It emphasizes keeping nearby points close.
Perplexity Parameter
- Perplexity (typically 5–50): Approximate number of neighbors considered. Low = focus on local structure. High = consider more global structure.
- Rule of thumb: 5–50; often 30 works well. Smaller datasets need lower perplexity (< sample count / 3).
Only for Visualization — NOT for ML Features
Critical: t-SNE is non-linear and stochastic. Different runs give different layouts. Do not use t-SNE components as features for downstream ML — distances and coordinates are not meaningful in the same way as PCA.
Use t-SNE solely for 2D/3D visualization of high-dimensional data.
---
UMAP (Uniform Manifold Approximation and Projection)
Similar to t-SNE but Faster, Preserves Global Structure Better
UMAP builds a weighted graph of neighbors and optimizes a low-dimensional layout that preserves this structure. It is often faster than t-SNE and preserves global structure better.
nneighbors and mindist Parameters
- nneighbors (default 15): Local neighborhood size. Low = local structure; high = global structure. Range typically 2–200.
- mindist (default 0.1): Minimum distance between points in the embedding. Low = tighter clusters; high = more spread. Range 0.0–0.99.
| Parameter | Low | High |
|---|---|---|
| nneighbors | More local, fragmented | More global, smoother |
| mindist | Tighter clusters | More spread-out |
Comparison: PCA vs t-SNE vs UMAP
| Aspect | PCA | t-SNE | UMAP |
|---|---|---|---|
| Type | Linear | Non-linear | Non-linear |
| Speed | Fast | Slow | Faster than t-SNE |
| Global structure | Preserves (linear) | Emphasizes local | Preserves local and global |
| Deterministic | Yes | No (random init) | Mostly (can fix seed) |
| Use for ML features | Yes | No | Use with caution |
| Use for visualization | Yes (linear) | Yes | Yes |
| Scalability | High | Medium | High |
When to Use Each
| Scenario | Recommendation |
|---|---|
| Reduce features for ML | PCA (or other linear methods) |
| Visualize clusters in 2D | t-SNE or UMAP |
| Large datasets | PCA or UMAP |
| Need interpretable components | PCA |
| Preserve local neighborhoods | t-SNE or UMAP |
| Preserve global structure | PCA or UMAP |
Feature Selection vs Feature Extraction
| Approach | What It Does | Example |
|---|---|---|
| Feature selection | Keeps a subset of original features | Correlation filter, LASSO |
| Feature extraction | Creates new features from combinations | PCA, autoencoders |
---
Using Dimensionality Reduction in the Platform
- Before clustering: Reduce with PCA to speed up and denoise; then cluster on PCA components.
- For visualization: Use t-SNE or UMAP to create 2D/3D scatter plots.
- For ML: Use PCA components as input features when you have many correlated features.
- Always scale features before PCA, t-SNE, or UMAP.
Interpreting Results
- PCA: Inspect loadings to name components; use scree plot to choose K.
- t-SNE/UMAP: Clusters in the plot suggest groupings; distances are approximate. Colors by labels to validate.
- Variance explained: For PCA, report cumulative variance for chosen components.
Common Pitfalls
| Pitfall | Solution |
|---|---|
| Using t-SNE/UMAP outputs as ML features | Use PCA or raw features for ML |
| Forgetting to scale | Always standardize before PCA |
| Over-interpreting t-SNE distances | Only relative proximity matters |
| Too low perplexity (t-SNE) | Use 5–50; avoid below ~5 |
| Ignoring stochasticity | Run t-SNE multiple times; fix seed for reproducibility |
Quick Reference
| Method | Best For | Key Parameters |
|---|---|---|
| PCA | ML features, fast viz, interpretability | ncomponents, scale |
| t-SNE | 2D visualization, local structure | perplexity 5–50 |
| UMAP | 2D/3D viz, global + local, scalability | nneighbors, min_dist |
What's Next?
- [Features Overview](/analytics/user-manuals/adv-all/features-overview) — Feature engineering basics
- [Clustering Overview](/analytics/user-manuals/adv-all/clustering-overview) — Cluster after reducing dimensions
- [ML Overview](/analytics/user-manuals/ml-basics/ml-overview) — Using reduced features in models
- [Visualization Overview](/analytics/user-manuals/viz-charts/viz-overview) — Visualizing embeddings
Related Articles
Feature Engineering and Feature Store
Create powerful new features from your data and manage them in a central catalog for reuse across projects.
Clustering Analysis
Group similar data points together using K-Means, DBSCAN, Hierarchical, and other clustering algorithms.
Machine Learning Overview: Workflow and Getting Started
A beginner-friendly recap of ML, classification vs regression vs clustering, the ML workflow (select, configure, train, evaluate, predict), and a 5-minute quick-start guide.
Visualization Overview: Charts, Types, and When to Use Them
Why visualize data, all chart types with "when to use" guidance, chart configuration, exporting, and a decision table for choosing the right chart.
Was this helpful?