Mini-batch K-means Clustering¶
Variant of the KMeans algorithm which uses mini-batches to reduce the computation time
Documentation
Variant of the KMeans algorithm which uses mini-batches to reduce the computation time
Configuration:
n_clusters
The number of clusters to form as well as the number of centroids to generate.
max_no_improvement
Control early stopping based on the consecutive number of mini batches that does not yield an improvement on the smoothed inertia.
To disable convergence detection based on inertia, set max_no_improvement to None.
batch_size
Size of the mini batches. For faster compuations, you can set the
batch_size
greater than 256 * number of cores to enable parallelism on all cores.Changed in version 1.0: batch_size default changed from 100 to 1024.
init
Method for initialization:
‘k-means++’ : selects initial cluster centers for k-mean clustering in a smart way to speed up convergence. See section Notes in k_init for more details.
‘random’: choose n_clusters observations (rows) at random from data for the initial centroids.
If an array is passed, it should be of shape (n_clusters, n_features) and gives the initial centers.
If a callable is passed, it should take arguments X, n_clusters and a random state and return an initialization.
compute_labels
Compute label assignment and inertia for the complete dataset once the minibatch optimization has converged in fit.
max_iter
Maximum number of iterations over the complete dataset before stopping independently of any early stopping criterion heuristics.
tol
Control early stopping based on the relative center changes as measured by a smoothed, variance-normalized of the mean center squared position changes. This early stopping heuristics is closer to the one used for the batch variant of the algorithms but induces a slight computational and memory overhead over the inertia heuristic.
To disable convergence detection based on normalized center change, set tol to 0.0 (default).
init_size
Number of samples to randomly sample for speeding up the initialization (sometimes at the expense of accuracy): the only algorithm is initialized by running a batch KMeans on a random subset of the data. This needs to be larger than n_clusters.
If None, the heuristic is init_size = 3 * batch_size if 3 * batch_size < n_clusters, else init_size = 3 * n_clusters.
n_init
Number of random initializations that are tried. In contrast to KMeans, the algorithm is only run once, using the best of the
n_init
initializations as measured by inertia.reassignment_ratio
Control the fraction of the maximum number of counts for a center to be reassigned. A higher value means that low count centers are more easily reassigned, which means that the model will take longer to converge, but should converge in a better clustering. However, too high a value may cause convergence issues, especially with a small batch size.
random_state
Determines random number generation for centroid initialization and random reassignment. Use an int to make the randomness deterministic. See random_state.
Attributes:
cluster_centers_
Coordinates of cluster centers.
labels_
Labels of each point (if compute_labels is set to True).
inertia_
The value of the inertia criterion associated with the chosen partition if compute_labels is set to True. If compute_labels is set to False, it’s an approximation of the inertia based on an exponentially weighted average of the batch inertiae. The inertia is defined as the sum of square distances of samples to their cluster center, weighted by the sample weights if provided.
Input ports:
- Output ports:
- modelmodel
Model
Definition
Input ports
Output ports
- model
model
Model
- class node_clustering.MiniBatchKMeansClustering[source]