Abstract
This paper shows that one can be competitive with the k-means objective while operating online. In this model, the algorithm receives vectors $v_1,...,v_n$ one by one in an arbitrary order. For each vector the algorithm outputs a cluster identifier before receiving the next one. Our online algorithm generates $\tilde{O}(k)$ clusters whose k-means cost is $\tilde{O}(W^*)$. Here, $W^*$ is the optimal k-means cost using $k$ clusters and $\tilde{O}$ suppresses poly-logarithmic factors. We also show that, experimentally, it is not much worse than k-means++ while operating in a strictly more constrained computational model.
Introduction
In traditional $k$-means clustering, the entire dataset is available upfront. While "streaming" models allow data to be processed sequentially, they often permit the algorithm to defer announcing cluster centers until the end of the stream. However, real-time applications such as news recommendation or fraud detection require an online approach: each data point must be assigned to a cluster immediately upon arrival.
This setting is challenging. A "stingy" approach that opens too few clusters early on may fail to account for later outliers, leading to high error. Conversely, opening too many clusters negates the benefits of data compression. This paper introduces an algorithm that makes immediate decisions while maintaining space and time complexity that grows only logarithmically with the stream length.
Methods
The proposed approach is inspired by Meyerson’s online facility location algorithm. The authors present two variants: a semi-online algorithm, which assumes prior knowledge of a lower bound for the optimal cost ($W^*$) and the total number of points ($n$), and a fully online algorithm that estimates these parameters dynamically.
The Doubling Strategy
The algorithm maintains a set of centers $C$. For each incoming point $v$, it calculates the squared distance to the nearest existing center, $D^2(v, C)$. A new cluster is opened at $v$ with a probability proportional to $D^2(v, C) / f_r$, where $f_r$ represents a "facility cost." If the number of open clusters exceeds a threshold (approximately $k \log n$), the algorithm concludes $f_r$ is too low, doubles it, and continues. This feedback loop allows the algorithm to adapt to the data scale without storing the entire history.
Experimental Setup
The algorithm was evaluated on 12 diverse datasets from the LibSvm and UCI repositories, including text (20news-binary), demographic (adult, poker), sensor (magic04, shuttle), and linguistic (maptaskcoref) data. These datasets range in dimensionality from 2 to over 60,000 features.
Results and Insights
A key theoretical finding is that online algorithms must be allowed to create slightly more than $k$ clusters to remain competitive. The authors' algorithm generates $\tilde{O}(k)$ clusters to achieve a cost comparable to offline $k$-means using exactly $k$ clusters.
Experimentally, the ratio between the actual number of clusters generated ($k_{actual}$) and the target ($k_{target}$) remains remarkably stable and close to 1.0 across different datasets, as shown in the figure above. Furthermore, the online algorithm performs nearly as well as the gold-standard offline algorithm, $k$-means++, despite the latter's ability to iterate over the entire dataset multiple times.
Applications in Feature Learning
Online $k$-means can serve as an effective "feature factory." By using the assigned cluster ID as a new feature for a linear classifier, significant improvements in accuracy were observed.
As detailed in the table above, the "shuttle" dataset saw classification accuracy rise from 0.9247 with raw features to 0.9973 with $k$-means features. Similar gains were noted for the "skin" and "poker" datasets.
Limitations and Future Work
While the fully online algorithm is robust, its theoretical cost guarantee is a factor of $\log n$ higher than the semi-online version. Future work may focus on closing this theoretical gap. Additionally, while $k$-means features improve accuracy, they increase the feature count, which can impact the convergence speed of downstream learners. Finally, the practical implementation relies on heuristic constants for cluster conversion; automating these parameters remains an open challenge.
Summary updated