fuzzyclust.large.RandomSampleFCM#

class fuzzyclust.large.RandomSampleFCM(n_clusters=3, sample_size=0.1, m=2.0, tol=0.0001, max_iter=300, init='random', n_init=1, chunk_size=None, random_state=None, verbose=0)[source]#

Bases: BaseFuzzyClusterer

Random sample and extend FCM (rseFCM) for very large data.

The simplest way to cluster more data than FCM can iterate over: draw a random sample of \(n_s\ll N\) observations, run FCM on the sample, and extend the result to all \(N\) samples with one membership step from the fixed prototypes (extend_partition()). Havens et al. (2012) use rseFCM as the baseline of their study of FCM for very large data: it is the fastest of the schemes, and when the clusters are well represented in a random sample its partition is practically that of FCM on the full data.

Parameters:
n_clustersint, default=3

Number of clusters \(c\).

sample_sizeint or float, default=0.1

Size \(n_s\) of the random sample: a number of samples or a fraction of n_samples.

mfloat, default=2.0

Fuzziness exponent \(m>1\).

tolfloat, default=1e-4
max_iterint, default=300
init{“random”, “kmeans++”} or ndarray, default=”random”
n_initint, default=1

Random restarts of the FCM run on the sample.

chunk_sizeint or None, default=None

Samples per chunk of the extension step (memory); None extends all samples at once.

random_stateint, RandomState instance or None, default=None

Controls the sample and the initialization.

verboseint, default=0
Attributes:
sample_indices_ndarray of shape (n_sample,)

Row indices of the sample.

fcm_FCM

The clusterer fitted on the sample.

cluster_centers_ndarray of shape (n_clusters, n_features)
membership_ndarray of shape (n_samples, n_clusters)

Extended partition of all samples.

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

\(J\) of the extended partition on the full data.

objective_history_ndarray

\(J\) per iteration of the FCM run on the sample.

n_iter_int

Iterations of the FCM run on the sample.

Notes

rseFCM has no approximation guarantee: a cluster that is rare in the data may be missed by the sample. Its cost is one FCM run on \(n_s\) samples plus one pass over the data, \(O(n_s c\,l + N c)\).

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.

Examples

>>> from fuzzyclust.large import RandomSampleFCM, make_large_blobs
>>> X, y = make_large_blobs(n_samples=5000, n_clusters=3, random_state=0)
>>> rse = RandomSampleFCM(n_clusters=3, sample_size=500, random_state=0).fit(X)
>>> rse.sample_indices_.shape, rse.membership_.shape
((500,), (5000, 3))
fit(X, y=None)[source]#

Cluster a random sample with FCM and extend the partition to all samples.

Parameters:
Xarray_like of shape (n_samples, n_features)
yIgnored
Returns:
selfobject

Examples using fuzzyclust.large.RandomSampleFCM#

Fuzzy c-means for very large data: rseFCM, spFCM and oFCM

Fuzzy c-means for very large data: rseFCM, spFCM and oFCM