fuzzyclust.extensions.SCAD#
- class fuzzyclust.extensions.SCAD(n_clusters=3, m=2.0, variant='scad1', q=2.0, delta=None, delta_scale=1.0, tol=0.0001, max_iter=300, init='random', n_init=1, random_state=None, verbose=0)[source]#
Bases:
BaseFuzzyClustererSimultaneous clustering and attribute discrimination (Frigui & Nasraoui, 2004).
Every cluster \(i\) has its own vector of attribute weights \(\mathbf{w}_i=(w_{i1},\dots,w_{in})\), \(\sum_j w_{ij}=1\), that is learned together with the partition: the distance of a sample to a prototype is the weighted sum of the per-feature squared distances, and features that scatter the members of a cluster widely are down-weighted for that cluster. The weights make a cluster sensitive to the features that define it and let different clusters live in different subspaces; an irrelevant noise feature receives a small weight in every cluster. Two forms exist. SCAD-1 uses the weights linearly and keeps them away from the trivial crisp solution (all weight on the feature with the smallest scatter) by a quadratic regularization term with a cluster-specific coefficient \(\delta_i\), which may drive some weights to exactly zero. SCAD-2 raises the weights to an exponent \(q>1\) (like the fuzziness exponent for the memberships), needs no \(\delta_i\) and never gives zero weights.
- Parameters:
- n_clusters
int, default=3 Number of clusters \(c\).
- m
float, default=2.0 Fuzziness exponent \(m>1\).
- variant{“scad1”, “scad2”}, default=”scad1”
The regularized (SCAD-1) or the exponent (SCAD-2) form.
- q
float, default=2.0 Discrimination exponent of SCAD-2 (\(q>1\)); the closer to one, the sharper the weight vectors.
- delta
float, array_likeofshape(n_clusters,)orNone, default=None Regularization coefficients \(\delta_i\) of SCAD-1.
Nonere-estimates them from the current partition at every iteration as \(\delta_i=K\sum_k\mu_{ik}^m\sum_jw_{ij}d^2_{ikj}/\sum_jw_{ij}^2\) (the balance between the two terms of the functional, as proposed by the authors); a number or an array fixes them.- delta_scale
float, default=1.0 Factor \(K\) of the estimated \(\delta_i\) (SCAD-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_clusters,n_features) Attribute weights \(w_{ij}\) (rows sum to one).
- delta_
ndarrayofshape(n_clusters,) Coefficients \(\delta_i\) at convergence (SCAD-1; zeros for SCAD-2).
- 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
With the per-feature squared distances \(d^2_{ikj}=(x_{kj}-v_{ij})^2\), SCAD-1 minimizes
\[J_1=\sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}^m\sum_{j=1}^{n}w_{ij}\,d^2_{ikj} +\sum_{i=1}^{c}\delta_i\sum_{j=1}^{n}w_{ij}^2, \qquad \sum_j w_{ij}=1,\]whose weight update is
\[w_{ij}=\frac1n+\frac{1}{2\delta_i}\sum_{k=1}^{N}\mu_{ik}^m \Bigl(\frac1n\sum_{l=1}^{n}d^2_{ikl}-d^2_{ikj}\Bigr):\]the weight of feature \(j\) in cluster \(i\) is raised above \(1/n\) when the members of the cluster scatter less along \(j\) than on average; negative values are set to zero and the row is renormalized. SCAD-2 minimizes \(J_2=\sum_i\sum_k\mu_{ik}^m\sum_jw_{ij}^q d^2_{ikj}\) and gives
\[w_{ij}=\frac{1}{\sum_{l=1}^{n}\Bigl(\sum_k\mu_{ik}^md^2_{ikj}\big/ \sum_k\mu_{ik}^md^2_{ikl}\Bigr)^{1/(q-1)}} .\]In both forms the memberships follow the FCM formula with the weighted distance \(D^2_{ik}=\sum_jw_{ij}d^2_{ikj}\) (resp. \(w_{ij}^q\)) and the centers are the \(\mu^m\)-weighted means, since every coordinate of the center minimizes its own weighted sum of squares. The weights reward features with a small within-cluster scatter, so the features should be on comparable scales (standardize first): a feature with a much smaller variance than the others attracts the weight regardless of its relevance, because slicing it into \(c\) pieces gives a tiny scatter.
References
[1]H. Frigui, O. Nasraoui, “Unsupervised learning of prototypes and attribute weights”, Pattern Recognition 37(3), 567–581, 2004.
Examples
>>> import numpy as np >>> from fuzzyclust.extensions import SCAD >>> from fuzzyclust.datasets import make_fuzzy_blobs >>> X, _ = make_fuzzy_blobs(random_state=0) >>> rng = np.random.RandomState(0) >>> Xn = np.c_[X, 3.0 * rng.randn(X.shape[0])] # an irrelevant noise feature >>> scad = SCAD(n_clusters=3, random_state=0).fit(Xn) >>> bool((scad.feature_weights_[:, 2] < 0.2).all()) True
Examples using fuzzyclust.extensions.SCAD#
Learning which features matter: SCAD and the weighted FCM