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:
BaseFuzzyClustererWeighted 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_clusters
int, default=3 Number of clusters \(c\).
- m
float, default=2.0 Fuzziness exponent \(m>1\).
- tol
float, default=1e-4 - max_iter
int, default=300 - init{“random”, “kmeans++”}
orndarray, default=”random” - n_init
int, default=1 Random restarts; the run with the lowest final \(J\) is kept.
- random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- cluster_centers_
ndarrayofshape(n_clusters,n_features) - membership_
ndarrayofshape(n_samples,n_clusters) - labels_
ndarrayofshape(n_samples,) - distances_
ndarrayofshape(n_samples,n_clusters) - sample_weight_
ndarrayofshape(n_samples,) The weights used in the fit.
- objective_, objective_history_, n_iter_
See
BaseFuzzyClusterer; \(J\) is the weighted functional below.
- cluster_centers_
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
ofshape(n_samples,n_features) - y
Ignored - sample_weightarray_like
ofshape(n_samples,), default=None Non-negative weights \(w_k\);
Nonemeans all ones.
- Xarray_like
- Returns:
- self
object
- self
Examples using fuzzyclust.large.WeightedFCM#
Fuzzy c-means for very large data: rseFCM, spFCM and oFCM