pyclustering.cluster.kmedians.kmedians Class Reference

Class represents clustering algorithm K-Medians. More...

Public Member Functions

def __init__ (self, data, initial_centers, tolerance=0.001, ccore=True, kwargs)
 Constructor of clustering algorithm K-Medians. More...
 
def process (self)
 Performs cluster analysis in line with rules of K-Medians algorithm. More...
 
def get_clusters (self)
 Returns list of allocated clusters, each cluster contains indexes of objects in list of data. More...
 
def get_medians (self)
 Returns list of centers of allocated clusters. More...
 
def get_cluster_encoding (self)
 Returns clustering result representation type that indicate how clusters are encoded. More...
 

Detailed Description

Class represents clustering algorithm K-Medians.

The algorithm is less sensitive to outliers than K-Means. Medians are calculated instead of centroids.

     CCORE option can be used to use the pyclustering core - C/C++ shared library for processing that significantly increases performance.

Example:

# load list of points for cluster analysis
sample = read_sample(path);
# create instance of K-Medians algorithm
kmedians_instance = kmedians(sample, [ [0.0, 0.1], [2.5, 2.6] ]);
# run cluster analysis and obtain results
kmedians_instance.process();
kmedians_instance.get_clusters();

Definition at line 40 of file kmedians.py.

Constructor & Destructor Documentation

◆ __init__()

def pyclustering.cluster.kmedians.kmedians.__init__ (   self,
  data,
  initial_centers,
  tolerance = 0.001,
  ccore = True,
  kwargs 
)

Constructor of clustering algorithm K-Medians.

Parameters
[in]data(list): Input data that is presented as list of points (objects), each point should be represented by list or tuple.
[in]initial_centers(list): Initial coordinates of medians of clusters that are represented by list: [center1, center2, ...].
[in]tolerance(double): Stop condition: if maximum value of change of centers of clusters is less than tolerance than algorithm will stop processing
[in]ccore(bool): Defines should be CCORE library (C++ pyclustering library) used instead of Python code or not.
[in]**kwargsArbitrary keyword arguments (available arguments: 'metric').

Keyword Args:

  • metric (distance_metric): Metric that is used for distance calculation between two points.

Definition at line 62 of file kmedians.py.

Member Function Documentation

◆ get_cluster_encoding()

def pyclustering.cluster.kmedians.kmedians.get_cluster_encoding (   self)

Returns clustering result representation type that indicate how clusters are encoded.

Returns
(type_encoding) Clustering result representation.
See also
get_clusters()

Definition at line 149 of file kmedians.py.

◆ get_clusters()

def pyclustering.cluster.kmedians.kmedians.get_clusters (   self)

Returns list of allocated clusters, each cluster contains indexes of objects in list of data.

See also
process()
get_medians()

Definition at line 125 of file kmedians.py.

Referenced by pyclustering.samples.answer_reader.get_cluster_lengths(), and pyclustering.cluster.optics.optics.process().

◆ get_medians()

def pyclustering.cluster.kmedians.kmedians.get_medians (   self)

Returns list of centers of allocated clusters.

See also
process()
get_clusters()

Definition at line 137 of file kmedians.py.

◆ process()

def pyclustering.cluster.kmedians.kmedians.process (   self)

Performs cluster analysis in line with rules of K-Medians algorithm.

Returns
(kmedians) Returns itself (K-Medians instance).
Remarks
Results of clustering can be obtained using corresponding get methods.
See also
get_clusters()
get_medians()

Definition at line 90 of file kmedians.py.


The documentation for this class was generated from the following file: