Web-scale k-means clustering

D. Sculley

article2010WWW1,349 citations

Proposes a mini-batch optimization and fast L1 projection method for k-means clustering that reduces computational cost by orders of magnitude on massive datasets while maintaining solution quality and producing compact, sparse cluster centers.

Listen

Modern web-based systems rely heavily on unsupervised clustering for tasks like grouping search results, aggregating news stories, and detecting near-duplicate content. While classic batch k-means remains the industry standard, its high computational cost makes it too slow for large datasets in user-facing applications that demand sub-second response times. Online stochastic gradient descent offers faster execution but produces significantly lower-quality groupings due to random noise. High dimensionality also creates bulky cluster centers that incur heavy storage and network transfer penalties.

The article demonstrates two enhancements to overcome these scalability barriers: a mini-batch optimization technique for k-means clustering and an efficient approximation method to enforce sparsity in cluster centers. The goal is to dramatically lower processing latency and memory footprints while retaining near-optimal clustering quality.

The author evaluated this approach using the benchmark RCV1 text document collection, training on 781,265 examples and evaluating on 23,149 held-out test documents across different cluster counts. The mini-batch algorithm was compared against standard batch k-means and single-example stochastic gradient descent. Additionally, the author tested an approximate bisection projection against an existing linear-time projection method to assess execution time, non-zero feature counts, and clustering accuracy.

The evaluation revealed three key findings. First, mini-batch k-means converged to near-optimal cluster centers orders of magnitude faster than classic batch k-means, processing nearly one million documents in a fraction of a CPU second on a standard single machine. Second, mini-batch updates significantly outperformed online stochastic gradient descent in solution quality by reducing noise while avoiding the computational overhead of redundant data. Third, the proposed approximate projection method reduced execution time by more than 500-fold compared to full-batch clustering (0.19–0.27 seconds versus 133.96 seconds) and reduced non-zero features from over 200,000 down to roughly 2,500 to 44,000, incurring only a negligible increase in test error.

These results demonstrate that organizations can deploy high-quality, real-time clustering directly in latency-critical web products without expensive distributed computing hardware. The resulting sparsity drastically cuts memory usage and network bandwidth when transmitting cluster models across distributed systems. Operating teams can achieve these benefits using standard commodity servers.

Engineering teams supporting large-scale text or web clustering applications should adopt mini-batch k-means to optimize latency and operational costs. For systems with constrained storage or high network distribution demands, teams should implement projected gradient descent using the approximate bisection method. System architects can tune the batch size and sparsity parameters depending on whether their primary constraint is training speed or absolute cluster fidelity.

The findings are demonstrated on text categorization data and may vary with data modalities exhibiting different distribution characteristics. While confidence in the performance gains is high due to consistent experimental results and open-source availability, organizations should run initial pilot benchmarks on their specific domain data before full production deployment.

Sculley (2010).pdf
Cover for Web-scale k-means clustering

Abstract

We present two modifications to the popular k-means clustering algorithm to address the extreme requirements for latency, scalability, and sparsity encountered in user-facing web applications. First, we propose the use of mini-batch optimization for k-means clustering. This reduces computation cost by orders of magnitude compared to the classic batch algorithm while yielding significantly better solutions than online stochastic gradient descent. Second, we achieve sparsity with projected gradient descent, and give a fast ϵ-accurate projection onto the L1-ball. Source code is freely available: http://code.google.com/p/sofia-ml

Table of Contents

  • Categories and Subject Descriptors
  • General Terms
  • Keywords
  • 1. CLUSTERING AND THE WEB
  • 2. MINI-BATCH K-MEANS
  • 3. SPARSE CLUSTER CENTERS
  • 4. REFERENCES

