-1

how can I pass 2 nodes as centroids to sklearn.kmeans(n_clusters,init,....) instead of random or kmeans++? algorithms['kmeans'] = KMeans(n_clusters=k_clusters,init='random', n_init=200)

Far
  • 5
  • 4

1 Answers1

0

sklearn also allows users to input centroids of shape (n_clusters, n_features).

The documentation: https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html

For less than n_clusters, you could use random initialization and pass it.

sotmot
  • 1,256
  • 2
  • 9
  • 21
  • I know but I have a dataset called "zarchy karate club" which represents a graph. the points are not in space by default. There were some implementations of kmeans clustering for it like the one on https://www.learndatasci.com/tutorials/k-means-clustering-algorithms-python-intro/, but I wonder how can I pass some nodes as centroids to sklearn.cluster.kmeans?! I dont know what (n_clusters, n_features) mean in this case?! – Far Jan 08 '22 at 18:00
  • Then it is not that simple. You'd have to send them to a `networkx` plot function, get their location, then select centroids, pass that. – sotmot Jan 08 '22 at 18:03
  • As for your `n_clusters, n_features` doubt, do consider reading a bit about kmeans -- atleast from the documentation I posted in my answer. – sotmot Jan 08 '22 at 18:04
  • Can I use kmeans.transform for this purpose? Does it change data to change to locations? – Far Jan 08 '22 at 18:10
  • Well technically, before you use `transform`, you need to `fit`. Else it uses untrained, random centroids. – sotmot Jan 08 '22 at 18:12
  • Can you give me some examples of (n_clusters, n_features) especially for my dataset – Far Jan 08 '22 at 18:21