t-SNE — a map that keeps neighbors together
t-SNE places each row on a 2D or 3D map so that rows which were neighbors in the original space stay neighbors on the map. It does this by matching probability distributions, and the loss is a KL divergence. Distances between clusters on the map are not the original distances. A gap that looks large can be a layout choice. Do not measure cluster separation with a ruler on a t-SNE picture.
Perplexity is the effective number of neighbors used to build those probabilities. On a 150-row table, perplexity 30 is a fifth of the data and will glue groups together. Perplexity 5 to 15 is the range that can show local structure. Running it twice with the same perplexity and a different seed moves the points; the neighborhoods should not.
Reduce with PCA first when the table is wide. t-SNE in 50 noisy dimensions spends its neighbors on noise. A PCA pre-step to 20 or 30 columns is a standard part of the method, not a different analysis.
Settings that change this fit
- perplexity
- Neighborhood size. It must be smaller than the number of rows. Lower values reveal smaller groups and more of the random layout.
- learning rate
- Too low and the points collapse to a ball. Too high and they explode into a uniform cloud. If the picture looks like either, this is the knob.