9951 explained code solutions for 126 technologies


python-scikit-learnTSNe 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)ctrl + c
import numpy

import Numpy module

from sklearn import

import module from 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


Usage 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)
output
(4, 3)
(4, 2)