|
|
|
@ -148,9 +148,7 @@ print (km.labels_)
|
|
|
|
|
|
|
|
|
|
# MiniBatchKMeans
|
|
|
|
|
from sklearn.cluster import MiniBatchKMeans
|
|
|
|
|
mbk = MiniBatchKMeans(init='random',
|
|
|
|
|
n_clusters=num_clusters) #(init='k-means++',
|
|
|
|
|
‘random’ or an ndarray)
|
|
|
|
|
mbk = MiniBatchKMeans(init='random', n_clusters=num_clusters) #(init='k-means++',‘random’ or an ndarray)
|
|
|
|
|
mbk.fit_transform(tfidf_matrix)
|
|
|
|
|
mbk.fit(tfidf_matrix)
|
|
|
|
|
miniclusters = mbk.labels_.tolist()
|
|
|
|
@ -210,20 +208,17 @@ dist = 1 - cosine_similarity(tfidf_matrix)
|
|
|
|
|
dist.shape
|
|
|
|
|
# Метод главных компонент - PCA
|
|
|
|
|
from sklearn.decomposition import IncrementalPCA
|
|
|
|
|
icpa = IncrementalPCA(n_components=2,
|
|
|
|
|
batch_size=16)
|
|
|
|
|
icpa = IncrementalPCA(n_components=2, batch_size=16)
|
|
|
|
|
icpa.fit(dist)
|
|
|
|
|
demo2 = icpa.transform(dist)
|
|
|
|
|
xs, ys = demo2[:, 0], demo2[:, 1]
|
|
|
|
|
# PCA 3D
|
|
|
|
|
from sklearn.decomposition import IncrementalPCA
|
|
|
|
|
icpa = IncrementalPCA(n_components=3,
|
|
|
|
|
batch_size=16)
|
|
|
|
|
icpa = IncrementalPCA(n_components=3,batch_size=16)
|
|
|
|
|
icpa.fit(dist)
|
|
|
|
|
ddd = icpa.transform(dist)
|
|
|
|
|
xs, ys, zs = ddd[:, 0], ddd[:, 1], ddd[:, 2]
|
|
|
|
|
#Можно сразу примерно посмотреть, что получится в
|
|
|
|
|
итоге
|
|
|
|
|
#Можно сразу примерно посмотреть, что получится в итоге
|
|
|
|
|
from mpl_toolkits.mplot3d import Axes3D
|
|
|
|
|
fig = plt.figure()
|
|
|
|
|
ax = fig.add_subplot(111, projection='3d')
|
|
|
|
@ -232,4 +227,4 @@ ax.set_xlabel('X')
|
|
|
|
|
ax.set_ylabel('Y')
|
|
|
|
|
ax.set_zlabel('Z')
|
|
|
|
|
plt.show()
|
|
|
|
|
```
|
|
|
|
|
```
|
|
|
|
|