iwiwi 備忘録

学んだことを殴り書きます。自分向けのメモです。

t-SNE の実装はどれを使うべきなのか?

scikit-learn の問題点

scikit-learn 信者としてはとりあえず scikit-learn の実装を使いたくなるが、scikit-learn の実装はおすすめできないらしい。

  • -https://www.red dit.com/r/MachineLearning/comments/47kf7w/scikitlearn_tsne_implementation/ (はてなブログはred ditのURLを貼るとbad requestになり投稿できない謎仕様)

Besides being slower, sklearn's t-SNE implementation is fine once you realize the default learning rate is way too high for most applications. The definitive bh_tsne implementation by the author sets the learning rate to 200, and the original 2008 paper describes setting it to 100, while sklearn is set to 1000.

  • 遅い
  • デフォルト値の learning rate が大きすぎる

とのこと。それに加えて、自分の経験としては、Barnes Hut 木を指定してもメモリをもりもり確保して(即 Θ(n^2) のメモリを確保してる気がする)メモリ不足で死ぬ。だめ。

公式実装に基づくものたち

自分の結論

$ pip install bhtsne

からの

import sklearn.base
import bhtsne
import numpy as np


class BHTSNE(sklearn.base.BaseEstimator, sklearn.base.TransformerMixin):

    def __init__(self, dimensions=2, perplexity=30.0, theta=0.5, rand_seed=-1):
        self.dimensions = dimensions
        self.perplexity = perplexity
        self.theta = theta
        self.rand_seed = rand_seed

    def fit_transform(self, x):
        return bhtsne.tsne(
            x.astype(np.float64), dimensions=self.dimensions, perplexity=self.perplexity, theta=self.theta,
            rand_seed=self.rand_seed)