Implementation
The scikit-learn package contains the MiniBatchKMeans algorithm, which allows online learning. This class implements a partial_fit function, which takes a set of samples and updates the model. In contrast, calling fit() will remove any previous training and refit the model only on the new data.
MiniBatchKMeans follows the same clustering format as other algorithms in scikit-learn, so creating and using it is much the same as other algorithms.
The algorithm works by taking a streaming average of all points that it has seen. To compute this, we only need to keep track of two values, which are the current sum of all seen points, and the number of points seen. We can then use this information, combined with a new set of points, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access