pyclustering.cluster.agglomerative.agglomerative Class Reference

Class represents agglomerative algorithm for cluster analysis. More...

Public Member Functions

def __init__ (self, data, number_clusters, link=None, ccore=True)
 Constructor of agglomerative hierarchical algorithm. More...
 
def process (self)
 Performs cluster analysis in line with rules of agglomerative algorithm and similarity. More...
 
def get_clusters (self)
 Returns list of allocated clusters, each cluster contains indexes of objects in list of data. More...
 
def get_cluster_encoding (self)
 Returns clustering result representation type that indicate how clusters are encoded. More...
 

Detailed Description

Class represents agglomerative algorithm for cluster analysis.

Agglomerative algorithm considers each data point (object) as a separate cluster at the beggining and step by step finds the best pair of clusters for merge until required amount of clusters is obtained.

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

Example of agglomerative algorithm where centroid link is used:

# sample for cluster analysis (represented by list)
sample = read_sample(path_to_sample);
# create object that uses python code only
agglomerative_instance = agglomerative(sample, 2, link_type.CENTROID_LINK)
# cluster analysis
agglomerative_instance.process();
# obtain results of clustering
clusters = agglomerative_instance.get_clusters();

Algorithm performance can be improved if 'ccore' flag is on. In this case C++ library will be called for clustering. There is example of clustering 'LSUN' sample when usage of single or complete link will take a lot of resources and when core usage is prefereble.

# sample Lsun for cluster analysis
lsun_sample = read_sample(FCPS_SAMPLES.SAMPLE_LSUN);
# create instance of the algorithm that will use ccore library (the last argument)
agglomerative_instance = agglomerative(lsun_sample, 3, link_type.SINGLE_LINK, True);
# start processing
agglomerative_instance.process();
# get result and visualize it
lsun_clusters = agglomerative_instance.get_clusters();
visualizer = cluster_visualizer();
visualizer.append_clusters(lsun_clusters, lsun_sample);
visualizer.show();

Example of agglomerative clustering using different links:

agglomerative_lsun_clustering_single_link.png

Definition at line 58 of file agglomerative.py.

Constructor & Destructor Documentation

◆ __init__()

def pyclustering.cluster.agglomerative.agglomerative.__init__ (   self,
  data,
  number_clusters,
  link = None,
  ccore = True 
)

Constructor of agglomerative hierarchical algorithm.

Parameters
[in]data(list): Input data that is presented as a list of points (objects), each point should be represented by list, for example [[0.1, 0.2], [0.4, 0.5], [1.3, 0.9]].
[in]number_clusters(uint): Number of clusters that should be allocated.
[in]link(type_link): Link type that is used for calculation similarity between objects and clusters, if it is not specified centroid link will be used by default.
[in]ccore(bool): Defines should be CCORE (C++ pyclustering library) used instead of Python code or not (by default it is 'False').

Definition at line 106 of file agglomerative.py.

Member Function Documentation

◆ get_cluster_encoding()

def pyclustering.cluster.agglomerative.agglomerative.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 170 of file agglomerative.py.

◆ get_clusters()

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

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

Remarks
Results of clustering can be obtained using corresponding gets methods.
Returns
(list) List of allocated clusters, each cluster contains indexes of objects in list of data.
See also
process()

Definition at line 155 of file agglomerative.py.

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

◆ process()

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

Performs cluster analysis in line with rules of agglomerative algorithm and similarity.

See also
get_clusters()

Definition at line 134 of file agglomerative.py.


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