12345678910111213141516171819202122232425262728293031 |
- import pickle
- from sklearn.decomposition import PCA
- from sklearn.manifold import TSNE
- import numpy as np
- import pandas as pd
- import matplotlib.pyplot as plt
-
- data = pickle.load(open('users_vectors_clustering.p', 'rb'))
- all_data = []
- clusters = []
-
- for c in data:
- for user in data[c]:
- all_data.append(user)
- clusters.append(c)
-
- # pca = PCA(n_components=2)
-
- # principalComponents = pca.fit_transform(users_dataset)
- # principalDf = pd.DataFrame(data = principalComponents, columns = ['principal component 1', 'principal component 2'])
-
- algorithm = TSNE(n_components=2)
- components = algorithm.fit_transform(all_data)
-
- # components = pca.fit_transform(users_dataset)
- # print(components)
-
- plt.scatter(components[:, 0], components[:, 1], alpha=0.8, s=0.15, c=clusters)
-
- plt.savefig('results77.png')
- print('saved picture')
|