fuzzyclust.large.WeightedFCM#

class fuzzyclust.large.WeightedFCM(n_clusters=3, m=2.0, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#

Bases: BaseFuzzyClusterer

Weighted fuzzy c-means (wFCM): fuzzy c-means with a weight per sample.

Every sample \(\mathbf{x}_k\) carries a non-negative weight \(w_k\) that counts how many observations it stands for. A sample with weight 2 has exactly the effect of two identical samples, so a weighted prototype (a cluster center summarizing a chunk of data) can be clustered together with raw samples. wFCM is the building block of the single-pass and online algorithms for very large data of Havens et al. (2012) and, with the gray-level histogram as weights, of the fast image segmentation algorithms of fuzzyclust.image.

Parameters:
n_clustersint, default=3

Number of clusters \(c\).

mfloat, default=2.0

Fuzziness exponent \(m>1\).

tolfloat, default=1e-4
max_iterint, default=300
init{“random”, “kmeans++”} or ndarray, default=”random”
n_initint, default=1

Random restarts; the run with the lowest final \(J\) is kept.

random_stateint, RandomState instance or None, default=None
verboseint, default=0
Attributes:
cluster_centers_ndarray of shape (n_clusters, n_features)
membership_ndarray of shape (n_samples, n_clusters)
labels_ndarray of shape (n_samples,)
distances_ndarray of shape (n_samples, n_clusters)
sample_weight_ndarray of shape (n_samples,)

The weights used in the fit.

objective_, objective_history_, n_iter_

See BaseFuzzyClusterer; \(J\) is the weighted functional below.

Notes

wFCM minimizes the weighted c-means functional

\[J_w(\mathbf{X};\mathbf{U},\mathbf{V})=\sum_{i=1}^{c}\sum_{k=1}^{N} w_k\,\mu_{ik}^m\,\norm{\mathbf{x}_k-\mathbf{v}_i}^2\]

by alternating the unchanged FCM membership formula (the weights cancel in the per-sample optimality condition) with the weighted prototype update

\[\mathbf{v}_i=\frac{\sum_{k=1}^{N} w_k\,\mu_{ik}^m\,\mathbf{x}_k} {\sum_{k=1}^{N} w_k\,\mu_{ik}^m} .\]

With all weights equal to one wFCM is FCM; with integer weights it is FCM on the data set in which sample \(k\) is repeated \(w_k\) times.

References

[1]

T. C. Havens, J. C. Bezdek, C. Leckie, L. O. Hall, M. Palaniswami, “Fuzzy c-means algorithms for very large data”, IEEE Transactions on Fuzzy Systems 20(6), 1130–1146, 2012.

[2]

J. C. Bezdek, “Pattern Recognition with Fuzzy Objective Function Algorithms”, Plenum Press, 1981.

Examples

>>> import numpy as np
>>> from fuzzyclust.large import WeightedFCM
>>> X = np.array([[0.0], [1.0], [9.0], [10.0]])
>>> w = np.array([1.0, 3.0, 1.0, 1.0])
>>> wfcm = WeightedFCM(n_clusters=2, random_state=0).fit(X, sample_weight=w)
>>> np.sort(wfcm.cluster_centers_.ravel()).round(2)
array([0.75, 9.5 ])
fit(X, y=None, sample_weight=None)[source]#

Compute the weighted clustering.

Parameters:
Xarray_like of shape (n_samples, n_features)
yIgnored
sample_weightarray_like of shape (n_samples,), default=None

Non-negative weights \(w_k\); None means all ones.

Returns:
selfobject
score(X, y=None, sample_weight=None)[source]#

Negative weighted functional \(-J_w\) on X (higher is better).

Examples using fuzzyclust.large.WeightedFCM#

Fuzzy c-means for very large data: rseFCM, spFCM and oFCM

Fuzzy c-means for very large data: rseFCM, spFCM and oFCM