class_docstr: The K-means clusterer starts with k arbitrary chosen means then allocates
  each vector to the cluster with the closest mean. It then recalculates the
  means of each cluster as the centroid of the vectors in the cluster. This
  process repeats until the cluster memberships stabilise. This is a
  hill-climbing algorithm which may converge to a local maximum. Hence the
  clustering is often repeated with random initial means and the most
  commonly occurring output means are chosen.
docstr: :param  num_means:  the number of means to use (may use fewer)
  :type   num_means:  int
  :param  distance:   measure of distance between two vectors
  :type   distance:   function taking two vectors and returning a float
  :param  repeats:    number of randomised clustering trials to use
  :type   repeats:    int
  :param  conv_test:  maximum variation in mean differences before
                      deemed convergent
  :type   conv_test:  number
  :param  initial_means: set of k initial means
  :type   initial_means: sequence of vectors
  :param  normalise:  should vectors be normalised to length 1
  :type   normalise:  boolean
  :param svd_dimensions: number of dimensions to use in reducing vector
                         dimensionsionality with SVD
  :type svd_dimensions: int
  :param  rng:        random number generator (or None)
  :type   rng:        Random
  :param avoid_empty_clusters: include current centroid in computation
                               of next one; avoids undefined behavior
                               when clusters become empty
  :type avoid_empty_clusters: boolean
docstr_tok: [":","param","num_means",":","the","number","of","means","to","use","(","may","use","fewer",")",":","type","num_means",":","int",":","param","distance",":","measure","of","distance","between","two","vectors",":","type","distance",":","function","taking","two","vectors","and","returning","a","float",":","param","repeats",":","number","of","randomised","clustering","trials","to","use",":","type","repeats",":","int",":","param","conv_test",":","maximum","variation","in","mean","differences","before","deemed","convergent",":","type","conv_test",":","number",":","param","initial_means",":","set","of","k","initial","means",":","type","initial_means",":","sequence","of","vectors",":","param","normalise",":","should","vectors","be","normalised","to","length","1",":","type","normalise",":","boolean",":","param","svd_dimensions",":","number","of","dimensions","to","use","in","reducing","vector","dimensionsionality","with","SVD",":","type","svd_dimensions",":","int",":","param","rng",":","random","number","generator","(","or","None",")",":","type","rng",":","Random",":","param","avoid_empty_clusters",":","include","current","centroid","in","computation","of","next","one",";","avoids","undefined","behavior","when","clusters","become","empty",":","type","avoid_empty_clusters",":","boolean"]
code: def __init__(
      self,
      num_means,
      distance,
      repeats=1,
      conv_test=1e-6,
      initial_means=None,
      normalise=False,
      svd_dimensions=None,
      rng=None,
      avoid_empty_clusters=False,
  ):
      """
      :param  num_means:  the number of means to use (may use fewer)
      :type   num_means:  int
      :param  distance:   measure of distance between two vectors
      :type   distance:   function taking two vectors and returning a float
      :param  repeats:    number of randomised clustering trials to use
      :type   repeats:    int
      :param  conv_test:  maximum variation in mean differences before
                          deemed convergent
      :type   conv_test:  number
      :param  initial_means: set of k initial means
      :type   initial_means: sequence of vectors
      :param  normalise:  should vectors be normalised to length 1
      :type   normalise:  boolean
      :param svd_dimensions: number of dimensions to use in reducing vector
                             dimensionsionality with SVD
      :type svd_dimensions: int
      :param  rng:        random number generator (or None)
      :type   rng:        Random
      :param avoid_empty_clusters: include current centroid in computation
                                   of next one; avoids undefined behavior
                                   when clusters become empty
      :type avoid_empty_clusters: boolean
      """
      VectorSpaceClusterer.__init__(self, normalise, svd_dimensions)
      self._num_means = num_means
      self._distance = distance
      self._max_difference = conv_test
      assert not initial_means or len(initial_means) == num_means
      self._means = initial_means
      assert repeats >= 1
      assert not (initial_means and repeats > 1)
      self._repeats = repeats
      self._rng = rng if rng else random.Random()
      self._avoid_empty_clusters = avoid_empty_clusters
  
file_path: nltk/nltk/cluster/kmeans.py
imports: import copy
  import random
  import sys
  from nltk.cluster.util import VectorSpaceClusterer
label_desc: Use image node_id 1 to create a new KMeansClusterer object from inherited base classes: VectorSpaceClusterer with example: obj = KMeansClusterer(num_means, distance, repeats, conv_test, initial_means, normalise, svd_dimensions, rng, avoid_empty_clusters)