Knowls

  1. Knowl 1 — Mini-Batch k-Means Algorithm

    algorithm

    Mini-Batch kk-Means optimizes the standard kk-means objective by taking stochastic gradient descent steps over small random subsets of examples rather than single examples or the entire dataset. It tracks per-center sample counts to maintain per-center learning rates, reducing stochastic noise relative to single-sample online stochastic gradient descent while avoiding full batch passes over large datasets.

    Input: Number of clusters kk, mini-batch size bb, iteration limit tt, dataset X⊂RmX \subset \mathbb{R}^m
    Output: Set of cluster centers C={c1,…,ck}⊂RmC = \{c_1, \dots, c_k\} \subset \mathbb{R}^m
    Initialize each c∈Cc \in C with an example picked uniformly at random from XX
    Initialize per-center counts v[c]←0v[c] \leftarrow 0 for each c∈Cc \in C
    for i=1i = 1 to tt do
        M←M \leftarrow sample of bb examples picked uniformly at random from XX
        for each x∈Mx \in M do
            d[x]←arg⁡min⁡c∈C∥c−x∥2d[x] \leftarrow \arg\min_{c \in C} \|c - x\|_2
        end for
        for each x∈Mx \in M do
            c←d[x]c \leftarrow d[x]
            v[c]←v[c]+1v[c] \leftarrow v[c] + 1
            η←1v[c]\eta \leftarrow \frac{1}{v[c]}
            c←(1−η)c+ηxc \leftarrow (1 - \eta)c + \eta x
        end for
    end for
    return CC

    Nearest-center assignments are cached for the entire mini-batch prior to updating cluster centers to prevent within-batch assignment drift. The per-center learning rate η=1v[c]\eta = \frac{1}{v[c]} ensures that each center update corresponds to an exact running average of all data points assigned to that center over the course of training.

  2. Knowl 2 — Fast Approximate L1-Ball Projection (epsilon-L1)

    algorithm

    The ϵ\epsilon-L1 algorithm projects a vector c∈Rmc \in \mathbb{R}^m onto an L1L_1-ball of radius λ>0\lambda > 0 within a multiplicative tolerance parameter ϵ>0\epsilon > 0, yielding a projected vector whose L1L_1 norm lies in the interval [λ,λ(1+ϵ)][\lambda, \lambda(1 + \epsilon)]. It employs bisection search to determine the soft-thresholding parameter θ\theta.

    Input: Vector c∈Rmc \in \mathbb{R}^m, target L1L_1 radius λ>0\lambda > 0, tolerance ϵ>0\epsilon > 0
    Output: Projected sparse vector c∈Rmc \in \mathbb{R}^m
    if ∥c∥1≤λ+ϵ\|c\|_1 \le \lambda + \epsilon then
        return cc
    end if
    upper ←∥c∥∞\leftarrow \|c\|_\infty
    lower ←0\leftarrow 0
    current ←∥c∥1\leftarrow \|c\|_1
    while current >λ(1+ϵ)> \lambda(1 + \epsilon) or current <λ< \lambda do
        θ←upper+lower2.0\theta \leftarrow \frac{\text{upper} + \text{lower}}{2.0}
        current ←∑i:ci≠0max⁡(0,∣ci∣−θ)\leftarrow \sum_{i: c_i \neq 0} \max(0, |c_i| - \theta)
        if current ≤λ\le \lambda then
            upper ←θ\leftarrow \theta
        else
            lower ←θ\leftarrow \theta
        end if
    end while
    for i=1i = 1 to mm do
        ci←sign(ci)⋅max⁡(0,∣ci∣−θ)c_i \leftarrow \text{sign}(c_i) \cdot \max(0, |c_i| - \theta)
    end for
    return cc

    Compared to exact linear-time L1L_1 projection methods that require order statistics or sorting, the bisection approach requires only basic sequential array scans and is faster in practical execution due to favorable memory access patterns.

  3. Knowl 3 — Sparse Mini-Batch k-Means via Projected Gradient Descent

    model/method

    In high-dimensional applications such as document clustering, feature frequencies often follow power-law distributions, causing standard cluster centers to contain many near-zero values for rare terms. Sparse cluster centers reduce storage requirements and network transmission overhead.

    Sparse mini-batch kk-means incorporates sparsity constraints through projected gradient descent: following each mini-batch gradient step, every cluster center c∈Cc \in C is projected onto an L1L_1-ball of radius λ>0\lambda > 0:

    c←arg⁡min⁡c′∈Rm,∥c′∥1≤λ∥c′−c∥22c \leftarrow \arg\min_{c' \in \mathbb{R}^m, \|c'\|_1 \le \lambda} \|c' - c\|_2^2

    This projection step can be executed either using an exact linear-time L1L_1 projection algorithm or via the approximate ϵ\epsilon-L1 bisection procedure.

  4. Knowl 4 — Empirical Convergence Speed and Quality of Mini-Batch k-Means on RCV1

    empirical result

    Mini-Batch kk-Means with batch size b=1000b = 1000 was evaluated on the RCV1 text classification benchmark (781,265 training examples and 23,149 test examples) against Lloyd's classic batch kk-means algorithm and online stochastic gradient descent (SGD, batch size b=1b = 1) across cluster counts k∈{3,10,50}k \in \{3, 10, 50\}, initialized with identical random seeds.

    1. Computation Speed: Mini-Batch kk-Means converged several orders of magnitude faster than full batch kk-means, computing high-quality cluster centers for nearly one million documents in a fraction of a CPU second on a standard 2.4 GHz processor. It also executed multiple times faster than batch kk-means accelerated via triangle inequalities.
    2. Clustering Quality: Mini-Batch kk-Means achieved significantly lower test objective error than online single-sample SGD, which suffered from persistent stochastic variance and converged to poorer local optima.
  5. Knowl 5 — Comparison of L1-Constrained Mini-Batch k-Means Methods on RCV1

    data/table

    Sparse mini-batch kk-means was evaluated on the RCV1 dataset (781,265 training examples, 23,149 test examples) with k=10k = 10 clusters, mini-batch size b=1000b = 1000, t=16t = 16 iterations, and projection tolerance ϵ=0.01\epsilon = 0.01. The table compares unconstrained full batch kk-means, mini-batch kk-means with exact linear-time L1L_1-ball projection (LTL1P), and mini-batch kk-means with approximate bisection projection (ϵ\epsilon-L1) across two L1L_1 radii λ∈{5.0,1.0}\lambda \in \{5.0, 1.0\}:

    Method λ\lambda # Non-zeros Test Objective CPU Seconds
    Full batch – 200,319 0 (baseline) 133.96
    LTL1P 5.0 46,446 .004 (.002–.006) 0.51
    ϵ\epsilon-L1 5.0 44,060 .007 (.005–.008) 0.27
    LTL1P 1.0 3,181 .018 (.016–.019) 0.48
    ϵ\epsilon-L1 1.0 2,547 .028 (.027–.029) 0.19

    The test objective column reports fractional error relative to the converged full batch baseline, including the mean and 95% range across trials.

    The results show that L1L_1 projection reduces non-zero feature entries by 77% to over 98% with less than 3% degradation in test objective value. Furthermore, the approximate ϵ\epsilon-L1 projection runs roughly twice as fast as the exact LTL1P projection algorithm (0.19--0.27 CPU seconds versus 0.48--0.51 CPU seconds) and yields sparser cluster representations.

