Clustering, density estimation, and anomaly detection · Partition clustering · UCL002 · Algorithm
Mini-batch K-means
Approximate K-means using small stochastic batches, reducing computation for large numerical datasets or incremental processing. This is a distinct optimization algorithm, not a different probabilistic cluster family.
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page.
- k-means clustering Verified in Python and R
Do it in CodeSplash Run it on your own data, in Python or R.
- Availability
- Runs in CodeSplash
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through discover.kmeans. The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Approximate K-means using small stochastic batches, reducing computation for large numerical datasets or incremental processing. This is a distinct optimization algorithm, not a different probabilistic cluster family.
Question / hypotheses
Which partition best represents the chosen distance-based notion of within-group similarity? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.
Architecture / computational structure
Mini-batch assignment and count-weighted centroid updates, with a small retained centroid state.
Assumptions
Representative batches matter: time-sorted or subgroup-skewed batches can bias early centroids. The running-average update does not automatically solve concept drift because its learning rate decays.
Formula / computational definition
For a point assigned to centroid , update , with for the running number of assigned observations in the basic scheme. The target remains the full-data squared-distance objective, although stochastic steps need not decrease it every iteration.
Parameters and notation
Learned or fitted quantities: Centroids, cluster counts used by updates, and final labels. User-set hyperparameters/design choices: Batch size, initialization sample, reassignment ratio, stopping patience, and number of passes determine the speed–accuracy tradeoff. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.
Fitting, fine-tuning, and adaptation
Mini-batch updates can continue with new observations through the documented incremental API. A decaying count-based rate retains long memory; if drift is expected, use a deliberate refitting window or explicitly modified forgetting rule and validate it separately.
How to use and calibrate
Score final centroids on a common held-out sample; compare inertia, cluster occupancy, stability, wall time, and memory with full K-means. Report the sampling strategy as well as the seed.
Example application
Compress millions of sensor vectors into representative prototypes. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.
Interpretation / pitfalls
Watch out
The reported result is conditional on the representation and objective. A stable partition can reflect nuisance structure such as batch, collection site, or missingness. Confirm the interpretation in original variables and an independent sample.
Python and R code examples
Python has MiniBatchKMeans and partial_fit. R can call that verified implementation through reticulate; a native custom streaming loop must track assignments, centroid counts, and reassignment explicitly.
Component: One running-centroid update. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — One running-centroid update. · needs numpy
import numpy as np
center=np.array([2.,4.]); new=np.array([6.,2.]); count=4
result=center+(new-center)/(count+1)
print(result)
Component demo, not a trained model — One running-centroid update.
center=c(2,4); new=c(6,2); count=4
result=center+(new-center)/(count+1)
print(result)
Sources
- Source 1scikit-learn.org
From the CodeSplash reference, entry UCL002.