0
$\begingroup$

i m try to apply k-means with Python 3 to my dataset (Amazon review) for classify similar user (from review).

I just have a TF and TF-IDF matrix (and i have a row(user) and columns(words) value in distinct csv file) enter image description here

I m starting with sklearn from this sketch

https://scikit-learn.org/stable/auto_examples/text/plot_document_clustering.html#sphx-glr-auto-examples-text-plot-document-clustering-py

but in my case i don't have label or category, and i don't understand how k-means can cluster different items from this matrix TD-IDF.

  1. How can I group similar words from my dataset, from the matrix without having any information?
  2. How do I show these n-clusters in the chart?
  3. And how do I show the similar words of this cluster, if I do not have any information (like label or category)?

For now this is my code :

k = 5
km = KMeans(n_clusters=k, init='k-means++', max_iter=100, n_init=5)
km.fit(Y) ##Y is my TD-IDF matrix

original_centroids = svd.inverse_transform(km.cluster_centers_)
print(original_centroids.shape) 
for i in range(original_centroids.shape[0]):
original_centroids[i] = np.array([x for x in original_centroids[i]])
svd_centroids = original_centroids.argsort()[:, ::-1]

i would like have a set like this(with similar word near)

enter image description here

I m very lost, because i m new in this word.

$\endgroup$
  • $\begingroup$ There is no question... $\endgroup$ – Mark.F Dec 30 '18 at 9:17
  • $\begingroup$ the question is...how to apply k-means without the label. I edit the question $\endgroup$ – theantomc Dec 30 '18 at 9:19
  • $\begingroup$ The question doesn't make sense; k-means is an unsupervised technique and by nature has nothing to do with labels $\endgroup$ – Sean Owen Dec 30 '18 at 14:32
  • $\begingroup$ maybe I have to reformulate the question. Unfortunately I saw only this example and I saw these labels and maybe I was too tied to this particular. @SeanOwen My question was more specific than k-means, because I was trying to catalog users in different groups, but I understand how it is possible (it seems too magical) how I can divide them without knowing anything except the TD-IDF matrix and print with that example of related topics. This is why I tied myself to those labels.. I will edit the question. $\endgroup$ – theantomc Dec 30 '18 at 23:43
  • $\begingroup$ @theantomc are you trying to cluster words or users. In the edit you proposed it says you are trying to cluster words, for which k-means would be the wrong method but if it's user what you are trying to cluster then this question could be edited to reflect that intention. $\endgroup$ – wacax Dec 31 '18 at 13:54
1
$\begingroup$

K-means does not use labels.

The example that you looked at uses labels to compare the clusters to the labels. That part obviously requires labels; but that is not part of k-means.

$\endgroup$
  • $\begingroup$ Thanks for this clarification. So i don't understand how to classification this topics... Because i don't how to divided in groups similar topics. Because in example use " terms = vectorizer.get_feature_names()" for take "names" and cluster to different topics... In my case, just with TF-IDF i have just a division, but i don't know the topic... sorry this question that could be stupid, i m trying to understand $\endgroup$ – theantomc Dec 30 '18 at 9:51
  • $\begingroup$ K-means does not produce a topic. It produces center vectors. You'll have to make these "topics" yourself. But what is a "topic" anyway? That is subjective. $\endgroup$ – Has QUIT--Anony-Mousse Dec 31 '18 at 1:38
  • $\begingroup$ Because i dont cover how to do with this "topic" $\endgroup$ – theantomc Dec 31 '18 at 7:33
  • $\begingroup$ Nor do I. Because it's undefined. You have to define what a topic is. K-means doesn't use topics, it uses means. $\endgroup$ – Has QUIT--Anony-Mousse Dec 31 '18 at 20:53
  • $\begingroup$ For me the topic, is a different cluster. In this way i think that if I have a "topic car" i see just word related to the car... I think that is the way of the cluster $\endgroup$ – theantomc Jan 1 '19 at 11:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.