Coverage note — No substantial contributed material was omitted; all algorithms, methods, and empirical comparisons from the paper are represented.

References

  1. 1.L. Bottou and Y. Bengio. Convergence properties of the kmeans algorithm. In Advances in Neural Information Processing Systems. 1995.
  2. 2.J. Duchi, S. Shalev-Shwartz, Y. Singer, and T. Chandra. Efficient projections onto the l1l_1-ball for learning in high dimensions. In ICML '08: Proceedings of the 25th international conference on Machine learning, 2008.
  3. 3.C. Elkan. Using the triangle inequality to accelerate k-means. In ICML '03: Proceedings of the 20th international conference on Machine learning, 2003.
  4. 4.D. D. Lewis, Y. Yang, T. G. Rose, and F. Li. Rcv1: A new benchmark collection for text categorization research. J. Mach. Learn. Res., 5, 2004.
  5. 5.D. Witten and R. Tibshirani. A framework for feature selection in clustering. To Appear: Journal of the American Statistical Association, 2010.
  6. 6.X. Wu and V. Kumar. The Top Ten Algorithms in Data Mining. Chapman & Hall/CRC, 2009.

Citation

MLA
Sculley, D. “Web-scale K-means Clustering”. Proceedings of the 19th International Conference on World Wide Web, 2010, pp. 1177–78, https://doi.org/10.1145/1772690.1772862.
APA
Sculley, D. (2010). Web-scale k-means clustering. Proceedings of the 19th International Conference on World Wide Web, 1177–1178. https://doi.org/10.1145/1772690.1772862
Chicago
Sculley, D. 2010. “Web-scale K-means Clustering”. Proceedings of the 19th International Conference on World Wide Web, 1177–78. https://doi.org/10.1145/1772690.1772862.
Harvard
Sculley, D. (2010) “Web-scale k-means clustering”, Proceedings of the 19th international conference on World wide web. ACM, pp. 1177–1178. Available at: https://doi.org/10.1145/1772690.1772862.
Vancouver
1. Sculley D (2010) Web-scale k-means clustering. In: Proceedings of the 19th international conference on World wide web. ACM, pp 1177–1178

BibTeX

@inproceedings{Sculley_2010, series={WWW ’10}, title={Web-scale k-means clustering}, url={http://dx.doi.org/10.1145/1772690.1772862}, DOI={10.1145/1772690.1772862}, booktitle={Proceedings of the 19th international conference on World wide web}, publisher={ACM}, author={Sculley, D.}, year={2010}, month=Apr, pages={1177–1178}, collection={WWW ’10} }
Metadata:Crossref

Access the Paper

This paper is available from its original source. Click below to access the PDF.

Open PDF