Package parsimony :: Package algorithms :: Module cluster :: Class KMeans
[hide private]
[frames] | no frames]

Class KMeans

source code

         object --+        
                  |        
bases.BaseAlgorithm --+    
                      |    
bases.ImplicitAlgorithm --+
                          |
                         KMeans

The K-means clustering algorithm.

Performs clustering using the K-means clustering algorithm, also known as
Lloyd's algorithm.

Parameters
----------
K : Positive integer. The number of clusters to find.

init : KMeans.INIT or numpy array with shape (K, p). The initialisation
        method to use for the centres. If init is a numpy array, it
        contains the actual centres to use.

repeat : Positive integer. Default is 10. The number of times to repeat the
        initialisation and run the algorithm. The set of centre points that
        give the lowest within-cluster sum of squares is returned.

max_iter : Non-negative integer. Maximum allowed number of iterations.
        Default is 100.

eps : Positive float. The tolerance used by the stopping criterion.

Returns
-------
centers : Numpy array. The mean cluster centres.

Examples
--------
>>> import numpy as np

Nested Classes [hide private]
  INIT
Instance Methods [hide private]
 
__init__(self, K, init='random', repeat=10, max_iter=100, eps=5e-08)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
run(self, X)
Runs the K-means clustering algorithm on the given data matrix.
source code
 
_init_mus(self, X, K) source code
 
_closest_centers(self, X, mus, K)
Given a set of points and a set of centres, compute the closest centre to each point.
source code
 
_new_centers(self, X, closest, K)
Given a set of points, X, and their previously closest centre, encoded in closest, computes their new centres.
source code
 
_wcss(self, X, mus, closest, K)
Within-cluster sum of squares loss function.
source code

Inherited from bases.BaseAlgorithm: get_params, set_params

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]

Inherited from bases.BaseAlgorithm: check_compatibility

Class Variables [hide private]
  __abstractmethods__ = frozenset([])

Inherited from bases.ImplicitAlgorithm: __metaclass__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, K, init='random', repeat=10, max_iter=100, eps=5e-08)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

run(self, X)

source code 
Runs the K-means clustering algorithm on the given data matrix.

Parameters
----------
X : Numpy array of shape (n, p). The matrix of points to cluster.

Overrides: bases.ImplicitAlgorithm.run