Scikit-learn t-SNE plot

27 views Asked by At

I am doing a t-SNE plot for a time series of vectors, showing that the vectors end up in different clusters depending on "jumps" in the values of some components of the vectors. The visualization clearly shows 3 clusters corresponding to the 3 average vectors in the time series. But to highlight the temporal aspect of this, I'd like to plot arrows from one point to the next in the time series, following the time order. How could I do that??

Code:

import numpy as np
import matplotlib.pyplot as plt
from sklearn.manifold import TSNE

# Create random vector time series
X = np.random.random(size=(1000,5))
X[500:,3] += 3*np.ones(500)
X[750:,4] += 2*np.ones(250)
y = np.hstack((np.zeros(500), np.ones(250), 2*np.ones(250)))

# Calculate 2d embedding and display
X_embedded = TSNE(n_components=2, learning_rate='auto', init='random', perplexity=6).fit_transform(X)
fig, ax = plt.subplots(1,1)
plt.scatter(X_embedded[:,0], X_embedded[:,1], c = y, cmap=plt.cm.rainbow);

Result:

enter image description here

0

There are 0 answers