|
pyclustering
0.10.1
pyclustring is a Python, C++ data mining library.
|
3 @brief Cluster analysis algorithm: SOM-SC (Self-Organized Feature Map for Simple Clustering)
4 @details There is no paper on which implementation is based. Algorithm SOM-SC is adaptation of SOM for cluster analysis in simple way.
5 Basic idea: amount of cluster that should be allocated is defines amount of neurons in the self-organized map. SOM-SC can be
6 considered as neural network implementation of K-Means algorithm.
7 Implementation based on paper @cite article::nnet::som::1.
9 @authors Andrei Novikov (pyclustering@yandex.ru)
11 @copyright BSD-3-Clause
16 from pyclustering.core.wrapper
import ccore_library
24 @brief Class represents a simple clustering algorithm based on the self-organized feature map.
25 @details This algorithm uses amount of clusters that should be allocated as a size of SOM map. Captured
26 objects by neurons are considered as clusters. The algorithm is designed to process data with Gaussian
27 distribution that has spherical forms.
31 from pyclustering.cluster import cluster_visualizer
32 from pyclustering.cluster.somsc import somsc
33 from pyclustering.samples.definitions import FCPS_SAMPLES
34 from pyclustering.utils import read_sample
36 # Load list of points for cluster analysis
37 sample = read_sample(FCPS_SAMPLES.SAMPLE_TWO_DIAMONDS)
39 # Create instance of SOM-SC algorithm to allocated two clusters
40 somsc_instance = somsc(sample, 2)
42 # Run cluster analysis and obtain results
43 somsc_instance.process()
44 clusters = somsc_instance.get_clusters()
46 # Visualize clustering results.
47 visualizer = cluster_visualizer()
48 visualizer.append_clusters(clusters, sample)
54 def __init__(self, data, amount_clusters, epouch=100, ccore=True, **kwargs):
56 @brief Creates SOM-SC (Self Organized Map for Simple Clustering) algorithm for clustering analysis.
58 @param[in] data (list): List of points that are used for processing.
59 @param[in] amount_clusters (uint): Amount of clusters that should be allocated.
60 @param[in] epouch (uint): Number of epochs for training of SOM.
61 @param[in] ccore (bool): If it is True then CCORE implementation will be used for clustering analysis.
62 @param[in] **kwargs: Arbitrary keyword arguments (available arguments: `random_state`).
64 <b>Keyword Args:</b><br>
65 - random_state (int): Seed for random state (by default is `None`, current system time is used).
78 self.
__ccore = ccore_library.workable()
85 @brief Performs cluster analysis by competition between neurons in self-organized map.
87 @return (somsc) Returns itself (SOM Simple Clustering instance).
104 @brief Calculates the closest cluster to each point.
106 @param[in] points (array_like): Points for which closest clusters are calculated.
108 @return (list) List of closest clusters for each point. Each cluster is denoted by index. Return empty
109 collection if 'process()' method was not called.
115 index_cluster = self.
__network.simulate(point)
116 result.append(index_cluster)
123 @brief Returns list of allocated clusters, each cluster contains indexes of objects in list of data.
134 @brief Returns clustering result representation type that indicate how clusters are encoded.
136 @return (type_encoding) Clustering result representation.
142 return type_encoding.CLUSTER_INDEX_LIST_SEPARATION
145 def __verify_arguments(self):
147 @brief Verify input parameters for the algorithm and throw exception in case of incorrectness.
151 raise ValueError(
"Input data is empty (size: '%d')." % len(self.
__data_pointer))
154 raise ValueError(
"Amount of clusters (current value: '%d') should be greater than 0." %
158 raise ValueError(
"Amount of epouch (current value: '%d') should be greater or equal to 0." %
def predict(self, points)
Calculates the closest cluster to each point.
Represents self-organized feature map (SOM).
def get_cluster_encoding(self)
Returns clustering result representation type that indicate how clusters are encoded.
def __init__(self, data, amount_clusters, epouch=100, ccore=True, **kwargs)
Creates SOM-SC (Self Organized Map for Simple Clustering) algorithm for clustering analysis.
Class represents a simple clustering algorithm based on the self-organized feature map.
def __verify_arguments(self)
Verify input parameters for the algorithm and throw exception in case of incorrectness.
Neural Network: Self-Organized Feature Map.
def get_clusters(self)
Returns list of allocated clusters, each cluster contains indexes of objects in list of data.
def process(self)
Performs cluster analysis by competition between neurons in self-organized map.
Represents SOM parameters.
Module for representing clustering results.