Choosing how many principal components to retain

← Back to Blog & Articles

The fraction of total variance explained by the first k components is Σ_{i≤k} λ_i / Σ_{all i} λ_i.

A common heuristic is to keep enough components to explain 90-95% of total variance, or to look for an "elbow" in the sorted eigenvalue (scree) plot where additional components contribute diminishing returns.

t-SNE

PCA is a linear projection and can fail to reveal cluster structure that only separates along nonlinear manifolds. t-distributed Stochastic Neighbor Embedding (t-SNE) instead directly optimizes a low-dimensional (typically 2D) embedding so that pairwise similarities in the embedding match pairwise similarities in the original space, where similarity in the high-dimensional space is modeled as a Gaussian centered at each point (with per-point bandwidth chosen so a target "perplexity" — effectively, an expected number of close neighbors — is met) and similarity in the low-dimensional embedding is modeled with a heavier-tailed Student-t distribution, whose fatter tails counteract the "crowding problem" (in low dimensions there is comparatively less room for many equidistant points, so a heavier-tailed distribution is needed to represent moderate dissimilarities without artificially compressing everything together). The embedding is fit by minimizing the KL divergence between the high- and low-dimensional similarity distributions via gradient descent. t-SNE excels at revealing cluster structure visually but its axes and inter-cluster distances are not meaningful (unlike PCA's, which directly correspond to variance), and results can be sensitive to the perplexity hyperparameter.

Continue with the book

Explore the full treatment, worked examples, and exercises in The AI Algorithms Compendium.


Companion article for The AI Algorithms Compendium, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top