Computing Library › Machine Learning
Machine Learning

t-SNE

t-SNE is a nonlinear method that maps high-dimensional data to 2-D or 3-D, preserving local neighborhoods for visualization.

Visualizing neighborhoods

t-distributed stochastic neighbor embedding (t-SNE) is a nonlinear technique built for visualization. It converts pairwise distances into probabilities of being neighbors, then arranges points in 2-D or 3-D so that the low-dimensional neighbor probabilities match the high-dimensional ones as closely as possible.

How it works

Kronos motion — lego machine

The heavy tail is the key trick: it lets distant points spread out, so clusters separate cleanly instead of collapsing into a crowded blob.

Reading t-SNE plots carefully

t-SNE faithfully preserves local structure but distorts global structure. Cluster sizes and the distances between clusters in a t-SNE plot are not meaningful; only which points sit together is reliable. Different perplexity values and random seeds produce different layouts, so never over-interpret a single run.

python
from sklearn.manifold import TSNE
Z = TSNE(n_components=2, perplexity=30, init='pca').fit_transform(X)

When to use it

Use t-SNE to inspect whether classes or clusters separate, not as input to a downstream model, and not to measure distances. It is slow on large datasets; run PCA first to a few dozen dimensions to speed it up. For a faster method that better preserves global layout, prefer UMAP.