Plot Centroids by Clustering Things
Plot Centroids by Clustering Things
PUBLIC Asked
2 years, 8 months ago Modified
2 years, 8 months ago Viewed
1k times
Questions
I'm coding to group texts using KMeans and everything is working well, but I'm not able to plot the
Tags The Overflow Blog
centroids together. I don't know how to use matplotlib, only seaborn along with the vector created
Users 2 by tdidf. CEO update: Eliminating obstacles to
productivity, efficiency, and learning
Companies MiniBatchKMeans has the variable cluster_centers_ , but I'm not able to use it in the image.
Announcing more ways to learn and grow
COLLECTIVES
your skills
from sklearn.feature_extraction.text import TfidfVectorizer
pca = PCA(n_components = 9)
Collectives: The next iteration
sharing organizational
knowledge. X_pca = pca.fit_transform(vextorized.toarray())
y_pred = kmeans.fit_predict(vextorized)
Related
np.unique(y_pred)
Share Improve this question Follow edited May 23, 2020 at 11:56 asked May 22, 2020 at 3:24 1491 How to put the legend outside the plot
StupidWolf Sergio Pantano
43.7k 17 37 68 97 1 9 712 When to use cla(), clf() or close() for
clearing a plot in matplotlib?
y_train = newsgroups.target
How accurate is this figure by TIME magazine?
tfidf = TfidfVectorizer(max_features=2**12, ngram_range=(1,4), stop_words = 'englis What's the point of continuing not to recognize the
Taliban government of Afghanistan?
vextorized = tfidf.fit_transform(X_train)
Question feed
Now kmeans:
random_state=777)
y_pred = kmeans.fit_predict(vextorized)
centers_on_PCs = pca.transform(kmeans.cluster_centers_)
plt.scatter(x=centers_on_PCs[:,0],y=centers_on_PCs[:,1],s=200,c="k",marker="X")
Share Improve this answer Follow answered May 23, 2020 at 11:54
StupidWolf
43.7k 17 37 68
Add a comment
Your Answer
Post Your Answer By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
Not the answer you're looking for? Browse other questions tagged python matplotlib seaborn
STACK OVERFLOW PRODUCTS COMPANY STACK EXCHANGE NETWORK Blog Facebook Twitter LinkedIn Instagram