Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 1006 Bytes

tsne-embedding-example.md

File metadata and controls

34 lines (26 loc) · 1006 Bytes

TSNe embedding example

import numpy as np
from sklearn import manifold

X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
Xe = manifold.TSNE(n_components=2, learning_rate='auto', init='random').fit_transform(X)
  • import numpy - import lib:Numpy module
  • from sklearn import - import module from lib:scikit-learn
  • .TSNE( - creates T-distributed Stochastic Neighbor Embedding model
  • n_components=2 - reduce dataset to 2 features
  • .fit_transform( - train and transform given dataset
  • Xe - will contain embedded dataset

Example:

import numpy as np
from sklearn.manifold import TSNE

X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
print(X.shape)

Xe = TSNE(n_components=2, learning_rate='auto', init='random').fit_transform(X)
print(Xe.shape)
(4, 3)
(4, 2)