How to use fit_transform with an array?

Viewed 186

Example of array content:

[
    [4.9, 3.0, 1.4, 0.2, 0.0, 2.0], 
    [4.7, 3.2, 1.3, 0.2, 0.0, 2.0], 
    [4.6, 3.1, 1.5, 0.2, 0.0, 2.0], 
    ... 
]
model = TSNE(learning_rate=100)
transformed = model.fit_transform(data)

I'm trying to apply tSNE to a float array, but I get an error. What should I change?

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (149,) + inhomogeneous part.

1 Answers

Try this example:

from sklearn.manifold import TSNE
import numpy as np
X = np.array([[4.9, 3.0, 1.4, 0.2, 0.0, 2.0], [4.7, 3.2, 1.3, 0.2, 0.0, 2.0]])
model = TSNE(learning_rate=100)
transformed = model.fit_transform(X)
print(transformed)
Related