I am using the example code provided here to implement k-means clustering. I wish to plot the result on a graph to understand the output better. How do I go about it?
I find it a little difficult to understand the plotting code provided in some places.
Looking at the page to which you linked, it seems that the particular clustering scheme you use starts by mapping the words into a high dimensional space, e.g.,
HashingVectorizer hashes word occurrences to a fixed dimensional space
So, from this point, your question is how to project a high dimensional space onto 2D. After all, if you can do this, then you can just plot the points corresponding to words in 2D, and color the points according to their cluster number.
There are several ways to project a high dimensional space onto 2D. Perhaps the most intuitive one is PCA (which is the first in the link just above).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With