t-SNE (t-distributed stochastic neighbor embedding) is a nonlinear dimensionality reduction method that places high-dimensional data points in a two- or three-dimensional map so that points which are close neighbors in the original space stay close in the map. In machine learning and the wider field of artificial intelligence, it is used mainly as a visualization tool for exploring embeddings, clusters and class structure, not as a general-purpose feature transformation.
The method was introduced by Laurens van der Maaten and Geoffrey Hinton in 2008 as an improvement on stochastic neighbor embedding. Its defining idea is to compare probability distributions over neighbors rather than raw distances, and to use a heavy-tailed Student t-distribution in the low-dimensional map to prevent points from collapsing into a dense center.
How t-SNE builds a low-dimensional map
t-SNE works by converting distances into neighbor probabilities in both spaces and then moving the map points until the two sets of probabilities match as closely as possible. The algorithm runs in three stages.
- For each point, a Gaussian kernel centered on that point turns Euclidean distances into conditional probabilities that another point is its neighbor. The kernel width is chosen per point so that its distribution reaches a target perplexity.
- The conditional probabilities are symmetrized into joint probabilities, which makes every pair contribute in both directions and stabilizes the result for outliers.
- In the map, similarities are computed with a Student t-distribution with one degree of freedom, and the positions are optimized by gradient descent on the Kullback-Leibler divergence between the high-dimensional and low-dimensional distributions.
The heavy tails of the t-distribution solve the crowding problem: a two-dimensional plane has far less room for moderately distant points than a space with hundreds of dimensions. Heavy tails let dissimilar points sit far apart in the map without a large penalty, so separate clusters appear clearly separated. Because the Kullback-Leibler divergence punishes placing true neighbors far apart much more than placing non-neighbors close, t-SNE is biased toward preserving local structure.
The components of the algorithm can be summarized as follows.
| Component | Role | Practical effect |
|---|---|---|
| High-dimensional kernel | Gaussian similarities per point | Adapts to local density |
| Low-dimensional kernel | Student t with one degree of freedom | Reduces crowding of clusters |
| Cost function | Kullback-Leibler divergence | Favors local over global fidelity |
| Optimizer | Gradient descent with momentum | Result depends on initialization |
| Approximation | Barnes-Hut or FFT-based interpolation | Makes large datasets feasible |
Key t-SNE parameters and their effects
The output of t-SNE depends strongly on a handful of hyperparameters, and perplexity is the most influential of them. Perplexity can be read as the effective number of neighbors each point considers; typical values range from 5 to 50, and larger datasets usually tolerate higher values.
| Parameter | Typical range | What it controls |
|---|---|---|
| Perplexity | 5 to 50 | Balance between local and broader structure |
| Learning rate | About n/12, often 200 to 1,000 | Step size; too low causes compressed clouds |
| Early exaggeration | 4 to 12 for the first 250 iterations | Forms tight, well-separated clusters early |
| Iterations | 1,000 or more | Convergence of the layout |
| Initialization | PCA or random | Reproducibility and global arrangement |
| Output dimensions | 2 or 3 | Plotting; higher values are rarely useful |
Two settings deserve particular care. Early exaggeration multiplies the high-dimensional probabilities during the first phase so that clusters form before fine adjustment begins. PCA initialization generally preserves more of the global arrangement than random initialization and gives repeatable layouts, which is why recent implementations use it by default.
t-SNE compared with PCA and UMAP
t-SNE is one of several dimensionality reduction methods, and the right choice depends on whether the goal is visualization, compression or downstream modeling. Principal component analysis is linear and preserves global variance, while UMAP is a newer nonlinear method that is usually faster and keeps somewhat more global structure.
| Property | t-SNE | PCA | UMAP |
|---|---|---|---|
| Mapping type | Nonlinear | Linear | Nonlinear |
| Preserved structure | Mainly local neighborhoods | Global variance | Local with partial global |
| Typical runtime on 100,000 points | Minutes with approximations | Seconds | Faster than t-SNE |
| Transforms new data | Not natively | Yes | Yes |
| Deterministic | No, unless seeded | Yes | No, unless seeded |
| Main use | Visual exploration | Compression and preprocessing | Visualization and feature reduction |
A common workflow combines the methods: PCA first reduces the data to about 50 dimensions to remove noise and speed up computation, and t-SNE then produces the two-dimensional map. Standard t-SNE has no parametric mapping, so it cannot place new points without rerunning the optimization; parametric variants that train a neural network exist but are less common.
Reading a t-SNE plot correctly
A t-SNE map is reliable mainly about which points are neighbors, and several visual features of the plot carry little or no meaning. Misreading these features is the most frequent source of wrong conclusions.
| Visual feature | Meaningful | Reason |
|---|---|---|
| Membership of a tight group | Usually yes | Local neighborhoods are preserved |
| Cluster size | No | Density is equalized by the per-point kernels |
| Distance between clusters | Weakly at best | Global distances are not optimized |
| Apparent clusters in noise | No | Low perplexity can create spurious groups |
| Axis values | No | Coordinates have no units or direction |
Responsible practice is to run several perplexity values and several random seeds and to trust only the patterns that persist across runs. Visual groupings should be confirmed with a clustering algorithm such as k-means or DBSCAN applied to the original or PCA-reduced features, not to the t-SNE coordinates themselves.
Limitations and computational cost
Exact t-SNE has quadratic time and memory cost in the number of points, which limits it to a few thousand samples. The Barnes-Hut approximation reduces the cost to about O(n log n), and FFT-accelerated interpolation, as in FIt-SNE and openTSNE, scales to millions of points on ordinary hardware.
- Non-convex optimization: different seeds can give visibly different layouts.
- No out-of-sample mapping in the standard formulation.
- Unsuitable as model input: the coordinates distort distances and should not feed classifiers.
- Sensitivity to preprocessing: feature scaling and the choice of distance metric change the result.
- Limited global faithfulness: the relative placement of distant clusters is often arbitrary.
Explained without jargon
Imagine a huge spreadsheet where every row describes something, such as a photo or a customer, with hundreds of numbers. Nobody can picture hundreds of dimensions. t-SNE draws a flat map of those rows where similar items end up next to each other.
It works like seating guests at a large party. Each guest tells the host who their closest friends are, and the host arranges the tables so that friends sit together. The map is good at showing who belongs with whom, but the size of each table and the distance between tables do not mean much.
A typical use case
A data science team at an online retailer trains an image model on 60,000 product photos and wants to check whether the learned embeddings separate product categories. Each photo is represented by a 512-dimensional vector. The team first applies PCA to reduce the vectors to 50 dimensions and then runs an FFT-accelerated t-SNE with perplexity 30, PCA initialization and 1,000 iterations.
The resulting map shows distinct groups for shoes, bags and watches, but sneakers and running shoes overlap in a single mixed region. Inspecting that region reveals about 2,000 mislabeled training images. The team corrects the labels, retrains the model and confirms the improvement with standard accuracy metrics rather than with the picture alone. The outcome is a cleaner dataset and a measurable gain in classification accuracy.