Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from matplotlib import pyplot as plt
- from sklearn.manifold import TSNE
- def tsne_plot():
- "Creates and TSNE model and plots it"
- labels = []
- tokens = []
- for word in selected_words:
- if word in word2index.keys():
- tokens.append(word2vec(word))
- labels.append(word)
- tsne_model = TSNE(perplexity=40, n_components=2, init='pca', n_iter=2500, random_state=23)
- new_values = tsne_model.fit_transform(tokens)
- x = []
- y = []
- for value in new_values:
- x.append(value[0])
- y.append(value[1])
- plt.figure(figsize=(16, 16))
- for i in range(len(x)):
- plt.scatter(x[i],y[i])
- plt.annotate(labels[i],
- xy=(x[i], y[i]),
- xytext=(5, 2),
- textcoords='offset points',
- ha='right',
- va='bottom')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement