t-SNE (t-distributed stochastic neighbor embedding) is a nonlinear dimensionality-reduction method used primarily for visualizing high-dimensional data in two or three dimensions. It represents similarities between observations as probabilities and constructs a low-dimensional arrangement whose similarity probabilities approximately match them. Introduced by Laurens van der Maaten and Geoffrey Hinton in 2008, t-SNE is widely used in machine learning and exploratory data analysis. Its principal strength is revealing local neighborhood structure; distances between widely separated groups, their apparent sizes, and empty spaces in a plot generally do not have a straightforward quantitative interpretation.
Purpose and conceptual basis
An observation may be described by hundreds or thousands of features: pixel intensities, measured quantities, or coordinates produced by a representation-learning model. Such observations cannot be plotted directly in their original space. A low-dimensional representation, or embedding, assigns each observation a small number of coordinates while attempting to retain selected relationships.
t-SNE belongs to unsupervised learning because its standard objective does not require class labels. It is also commonly grouped with manifold-learning methods, although it does not require an explicit model of the manifold underlying the data.
Rather than preserving all pairwise distances, t-SNE emphasizes which observations are near one another. It converts distances into neighborhood probabilities, then adjusts the plotted coordinates to reproduce those probabilities as closely as possible. The result is a visualization of selected relationships, not a reconstruction of the original geometry.
Mathematical formulation
Let the input observations be , and let their low-dimensional coordinates be . The standard formulation uses Euclidean distances, although implementations can accept other distance measures or precomputed distances.
Similarities in the input space
For each observation , the conditional probability of selecting as a neighbor is
The bandwidth is chosen separately for each observation. This allows neighborhoods to adapt to differences in local sampling density.
The bandwidth is usually determined through a specified perplexity:
Perplexity can be interpreted as an effective number of neighbors, rather than a literal count. The bandwidth is adjusted until the conditional distribution has approximately the requested perplexity.
The conditional probabilities are then symmetrized:
With , these joint probabilities sum to one over all ordered pairs.
Similarities in the embedding
In the standard two-dimensional formulation, the embedding similarities use a Student’s t-distribution with one degree of freedom:
This distribution has heavier tails than the Gaussian kernels used for input similarities. Consequently, moderately distant points in the embedding retain more similarity than they would under a Gaussian kernel.
The heavy tails help address the crowding problem: a low-dimensional space cannot accommodate all the moderately distant neighbors of a high-dimensional point at comparable distances. The t-distribution permits dissimilar observations to be placed farther apart while keeping nearby observations relatively close.
Optimization objective
t-SNE minimizes the Kullback–Leibler divergence from the input similarity distribution to the embedding distribution :
This loss function is asymmetric. Assigning a very small to a pair with substantial incurs a strong penalty. Thus, the objective strongly discourages separating input-space neighbors, but it does not directly preserve every large input-space distance.
For the standard kernel, the gradient is
The optimization can be understood as a balance of attractive and repulsive interactions. Pairs with strong input similarities attract one another, while repulsive interactions help prevent the configuration from collapsing.
The coordinates are typically updated by gradient descent with momentum and other numerical adjustments. Because the objective is nonconvex, different initializations and optimization settings can yield different arrangements.
Parameters and optimization behavior
Several settings materially affect the result.
Perplexity. Lower values emphasize smaller neighborhoods and finer-scale structure. Higher values incorporate broader neighborhoods and can reveal relationships at larger scales. No single value is appropriate for all datasets, and perplexity must be compatible with the number of observations.
Initialization. Coordinates may begin from small random values or from a principal component analysis embedding. Initialization can influence convergence and the broad organization of the final plot. It does not make global distances intrinsically reliable.
Early exaggeration. During an initial optimization phase, input affinities are multiplied by a factor greater than one. This temporarily strengthens attraction between similar points and helps establish neighborhood groupings. The ordinary affinities are restored afterward.
Learning rate. The learning rate controls the size of coordinate updates. Inappropriate values can produce slow convergence, unstable arrangements, or distorted configurations. Numerical conventions differ between implementations, so identical parameter values need not imply identical behavior.
Optimization duration and randomness. An insufficient number of iterations can leave a plot far from a stable solution. Random initialization and approximate neighbor-search procedures can introduce additional variability. A fixed random seed improves reproducibility within a specified computational setup, but does not establish the validity of an interpretation.
These settings are hyperparameters of the visualization procedure, not characteristics inferred uniquely from the data.
Data preparation and distance choice
t-SNE operates on the similarities supplied to it. Its output therefore depends on preprocessing, the features retained, and the distance measure.
When features have different units or numerical ranges, Euclidean distances may be dominated by a small subset of them. Feature scaling changes those distances and therefore changes the relationships t-SNE attempts to preserve. Scaling is not a neutral operation: its appropriateness depends on what the features mean.
High-dimensional data are often reduced to an intermediate number of dimensions using principal component analysis or a related method before t-SNE is applied. This can reduce computation and suppress some noise, but it can also discard meaningful variation.
For learned representations, such as word embeddings or image features, the embedding reflects the representation and similarity measure rather than the raw observations alone. A visually distinct group can arise from meaningful structure, technical artifacts, or choices made during feature engineering.
Computational methods
A direct implementation evaluates interactions between all pairs of observations. This gives quadratic time complexity per optimization iteration and can require quadratic storage when dense pairwise affinities are retained.
Several developments make larger datasets practical:
- Barnes–Hut t-SNE uses a spatial tree to approximate repulsive interactions between sufficiently distant groups of points. Under typical conditions in low output dimensions, the force calculation scales approximately as . Sparse input affinities also reduce the cost of attractive interactions.
- Interpolation-based methods, including FIt-SNE, approximate repulsive interactions using interpolation on a grid and fast Fourier transforms. They substantially reduce optimization costs for large datasets.
- Approximate nearest-neighbor search reduces the expense of constructing input similarities by finding a limited set of likely neighbors instead of evaluating every pair.
These accelerations introduce approximation choices. End-to-end runtime also depends on input dimensionality, neighbor-search cost, perplexity, output dimensionality, and hardware; faster force computation alone does not make every stage scale linearly.
Graphics processing units and optimized implementations can provide further acceleration. Software packages differ in initialization, learning-rate conventions, stopping criteria, and available approximations.
Applications
t-SNE is used to explore image collections, document representations, measured datasets, and features learned by neural networks. It can reveal local groupings, transitions, unusual observations, and possible mismatches between labels and feature-space neighborhoods.
In biological research, a common application is visualizing high-dimensional gene-expression measurements, including single-cell datasets. In machine learning, it is often used to inspect how a model organizes observations in an internal latent space.
These applications are exploratory. A t-SNE plot alone does not establish class boundaries, validate a representation, demonstrate generalization, or identify the cause of an observed grouping.
Interpretation and limitations
Local structure is favored over global geometry
Nearby points often indicate input-space similarity, but neighborhood preservation is approximate. Conversely, widely separated points are not necessarily dissimilar in proportion to their plotted distance.
The relative placement of distant groups can change substantially between runs while many local neighborhoods remain similar. Rotation, reflection, and translation of an entire configuration have no intrinsic meaning.
Group size and density can be misleading
Because input bandwidths adapt to local density, t-SNE does not reliably preserve density or occupied volume. A compact, dense group in the original space may appear comparable in size to a more dispersed group. Apparent area is therefore not a direct measure of variability.
Likewise, the amount of white space between groups is not a calibrated measure of separation in the original space.
Visible groups are not automatically clusters
t-SNE is not itself a clustering algorithm. It produces coordinates, not a statistically justified partition. Distinct-looking islands may be encouraged by the neighborhood scale or optimization process, and continuous structures can sometimes appear fragmented.
Applying a method such as k-means to t-SNE coordinates groups points according to the visualization’s distorted geometry, rather than necessarily according to the intended structure of the original data.
Embeddings are sensitive to data and settings
Changing perplexity, preprocessing, sample composition, or initialization can alter the arrangement. Adding or removing observations can move existing points because the objective depends on the dataset as a whole.
Standard t-SNE optimizes a coordinate for each supplied observation rather than learning a general mapping from input vectors to output coordinates. It therefore has no intrinsic out-of-sample transformation. Extensions can place new observations relative to a fixed embedding or train a parametric mapping, but these introduce additional assumptions.
Embedding quality can be assessed with neighborhood-based measures such as trustworthiness, which penalizes points that become neighbors in the embedding despite being distant in the input space. Such measures evaluate particular aspects of preservation, not the truth of every visual interpretation.
Relationship to other methods
t-SNE developed from stochastic neighbor embedding, introduced by Hinton and Sam Roweis in 2002. The 2008 t-SNE formulation combined symmetric joint similarities with a heavy-tailed embedding distribution, improving optimization behavior and alleviating crowding. Barnes–Hut and interpolation-based implementations later extended its practical use to much larger datasets.
Unlike principal component analysis, t-SNE is nonlinear and does not seek directions of maximum variance. PCA provides a linear transformation applicable to new observations and supports explained-variance calculations; standard t-SNE provides neither.
Uniform Manifold Approximation and Projection is another widely used nonlinear visualization method. It optimizes a different neighborhood-based objective, and common implementations support placing new observations into an existing embedding. Neither method guarantees faithful global geometry or makes visible groups self-validating.
Autoencoders instead learn encoding and decoding functions through a reconstruction objective. They can provide reusable representations, but their training objective differs from t-SNE’s explicit emphasis on matching neighborhood probabilities.