- Introduced by
- van der Maaten, L. & Hinton, G.
- Year
- 2008
- Type
- Nonlinear dimensionality reduction (manifold visualization)
What does it do?
t-SNE (t-Distributed Stochastic Neighbor Embedding) is a nonlinear dimensionality-reduction method introduced by Laurens van der Maaten and Geoffrey Hinton in 2008 that maps high-dimensional data into a 2D or 3D space for visualization.
It preserves probabilistic local similarities, so points that are neighbours in the original space stay close together, revealing cluster structure and local neighbourhoods.
The intuition behind the method
When data lives in dozens or hundreds of dimensions, we cannot see it directly. t-SNE asks a simpler question for every pair of points: how likely is one to be picked as a neighbour of the other? It then arranges a 2D or 3D picture so that those neighbour probabilities are reproduced as faithfully as possible. The result is a map where tightly related observations gather into visible clumps, letting the eye spot groups that are invisible in the raw high-dimensional table.
History
Laurens van der Maaten and Geoffrey Hinton introduced t-SNE in 2008 in the Journal of Machine Learning Research (volume 9). It builds on the earlier Stochastic Neighbor Embedding, replacing its Gaussian kernel in the low-dimensional space with a heavy-tailed Student-t distribution to address the crowding problem. It remains a common reference point for exploratory visualization of high-dimensional data.
When to use it
Choose t-SNE to explore the local neighbourhood and cluster structure of high-dimensional continuous data, such as embeddings, gene-expression profiles or image features, shown in two or three dimensions, on a sample large enough that the groupings can be checked for stability. Do not use it to estimate distances, cluster sizes or densities, or to test hypotheses about group differences, because the map is an exploratory picture. Consider standardizing the features first, because the high-dimensional similarities are computed from distances between the raw features, and variables with large numeric ranges can dominate those distances. Because the output depends on perplexity and on the random start, compare several perplexity values and several runs before treating any grouping as real. t-SNE has no direct mapping for new observations, so it suits fixed datasets; if new points must later be placed on the same map, each addition generally requires re-running the embedding on the combined data. For very large datasets the optimization becomes slow, and a faster nonlinear method may be more practical.
Limitations and considerations
- The output is a visualization: distances between points and the sizes of clusters on the map do not quantitatively reflect the original data, so no statistical inference should be drawn from them.
- The optimization is computationally demanding on large datasets, so for big data it is slower than alternatives such as UMAP.
- Results are stochastic and depend on perplexity, so different runs or settings can produce visibly different maps.
- With small samples the embedding can be unstable and hard to reproduce, so groupings should be checked across perplexities and random starts.
- t-SNE has no direct way to embed new, out-of-sample points; each new observation generally requires re-running the embedding on the combined data. Autoencoders are often cited as easier to generalize in this respect, because their encoder can map new points directly.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Reveals local cluster structure and neighbourhoods that linear projections such as PCA can miss.
- Nonlinear, so it can follow curved manifold structure rather than only linear directions of maximum variance.
- The 2D or 3D output can be inspected directly, making groupings in high-dimensional data visible at a glance.
- The heavy-tailed Student-t kernel in the low-dimensional space lets dissimilar points separate, which reduces crowding of clusters in the centre of the map.
Applications
- Visualizing high-dimensional embeddings and learned feature spaces in 2D or 3D.
- Exploring cluster structure in single-cell or gene-expression data.
- Inspecting image or text feature representations from deep models.
- Exploratory neighbourhood analysis before quantitative clustering or classification.
How it works
How it works
For each pair of points in the original high-dimensional space, t-SNE converts their distance into a conditional probability that one would choose the other as a neighbour, using a Gaussian kernel. The kernel width is set separately for each point so that the effective number of neighbours matches the chosen perplexity (typically 5–50). Perplexity therefore controls the balance between local and broader structure.
Formula
p_{j|i} = \frac{\exp(-\lVert x_i - x_j \rVert^2 / 2\sigma_i^2)}{\sum_{k \neq i}\exp(-\lVert x_i - x_k \rVert^2 / 2\sigma_i^2)}Each point gets a position in the low-dimensional map, and pairwise similarities there are measured with a Student-t kernel with one degree of freedom, as in the formula, rather than a Gaussian. Its heavy tails let moderately distant points sit further apart, which prevents clusters from being crushed into the centre of the map. This is the remedy for the crowding problem that the earlier Stochastic Neighbor Embedding suffered from.
Formula
q_{ij} = \frac{(1 + \lVert y_i - y_j \rVert^2)^{-1}}{\sum_{k \neq l}(1 + \lVert y_k - y_l \rVert^2)^{-1}}t-SNE moves the low-dimensional points by gradient descent to minimize the Kullback–Leibler divergence between the high-dimensional neighbour probabilities and the low-dimensional similarities defined above. As this cost decreases, the neighbourhood structure of the map is pushed to match that of the original data, producing the final layout. Because the optimization starts from a random configuration, different runs can end in different layouts.
Formula
C = \mathrm{KL}(P \,\Vert\, Q) = \sum_{i \neq j} p_{ij} \log \frac{p_{ij}}{q_{ij}}Common pitfalls
- Reading the size of a cluster or the gap between two clusters as a measured quantity.
- Running the embedding on unstandardized features, where variables with large numeric ranges can dominate the Euclidean distances that define the neighbour probabilities.
- Relying on a single perplexity value; the visible grouping can change with that choice.
- Treating one run as the result, even though the optimization is stochastic and repeated runs can differ.
- Applying it to very small samples, where the map can be unstable; check stability across perplexities and random starts before interpreting groups.
Frequently asked questions
What does perplexity control?
Perplexity sets the effective number of neighbours each point considers, balancing attention between local and broader structure. Typical values lie in the 5–50 range. Try several values and check whether the visible grouping stays the same.
Can I read cluster sizes and distances from a t-SNE plot?
No. t-SNE preserves local neighbourhoods but not global geometry, so the size of a cluster and the gaps between clusters are not quantitatively meaningful. Use the plot to spot grouping, not to measure it.
How is t-SNE different from PCA?
PCA is a linear projection onto directions of maximum variance and preserves global structure, while t-SNE is a nonlinear method that preserves local neighbourhoods and excels at revealing clusters. They are complementary; PCA is often used as a preprocessing step before t-SNE.
Should I use t-SNE or UMAP?
Both are nonlinear visualization methods. t-SNE is a long-standing reference for local structure. UMAP is often faster on large datasets and tends to keep more global structure, so it can be the more practical choice when data volume is high.
Can I add new data points to an existing t-SNE map?
Not directly. t-SNE does not learn a mapping that can be applied to unseen points, so new observations generally require re-running the embedding on the combined data, and the layout may change. Parametric alternatives such as autoencoders can pass new points through their encoder directly.
Related methods
Sources
van der Maaten, L. & Hinton, G. (2008). Visualizing Data using t-SNE. Journal of Machine Learning Research, 9(86), 2579–2605.
Open publication reference2018_Book_NeuralNetworksAndDeepLearning, p. ?