Update lab2.md

master
Vladimir Protsenko 3 years ago
parent eff84da80d
commit 48d9e9a6dd

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

Loading…
Cancel
Save