(self, data, initial_centers, **kwargs)
Initialize Fuzzy C-Means algorithm.
(self)
Returns allocated clusters that consists of points that most likely (in line with membership) belong to these clusters.
Class represents Fuzzy C-means (FCM) clustering algorithm.
Fuzzy clustering is a form of clustering in which each data point can belong to more than one cluster.
Fuzzy C-Means algorithm uses two general formulas for cluster analysis. The first is to updated membership of each point:
\[w_{ij}=\frac{1}{\sum_{k=0}^{c}\left ( \frac{\left \| x_{i}-c_{j} \right \|}{\left \| x_{i}-c_{k} \right \|} \right )^{\frac{2}{m-1}}}\]
The second formula is used to update centers in line with obtained centers:
\[c_{k}=\frac{\sum_{i=0}^{N}w_{k}\left ( x_{i} \right )^{m}x_{i}}{\sum_{i=0}^{N}w_{k}\left ( x_{i} \right )^{m}}\]
Fuzzy C-Means clustering results depend on initial centers. Algorithm K-Means++ can used for center initialization from module '
pyclustering.cluster.center_initializer
'.
CCORE implementation of the algorithm uses thread pool to parallelize the clustering process.
Here is an example how to perform cluster analysis using Fuzzy C-Means algorithm:
from
pyclustering.samples.definitions
import
FAMOUS_SAMPLES
sample =
read_sample
(FAMOUS_SAMPLES.SAMPLE_OLD_FAITHFUL)
initial_centers = kmeans_plusplus_initializer(sample, 2, kmeans_plusplus_initializer.FARTHEST_CENTER_CANDIDATE).initialize()
fcm_instance = fcm(sample, initial_centers)
fcm_instance.process()
clusters = fcm_instance.get_clusters()
centers = fcm_instance.get_centers()
visualizer = cluster_visualizer()
visualizer.append_clusters(clusters, sample)
visualizer.append_cluster(centers, marker=
'*'
, markersize=10)
visualizer.show()
The next example shows how to perform image segmentation using Fuzzy C-Means algorithm:
initial_centers = kmeans_plusplus_initializer(data, 3, kmeans_plusplus_initializer.FARTHEST_CENTER_CANDIDATE).initialize()
fcm_instance = fcm(data, initial_centers)
fcm_instance.process()
clusters = fcm_instance.get_clusters()
Image segmentation using Fuzzy C-Means algorithm.
Returns allocated clusters that consists of points that most likely (in line with membership) belong to these clusters.