fuzzyclust.relational.FuzzyKModes#

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

Bases: FuzzyKPrototypes

Fuzzy k-modes clustering of categorical data (Huang and Ng, 1999).

Every attribute is categorical, the dissimilarity between two records is the number of attributes in which they differ (simple matching), and the prototype of a cluster is its mode: per attribute the category that carries the largest membership mass. The algorithm is FuzzyKPrototypes with all columns categorical and \(\gamma=1\), i.e. the fuzzy c-means functional with the matching dissimilarity

\[J=\sum_{i=1}^{c}\sum_{k=1}^{N}\mu_{ik}^m\sum_{j=1}^{n}\delta(x_{kj},v_{ij}),\]

minimized by alternating the FCM membership formula (with the dissimilarity in the role of \(D^2_{ik}\); \(\mu_{ik}=1\) when the record is the mode) and the mode update of Huang and Ng’s theorem. Because the dissimilarity is integer-valued, many records are equally far from several modes and the partition is fuzzier than that of FCM on numeric data; the exponent \(m\) should be kept small (Huang and Ng use \(m\approx1.1\)–$2$), and ties in the mode update are resolved by the first category in the encoder’s order.

Parameters:
n_clustersint, default=3
mfloat, default=1.5

Fuzziness exponent \(m>1\).

tol, max_iter, init, n_init, random_state, verbose

See FuzzyKPrototypes.

Attributes:
modes_pandas.DataFrame or ndarray of shape (n_clusters, n_features)

The modes with the original category labels (same as prototypes_).

cluster_centers_ndarray of shape (n_clusters, n_features)

The modes as integer codes (stored as floats).

categories_, membership_, labels_, distances_, objective_, objective_history_, n_iter_

See FuzzyKPrototypes.

References

[1]

Z. Huang, M. K. Ng, “A fuzzy k-modes algorithm for clustering categorical data”, IEEE Transactions on Fuzzy Systems 7(4), 446–452, 1999.

[2]

Z. Huang, “Extensions to the k-means algorithm for clustering large data sets with categorical values”, Data Mining and Knowledge Discovery 2(3), 283–304, 1998.

Examples

>>> from fuzzyclust.relational import FuzzyKModes, make_categorical_blobs
>>> data = make_categorical_blobs(random_state=0)
>>> km = FuzzyKModes(n_clusters=3, random_state=0).fit(data.data)
>>> km.modes_.shape, km.membership_.shape
((3, 6), (300, 3))

Examples using fuzzyclust.relational.FuzzyKModes#

Fuzzy k-modes on categorical survey data

Fuzzy k-modes on categorical survey data

Fuzzy k-prototypes on mixed numeric and categorical data

Fuzzy k-prototypes on mixed numeric and categorical data