fuzzyclust.large.OnlineFCM#

class fuzzyclust.large.OnlineFCM(n_clusters=3, chunk_size=10000, m=2.0, tol=0.0001, max_iter=300, init='random', n_init=1, chunk_init='previous', shuffle=True, random_state=None, verbose=0)[source]#

Bases: BaseFuzzyClusterer

Online fuzzy c-means (oFCM) for very large and streaming data.

Every chunk is clustered on its own with FCM; the \(c\) prototypes of each chunk, weighted by the total membership they collected, are kept. When all chunks have been seen, the \(s\cdot c\) weighted prototypes are clustered into \(c\) clusters with weighted FCM (WeightedFCM), and the partition of all samples is obtained by one extension step. In contrast to SinglePassFCM the chunks do not influence each other, so the chunk clusterings can run in parallel or arrive from a stream in any order; the price is the storage of \(s\cdot c\) prototypes and the final clustering of them (Hore et al. 2009; Havens et al. 2012).

Parameters:
n_clustersint, default=3

Number of clusters \(c\).

chunk_sizeint, default=10000

Samples per chunk \(n_l\).

mfloat, default=2.0

Fuzziness exponent \(m>1\).

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

Initialization of the FCM run on the first chunk.

n_initint, default=1

Random restarts of the first chunk.

chunk_init{“previous”, “independent”}, default=”previous”

Start the FCM run on a chunk from the prototypes of the previous chunk (fewer iterations, aligned cluster order) or from a fresh initialization with init/n_init (fully independent chunk clusterings, as in the original formulation).

shufflebool, default=True

Randomly permute the samples before chunking in fit; partial_fit never reorders.

random_stateint, RandomState instance or None, default=None
verboseint, default=0
Attributes:
cluster_centers_ndarray of shape (n_clusters, n_features)

The prototypes of the final weighted clustering of the chunk prototypes.

center_weights_ndarray of shape (n_clusters,)

Weight (number of observations) collected by every final prototype.

chunk_centers_ndarray of shape (n_chunks, n_clusters, n_features)

Prototypes of every chunk.

chunk_weights_ndarray of shape (n_chunks, n_clusters)

Weights \(w_{li}=\sum_k\mu_{ik}\) of the chunk prototypes.

chunk_objective_, chunk_n_iter_ndarray of shape (n_chunks,)
n_chunks_int
centers_model_WeightedFCM or None

The final weighted clusterer of the chunk prototypes (None after a single chunk, when there is nothing to merge).

membership_ndarray of shape (n_samples, n_clusters)

Extended partition of the data passed to fit (after partial_fit: of the last chunk).

labels_, distances_, objective_

Of the extended partition.

objective_history_ndarray

\(J_w\) per iteration of the final weighted clustering.

n_iter_int

Iterations of the final weighted clustering.

Notes

\[\begin{split}(\mathbf{U}_l,\mathbf{V}_l)&=\text{FCM}(\mathbf{X}_l),\qquad w_{li}=\sum_{k}\mu_{l,ik},\qquad l=1,\dots,s,\\ \mathbf{V}&=\text{wFCM}\big([\mathbf{V}_1;\dots;\mathbf{V}_s],\ [\mathbf{w}_1;\dots;\mathbf{w}_s]\big),\\ \mathbf{U}&=\text{extend}(\mathbf{X},\mathbf{V}).\end{split}\]

The final weighted clustering is initialized with the prototypes of the last chunk. partial_fit() appends the prototypes of a new chunk and repeats the (cheap) final clustering, so the model is usable after every chunk of a stream.

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.

[2]

P. Hore, L. O. Hall, D. B. Goldgof, Y. Gu, A. A. Maudsley, A. Darkazanli, “A scalable framework for segmenting magnetic resonance images”, Journal of Signal Processing Systems 54(1–3), 183–203, 2009.

Examples

>>> from fuzzyclust.large import OnlineFCM, make_large_blobs
>>> X, y = make_large_blobs(n_samples=5000, n_clusters=3, random_state=0)
>>> of = OnlineFCM(n_clusters=3, chunk_size=1000, random_state=0).fit(X)
>>> of.n_chunks_, of.chunk_weights_.shape, of.membership_.shape
(5, (5, 3), (5000, 3))
fit(X, y=None)[source]#

Cluster every chunk, cluster the weighted chunk prototypes, extend to all samples.

Parameters:
Xarray_like of shape (n_samples, n_features)
yIgnored
Returns:
selfobject
partial_fit(X, y=None)[source]#

Add one chunk of a stream: cluster it, store its weighted prototypes, update the model.

membership_ and labels_ refer to the chunk just processed; use predict_proba() for other data.

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

Examples using fuzzyclust.large.OnlineFCM#

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

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

Clustering a drifting stream chunk by chunk with partial_fit

Clustering a drifting stream chunk by chunk with partial_fit