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.

Example of agglomerative algorithm where centroid link is used:

from pyclustering.cluster.agglomerative import agglomerative, type_link
from pyclustering.cluster import cluster_visualizer
from pyclustering.samples.definitions import FCPS_SAMPLES
from pyclustering.utils import read_sample
# Sample for cluster analysis (represented by list)
sample = read_sample(FCPS_SAMPLES.SAMPLE_TARGET)
# Create object that uses python code only
agglomerative_instance = agglomerative(sample, 6, type_link.SINGLE_LINK, ccore=True)
# Cluster analysis
agglomerative_instance.process()
# Obtain results of clustering
clusters = agglomerative_instance.get_clusters()
# Visualize clustering results
visualizer = cluster_visualizer()
visualizer.append_clusters(clusters, sample)
visualizer.show()

There is example of clustering 'LSUN' sample:

from pyclustering.cluster.agglomerative import agglomerative, type_link
from pyclustering.cluster import cluster_visualizer
from pyclustering.samples.definitions import FCPS_SAMPLES
from pyclustering.utils import read_sample
# 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, type_link.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 117 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 187 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 172 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.

Returns
(agglomerative) Returns itself (Agglomerative instance).
See also
get_clusters()

Definition at line 147 of file agglomerative.py.


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