fuzzyclust.incomplete.IncompleteFCM#

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

Bases: BaseFuzzyClusterer

Fuzzy c-means clustering of incomplete data (Hathaway and Bezdek, 2001).

Missing feature values are marked by NaN. Four strategies of running fuzzy c-means on such data are available (strategy):

"wds"

Whole-data strategy: samples with missing values are dropped and FCM is run on the complete samples only. The incomplete samples then receive memberships from their partial distances to the prototypes (the paper’s own suggestion for classifying them). Adequate when few samples are incomplete.

"pds"

Partial-distance strategy: every sample takes part, the distance to a prototype is the partial distance partial_distances() over the observed features (rescaled to the full dimension), and every prototype coordinate is the membership-weighted mean of the samples that observe it.

"ocs"

Optimal-completion strategy: the missing values are additional variables of the c-means functional. Each is updated to the value that minimizes \(J\) for the current partition, the membership-weighted mean of the prototype coordinates; FCM then runs on the completed data. OCS imputes the data as a by-product.

"nps"

Nearest-prototype strategy: like OCS, but a missing value is replaced by the coordinate of the nearest prototype of its sample (a hard version of OCS, cheaper and a little less accurate).

Parameters:
n_clustersint, default=3

Number of clusters \(c\).

mfloat, default=2.0

Fuzziness exponent \(m>1\).

strategy{“wds”, “pds”, “ocs”, “nps”}, default=”pds”

How the missing values are handled (see above).

tolfloat, default=1e-4

Termination tolerance on \(\max_{ik}|\Delta\mu_{ik}|\).

max_iterint, default=300
init{“random”, “kmeans++”} or ndarray, default=”random”

Initialization, see BaseFuzzyClusterer. It is computed on the data with the missing values provisionally filled by the feature means of the observed values.

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)

Prototypes \(\mathbf{v}_i\).

membership_ndarray of shape (n_samples, n_clusters)

Fuzzy partition \(\mathbf{U}^T\) of all samples (for "wds" the incomplete samples are classified by their partial distances after the fit).

labels_ndarray of shape (n_samples,)
distances_ndarray of shape (n_samples, n_clusters)

Distances at convergence: Euclidean on the completed data for "ocs"/"nps", partial distances otherwise.

missing_mask_ndarray of bool of shape (n_samples, n_features)

True where a value was missing.

n_missing_int

Number of missing values.

X_completed_ndarray of shape (n_samples, n_features)

The data with the missing values filled in. For "ocs" and "nps" these are the values the algorithm optimized; for "pds" and "wds" they are a post-hoc estimate by the OCS formula (membership-weighted prototype coordinates) from the final partition, not used by the algorithm.

covariances_ndarray of shape (n_clusters, n_features, n_features)

Fuzzy covariances of the final partition on the completed data.

objective_, objective_history_, n_iter_

See BaseFuzzyClusterer.

Notes

Let \(I_{kj}=1\) when \(x_{kj}\) is observed (0 when it is missing), \(I_k=\sum_j I_{kj}\), \(X_M\) the set of missing values and \(X_P\) the observed ones. The strategies optimize the c-means functional \(J=\sum_i\sum_k\mu_{ik}^m D^2_{ik}\) as follows.

PDS – the partial distance and the prototype update

\[D^2_{ik}=\frac{n}{I_k}\sum_{j=1}^{n}I_{kj}(x_{kj}-v_{ij})^2,\qquad v_{ij}=\frac{\sum_{k=1}^{N}\mu_{ik}^m I_{kj}\,x_{kj}}{\sum_{k=1}^{N}\mu_{ik}^m I_{kj}},\]

with the usual membership formula.

OCS – \(J\) is minimized over \((\mathbf{U},\mathbf{V},X_M)\); the necessary condition for a missing value is

\[x_{kj}=\frac{\sum_{i=1}^{c}\mu_{ik}^m v_{ij}}{\sum_{i=1}^{c}\mu_{ik}^m}, \qquad x_{kj}\in X_M ,\]

and the memberships and prototypes are those of FCM on the completed data. The three-block alternating optimization decreases \(J\) monotonically.

NPS – the missing value is set to the coordinate of the prototype nearest to the sample, \(x_{kj}=v_{ij}\) with \(i=\arg\min_l D^2_{lk}\), the nearest prototype being judged by the partial distance over the observed features.

WDS – plain FCM on the complete samples; the incomplete ones are classified afterwards with partial distances.

Hathaway and Bezdek ran the strategies on IRIS with 0–75 % of the values missing completely at random and compared the prototypes with those of FCM on the complete data: PDS and OCS were the most accurate, NPS close behind, and WDS degraded once a large share of the samples was affected; OCS has the extra merit of imputing the data. OCS and NPS change the data they cluster and therefore have more local optima than PDS – use n_init or start them from the PDS prototypes (init=pds.cluster_centers_) when the result matters.

References

[1]

R. J. Hathaway, J. C. Bezdek, “Fuzzy c-means clustering of incomplete data”, IEEE Transactions on Systems, Man, and Cybernetics, Part B 31(5), 735–744, 2001.

[2]

J. K. Dixon, “Pattern recognition with partly missing data”, IEEE Transactions on Systems, Man, and Cybernetics 9(10), 617–621, 1979.

Examples

>>> import numpy as np
>>> from fuzzyclust.datasets import make_fuzzy_blobs
>>> from fuzzyclust.incomplete import IncompleteFCM, make_mcar
>>> X, _ = make_fuzzy_blobs(random_state=0)
>>> Xm = make_mcar(X, missing_rate=0.2, random_state=0)
>>> model = IncompleteFCM(n_clusters=3, strategy="ocs", random_state=0).fit(Xm)
>>> model.membership_.shape, bool(np.isnan(model.X_completed_).any())
((300, 3), False)
fit(X, y=None)[source]#

Cluster incomplete data (NaN marks a missing value).

Parameters:
Xarray_like of shape (n_samples, n_features)

Data with NaN for missing values. Every sample must observe at least one feature and every feature must be observed at least once.

yIgnored
Returns:
selfobject
predict_proba(X)[source]#

Memberships of (possibly incomplete) new samples from their partial distances.

Returns:
Undarray of shape (n_samples, n_clusters)
score(X, y=None)[source]#

Negative c-means functional with partial distances on X (higher is better).

transform(X)[source]#

Partial distances \(D_{ik}\) of (possibly incomplete) samples to the prototypes.

Examples using fuzzyclust.incomplete.IncompleteFCM#

Clustering incomplete data: the four strategies of Hathaway and Bezdek

Clustering incomplete data: the four strategies of Hathaway and Bezdek

Imputation by clustering: accuracy of the completed values

Imputation by clustering: accuracy of the completed values