fuzzyclust.extensions.FeatureWeightedFCM#
- class fuzzyclust.extensions.FeatureWeightedFCM(n_clusters=3, m=2.0, t=2.0, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#
Bases:
BaseFuzzyClustererFuzzy c-means with global attribute weights (after Huang et al., 2005).
One weight vector \(\boldsymbol\alpha=(\alpha_1,\dots,\alpha_n)\), \(\sum_j\alpha_j=1\), shared by all clusters, scales the features in the distance, and the weights are optimized together with the partition. A feature along which the clusters are poorly separated—so that the members scatter widely about their prototypes—receives a small weight, and the clustering effectively runs in the subspace of the informative features. The exponent \(t>1\) on the weights plays the role of the fuzziness exponent: the closer to one, the more the weight concentrates on the single best feature.
- Parameters:
- n_clusters
int, default=3 Number of clusters \(c\).
- m
float, default=2.0 Fuzziness exponent \(m>1\).
- t
float, default=2.0 Weight exponent \(t>1\).
- tol
float, default=1e-4 - max_iter
int, default=300 - init{“random”, “kmeans++”}
orndarray, default=”random” - n_init
int, default=1 - random_state
int,RandomStateinstanceorNone, default=None - verbose
int, default=0
- n_clusters
- Attributes:
- cluster_centers_
ndarrayofshape(n_clusters,n_features) - feature_weights_
ndarrayofshape(n_features,) Global attribute weights \(\alpha_j\) (sum to one).
- membership_, labels_, distances_, objective_, objective_history_, n_iter_
See
BaseFuzzyClusterer;distances_andtransformreturn the weighted distances.- covariances_
ndarrayofshape(n_clusters,n_features,n_features) Fuzzy covariance matrices of the final partition (unweighted).
- cluster_centers_
Notes
The functional is
\[J=\sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}^m\sum_{j=1}^{n}\alpha_j^t\,(x_{kj}-v_{ij})^2, \qquad\sum_{j=1}^{n}\alpha_j=1,\]and the Lagrange conditions give, next to the FCM membership formula with the weighted distance and the fuzzy means for the centers,
\[\alpha_j=\frac{1}{\sum_{l=1}^{n}\Bigl(\sum_{i,k}\mu_{ik}^md^2_{ikj}\big/ \sum_{i,k}\mu_{ik}^md^2_{ikl}\Bigr)^{1/(t-1)}},\]the same form as the membership formula with the total scatter along a feature in place of the distance to a prototype. The weights are the diagonal of a norm-inducing matrix \(\mathbf{A}=\diag(\alpha_j^t)\) learned from the data, so the method sits between FCM with the diagonal norm (fixed, from the feature variances) and GK (full, cluster-specific). As with SCAD the features should be standardized first, because a feature of small variance attracts the weight. Keller and Klawonn use the same kind of weights per cluster.
References
[1]J. Z. Huang, M. K. Ng, H. Rong, Z. Li, “Automated variable weighting in k-means type clustering”, IEEE Transactions on Pattern Analysis and Machine Intelligence 27(5), 657–668, 2005.
[2]A. Keller, F. Klawonn, “Fuzzy clustering with weighting of data variables”, International Journal of Uncertainty, Fuzziness and Knowledge-Based Systems 8(6), 735–746, 2000.
Examples
>>> import numpy as np >>> from fuzzyclust.extensions import FeatureWeightedFCM >>> from fuzzyclust.datasets import make_fuzzy_blobs >>> X, _ = make_fuzzy_blobs(random_state=0) >>> Xn = np.c_[X, 3.0 * np.random.RandomState(0).randn(X.shape[0])] >>> wfcm = FeatureWeightedFCM(n_clusters=3, random_state=0).fit(Xn) >>> int(wfcm.feature_weights_.argmin()) 2
Examples using fuzzyclust.extensions.FeatureWeightedFCM#
Learning which features matter: SCAD and the weighted FCM