distillpub / post--misread-tsne

How to Use t-SNE Effectively
https://distill.pub/2016/misread-tsne/
Creative Commons Attribution 4.0 International
195 stars 41 forks source link

Importance of Random initialisation / seed ? #9

Open knbknb opened 6 years ago

knbknb commented 6 years ago

I am by no means an expert on t-SNE, and I think your blogpost https://distill.pub/2016/misread-tsne/ is quite helpful for beginners, like myself.

Now that I have installed R-package Rtsne (https://github.com/jkrijthe/Rtsne), I ran one of its code examples from the package documentation. There I noticed that initialisation with a random seed also is very important. However you don't mention influence of the random seed in your blogpost.

## documentation code
iris_unique <- unique(iris) # Remove duplicates
iris_matrix <- as.matrix(iris_unique[,1:4])
set.seed(42) # Set a seed if you want reproducible results
tsne_out <- Rtsne(iris_matrix) # Run TSNE

# Show the objects in the 2D tsne representation
plot(tsne_out$Y,col=iris_unique$Species)
### end of r documentation

### my code
# run again, with different random initzn: completely different-looking plot
tsne_out <- Rtsne(iris_matrix) # Run TSNE
plot(tsne_out$Y,col=iris_unique$Species)

For the small (n= 150) iris dataset, the clusters just seem to be flip-flopped to different edges of the 2d-plane of the plotting area, but for more complex data the plots can look completely different, even when the hyperparameters are held constant and just the init values change.

(Let me know if this is not written clearly enough.)

sleighsoft commented 5 years ago

The seed indeed has a big impact on the result of a t-SNE plot due to its use of gradient descent and possibly many local optima it can find.

I would like the authors to provide the seeds they used to generate their subplots. If you click on let's say paragraph 1. Perplexity 2, Steps 5000 it shows a stepwise visualization that will not recreate the thumbnail that you clicked at.