kennyhsieh1111
11/28/2019 - 12:17 PM

T-Distributed Stochastic Neighbor Embedding (TSNE)

TSNE is a popular unsupervised dimensionality reduction algorithm that finds uses as varied as neurology, image similarity, and visualizing neural networks.

Provided with three methods:

  1. Scikit-learn (Traditional)
  2. Multicore (Parallel Accerlerate, faster)
  3. RAPIDS (GPU Accerlerate, fastest)

Resource

  1. Medium : Accelerating TSNE with GPUs: From hours to seconds
from sklearn.datasets import load_digits
X, y = load_digits().data, load_digits().target

from sklearn.manifold import TSNE
tsne = TSNE(n_components = 2)
X_hat = tsne.fit_transform(X)

# To plot the embedding
import matplotlib.pyplot as plt
%matplotlib inline
plt.scatter(X_hat[:,0], X_hat[:,1], c = y, s = 0.5)
from sklearn.datasets import load_digits
digits = load_digits()

from MulticoreTSNE import MulticoreTSNE as TSNE
embeddings = TSNE(n_jobs=4).fit_transform(digits.data)
vis_x = embeddings[:, 0]
vis_y = embeddings[:, 1]

from matplotlib import pyplot as plt
plt.scatter(vis_x, vis_y, c=digits.target, cmap=plt.cm.get_cmap("jet", 10), marker='.')
plt.colorbar(ticks=range(10))
plt.clim(-0.5, 9.5)
plt.show()
# Installation
# https://rapids.ai/start.html#rapids-release-selector
# conda install -c rapidsai -c nvidia -c conda-forge -c defaults rapids=0.10 python=3.7

from sklearn.datasets import load_digits
X, y = load_digits().data, load_digits().target

from cuml.manifold import TSNE
tsne = TSNE(n_components = 2)
X_hat = tsne.fit_transform(X)

# To plot the embedding
import matplotlib.pyplot as plt
%matplotlib inline
plt.scatter(X_hat[:,0], X_hat[:,1], c = y, s = 0.5)