2
$\begingroup$

I played around with the t-SNE implementation in scikit-learn and found that increasing perplexity seemed to always result in a torus/circle. I couldn't find any mentions about this in literature. Check out some examples below, which is just a slight change to sk-learn's t-sne perplexity example. I would love to learn why.

t-sne perplexity

Following input from @amoeba I made a couple of extra examples with perplexity closer to the sample size of 300: enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ What is the sample size here? Linked scikit code uses n=300, and you can't use perplexity larger than n: it's not possible to achieve it. Some tsne implementations will not allow it at all. $\endgroup$
    – amoeba
    Commented Mar 8, 2018 at 11:27
  • $\begingroup$ I see. n is 300 in these examples as well. $\endgroup$ Commented Mar 8, 2018 at 12:57
  • $\begingroup$ Then I am surprised that scikit-learn allows to run t-sne with this parameter at all. I might add this as an answer a bit later today. $\endgroup$
    – amoeba
    Commented Mar 8, 2018 at 14:10

1 Answer 1

3
$\begingroup$

One cannot have perplexity values larger than sample size. [I don't have time right now, but I will try to provide a brief mathematical explanation of this later.]

A popular t-SNE tutorial https://distill.pub/2016/misread-tsne/ says

The image for perplexity 100, with merged clusters, illustrates a pitfall: for the algorithm to operate properly, the perplexity really should be smaller than the number of points. Implementations can give unexpected behavior otherwise.

As explained by Laurens van der Maaten, https://github.com/distillpub/post--misread-tsne/issues/2:

I just had one small remark: you show some results with perplexity 100 that are a complete mess. This mess is likely not due to a property of the algorithm, but due to the implementation you used not catching invalid parameter inputs. Note that the perplexity of a distribution over N items can never be higher then N (in this case, the distribution is uniform). For t-SNE this means you need at least 101 points to be able to use perplexity 100. If you use a perplexity setting that is too high for the number of points (and have no assertion checking for that), the binary search for the right bandwidth will fail and the algorithm produces garbage (depending on the exact implementation).

By the way, I don't trust scikit-learn implementation of t-SNE. I had various problems with it, and I prefer to use Laurens van der Maaten's C++ library (you can find Python wrappers).

$\endgroup$
1
  • $\begingroup$ Cool, thanks. If this behavior is isolated to sk-learn and using a too high perplexity is mathematically incorrect, then I accept your answer. $\endgroup$ Commented Mar 12, 2018 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.