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:
BaseFuzzyClustererRandom 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_clusters
int, default=3 Number of clusters \(c\).
- sample_size
intorfloat, default=0.1 Size \(n_s\) of the random sample: a number of samples or a fraction of
n_samples.- m
float, default=2.0 Fuzziness exponent \(m>1\).
- tol
float, default=1e-4 - max_iter
int, default=300 - init{“random”, “kmeans++”}
orndarray, default=”random” - n_init
int, default=1 Random restarts of the FCM run on the sample.
- chunk_size
intorNone, default=None Samples per chunk of the extension step (memory);
Noneextends all samples at once.- random_state
int,RandomStateinstanceorNone, default=None Controls the sample and the initialization.
- verbose
int, default=0
- n_clusters
- Attributes:
- sample_indices_
ndarrayofshape(n_sample,) Row indices of the sample.
- fcm_
FCM The clusterer fitted on the sample.
- cluster_centers_
ndarrayofshape(n_clusters,n_features) - membership_
ndarrayofshape(n_samples,n_clusters) Extended partition of all samples.
- labels_
ndarrayofshape(n_samples,) - distances_
ndarrayofshape(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.
- sample_indices_
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
ofshape(n_samples,n_features) - y
Ignored
- Xarray_like
- Returns:
- self
object
- self
Examples using fuzzyclust.large.RandomSampleFCM#
Fuzzy c-means for very large data: rseFCM, spFCM and oFCM