Sub topic 16
Reading embeddings without fooling yourself
This chapter assumes you can run the t-SNE and UMAP examples from earlier chapters and know what perplexity, n_neighbors and min_dist control. It covers what an embedding plot does and does not tell you.
What a plot can support
Both methods optimise for local neighbourhoods. Points that appear close together were probably close in the original space. Almost everything else you might read off the plot is unreliable.
| Visual feature | Safe to trust? | Why |
|---|---|---|
| Tight group of points | Mostly | Neighbours were preserved |
| Cluster size | No | t-SNE expands dense regions and shrinks sparse ones, so size does not track spread |
| Distance between clusters | No | Global layout is weakly constrained |
| Cluster position or rotation | No | Only relative structure is optimised, so a new seed can move everything |
| Apparent cluster at one setting | Only if stable | Small perplexity can split noise into clumps |
Common errors
Reading cluster size and gaps
If digit 1 forms a large blob and digit 0 a small one, that does not mean 1 varies more. The kernel adapts to local density, so each group fills similar space. Gaps between groups may be stretched or squeezed too.
Spurious clusters
Low perplexity (such as 5) can break a single smooth structure into small islands. High min_dist in UMAP can spread points out, and very low n_neighbors can fragment a connected manifold. Random data run with small settings can look clustered.
Trusting one run
Embeddings depend on the seed, initialisation and parameters. A feature you believe in should survive a change of both.
from sklearn.datasets import load_digits
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
X, y = load_digits(return_X_y=True)
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
for ax, seed in zip(axes, [0, 1, 2]):
Z = TSNE(perplexity=30, init="random", learning_rate="auto",
random_state=seed).fit_transform(X)
ax.scatter(Z[:, 0], Z[:, 1], c=y, cmap="tab10", s=6)
ax.set_title(f"seed = {seed}")
plt.show()Using init="random" makes seed effects visible. The groups should reappear in each panel, but their positions and orientations will differ. Groups that appear in only one panel are suspect. With init="pca" the layout is more stable, which also means it hides some of this variation.
A checking routine
When you report a result, state the method, parameters and seed. Say "these groups are neighbours in the original space" and avoid claims about distances between groups.
Exercise
A t-SNE plot shows cluster A about three times wider than cluster B, and A sits far from B while C sits close to B. A colleague concludes that A is the most varied group and is the least similar to the others. Which parts of this conclusion are unsupported, and what would you check first?
Show answer
Cluster width and the distances between clusters are both unsupported, because t-SNE adapts to local density and does not preserve global distances. Only the claim that points inside each cluster are neighbours is reasonable. First rerun with different seeds and perplexity values to see whether the groups and their arrangement persist. Then check inter-group similarity directly in the original space, for example by comparing group means or by using PCA.