t-SNE and UMAP caveats
Quick answer
t-SNE and UMAP construct nonlinear low-dimensional embeddings intended to reveal neighborhood structure. Their plots are exploratory representations, not faithful maps of global distances or proof of cluster counts. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 SciPy 1.17.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Measure local neighbor retention
a=[1,2,3]; b=[2,3,4]print(len(set(a)&set(b)),len(a))Observed local output:
2 3Two of three original neighbors survive in the embedding.
How it works
t-SNE builds similarity probabilities from high-dimensional distances, with local bandwidths governed by perplexity (an effective neighborhood scale). It minimizes KL divergence between those affinities and heavy-tailed low-dimensional affinities; missing strong input neighbors is penalized substantially. The objective is nonconvex, so initialization, seed, perplexity and optimization matter. Perplexity must be smaller than the number of samples in scikit-learn. The estimator offers fit_transform, not a general transform for new observations. Do not concatenate test rows to refit a visualization and call it a predictive pipeline. UMAP constructs a weighted neighborhood graph and optimizes an embedding to represent its fuzzy connectivity. Its n_neighbors adjusts neighborhood scale, min_dist influences how tightly embeddings pack, and metric defines input geometry. These knobs are not direct cluster counts or a hard guarantee of pairwise distances. Some UMAP implementations support transforming unseen rows after fitting; check version-specific behavior. UMAP is an overview here because umap-learn is absent locally; no UMAP execution is claimed. Neighborhood overlap at k counts shared nearest-neighbor IDs divided by k, averaged across rows. Trustworthiness instead penalizes unexpected embedded neighbors according to their input ranks; it is useful but does not guarantee global geometry. Compare fixed settings across seeds and report the input metric. Plot rotations/reflections are arbitrary; apparent islands, gaps and sizes do not prove discrete classes or population densities. For downstream modeling, select transforms on training folds and use only methods with a verified out-of-sample transform.
Run a small t-SNE embedding
import numpy as npfrom sklearn.manifold import TSNE,trustworthinessr=np.random.default_rng(7)X=r.normal(size=(40,5))Z=TSNE(n_components=2,perplexity=8,init="random",random_state=7,max_iter=500,learning_rate="auto").fit_transform(X)t=trustworthiness(X,Z,n_neighbors=5)print(Z.shape,bool(np.isfinite(Z).all()),bool(0<=t<=1))Observed local output:
(40, 2) True TrueVerify shape and bounded metric, not exact coordinate values across environments.
Common mistakes
Do not read inter-island spacing as calibrated distance, compare coordinate axes across independently fitted embeddings, or tune on final test labels. A high trustworthiness score does not validate global distances.
Practice and next steps
For original neighbors [1,2,3] and embedded neighbors [2,3,4], compute overlap. Then compare two t-SNE seeds in the project using neighborhood overlap instead of raw coordinate differences. Complete the knowledge check and staged exercise. Next: Semi-supervised and self-supervised learning.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
t-SNE and UMAP caveats — knowledge check
Apply t-sne and umap caveats to new scenarios.
What does perplexity influence in t-SNE?
Two seeds produce rotated plots. What should be compared?
Which scikit-learn t-SNE capability is absent?
What does UMAP min_dist influence?
What can a high trustworthiness score establish?