{"title": "Stability of $K$-Means Clustering", "book": "Advances in Neural Information Processing Systems", "page_first": 1121, "page_last": 1128, "abstract": null, "full_text": "Stability of K -Means Clustering\nAlexander Rakhlin Department of Computer Science UC Berkeley Berkeley, CA 94720 rakhlin@cs.berkeley.edu Andrea Caponnetto Department of Computer Science University of Chicago Chicago, IL 60637 and ` D.I.S.I., Universita di Genova, Italy caponnet@uchicago.edu\n\nAbstract\nWe phrase K -means clustering as an empirical risk minimization procedure over a class HK and explicitly calculate the covering number for this class. Next, we show that stability of K -means clustering is characterized by the geometry of HK with respect to the underlying distribution. We prove that in the case of a unique global minimizer, the clustering solution is stable with respect to complete changes of the data, while for the case of multiple minimizers, the change of (n1/2 ) samples defines the transition between stability and instability. While for a finite number of minimizers this result follows from multinomial distribution estimates, the case of infinite minimizers requires more refined tools. We conclude by proving that stability of the functions in HK implies stability of the actual centers of the clusters. Since stability is often used for selecting the number of clusters in practice, we hope that our analysis serves as a starting point for finding theoretically grounded recipes for the choice of K .\n\n1\n\nIntroduction\n\nIdentification of clusters is the most basic tool for data analysis and unsupervised learning. While people are extremely good at pointing out the relevant structure in the data just by looking at the 2-D plots, learning algorithms struggle to match this performance. Part of the difficulty comes from the absence, in general, of an objective way to assess the clustering quality and to compare two groupings of the data. Ben-David et al [1, 2, 3] put forward the goal of establishing a Theory of Clustering. In particular, attempts have been made by [4, 2, 3] to study and theoretically justify the stability-based approach of evaluating the quality of clustering solutions. Building upon these ideas, we present a characterization of clustering stability in terms of the geometry of the function class associated with minimizing the objective function. To simplify the exposition, we focus on K -means clustering, although the analogous results can be derived for K -medians and other clustering algorithms which minimize an objective function. Let us first motivate the notion of clustering stability. While for a fixed K , two clustering solutions can be compared according to the K -means objective function (see the next section), it is not meaningful to compare the value of the objective function for different K . How can one decide, then, on the value of K ? If we assume that the observed data is distributed independently according to some unknown distribution, the number of clusters K should correspond to the number of modes of the associated probability density. Since density estimation is a difficult task, another approach is needed. A stability-based solution has been used for at least a few decades by practitioners. The approach stipulates that, for each K in some range, several clustering solutions should be computed by sub-sampling or perturbing the data. The best value of K is that for which the clustering solutions\n\n\f\nare most \"similar\". This rule of thumb is used in practice, although, to our knowledge, there is very little theoretical justification in the literature. The precise details of data sub-sampling in the method described above differ from one paper to another. For instance, Ben-Hur et al [5] randomly choose overlapping portions of the data and evaluate the distance between the resulting clustering solutions on the common samples. Lange et al [6], on the other hand, divide the sample into disjoint subsets. Similarly, Ben-David et al [3, 2] study stability with respect to complete change of the data (independent draw). These different approaches of choosing K prompted us to give a precise characterization of clustering stability with respect to both complete and partial changes of the data. It has been noted by [6, 4, 3] that the stability of clustering with respect to complete change of the data is characterized by the uniqueness of the minimum of the objective function with respect to the true distribution. Indeed, minimization of the K -means objective function can be phrased as an empirical risk minimization procedure (see [7]). The stability follows, under some regularity assumptions, from the convergence of empirical and expected means over a Glivenko-Cantelli class of functions. We prove stability in the case of a unique minimizer by explicitly computing the covering number in the next section and noting that the resulting class is VC-type. We go further in our analysis by considering the other two interesting cases: finite and infinite number of minimizers of the objective function. With the help of a stability result of [8, 9] for empirical risk m imization, we are able to prove that K -means clustering is stable with resect in p to changes of o( n) samples, where n is the total number of samples. In fact, the rate of ( n) changes is a sharp transition between stability and instability in these cases.\n\n2\n\nPreliminaries\n\nLet (Z , A, P ) be a probability space with an unknown probability measure P . Let denote the Euclidean norm. We assume from the outset that the data live in a Euclidean ball in Rm , i.e. Z B2 (0, R) Rm for some R > 0 and Z is closed. A partition function C : Z {1, . . . , K } assigns to each point Z its \"cluster identity\". The goal of clustering is to find a good partition based on the sample Z1 , . . . , Zn of n points, distributed independently according to P . In particular, for K -means clustering, the quality of C on Z1 , . . . , Zn is measured by the within-point scatter1 (see [10]) W (C ) = 1k 2n\nK\n\n= 1 , j : C ( Z i )= C ( Z j )= k\n\ni\n\nZi - Zj 2.\n\n(1)\n\nIt is easy to verify that the (scaled) within-point scatter can be rewritten as W (C ) = 1k n\nK\n\n= 1 : C ( Z i )= k\n\ni\n\nZi - ck 2\n\n(2)\n\nwhere ck is the mean of the k -th cluster based on the assignment C (see Figure 1). We are interested in the minimizers of the within-point scatter. Such assignments have to map each point to its nearest cluster center. Since in this case the partition function C is completely determined by the K centers, we will often abuse the notation by associating C with the set {c1 , . . . , cK }.\n\nThe K -means clustering algorithm is an alternating procedure minimizing the within-point scatter W (C ). The centers {ck }K 1 are computed in the first step, following by the assignment of each Zi k= to its closest center ck ; the procedure is repeated. The algorithm can get trapped in local minima, and various strategies, such as starting with several random assignments, are employed to overcome the problem. In this paper, we are not concerned with the algorithmic issues of the minimization procedure. Rather, we study stability properties of the minimizers of W (C ). The problem of minimizing W (C ) can be phrased as empirical risk minimization [7] over the function class HK = {hA (z ) = z - ai 2, i = argmin z - aj 2 : A = {a1 , . . . , aK } Z K },\nj {1...K }\n1\n\n(3)\n\nWe have scaled the within-point scatter by 1/n if compared to [10].\n\n\f\nck - Zi 2 c1 c2\n\nFigure 1: The clustering objective is to place the centers ck to minimize the sum of squared distances from points to their closest centers. where the functions are obtained by selecting all possible K centers. Functions hA (z ) in HK can also be written as iK z - ai 2I(z is closest to ai ), hA (z ) =\n=1\n\nMoreover, if C minimizes the left-hand side, hC has to minimize the right-hand side and vice versa. Hence, we will interchangeably use C and hC as minimizers of the within-point scatter.\n\nwhere ties are broken, for instance, in the order of ai 's. Hence, functions hA HK are K parabolas glued together with centers at a1 , . . . , aK , as shown in Figure 1. With this notation, one can see that n 1i h(Zi ). min W (C ) = min C hHK n =1\n\nSeveral recent papers (e.g. [11]) have addressed the question of finding the distance metric for clustering. Fortunately, in our case there are several natural choices. One choice is to measure the similarity between the centers {ak }K 1 and {bk }K 1 of clusterings A and B . Another choice is to k= k= measure the Lq (P ) distance between hA and hB for some q 1. In fact, we show that these two choices are essentially equivalent.\n\n3\n\nCovering Number for HK\n\nThe following technical Lemma shows that a covering of the ball B2 (0, R) induces a cover of HK in the L distance because small shifts of the centers imply small changes of the corresponding functions in HK . Lemma 3.1. For any > 0, 12 mK 6R K + N (HK , L , ) . m 4 Proof. It is well-known that a Euclidean ball of radius R in Rm can be covered by N = R+ balls of radius (see Lemma 2.5 in [12]). Let T = {t1 , . . . , tN } be the set of centers of such a cover. Consider an arbitrary function hA HK with centers at {a1 , . . . , aK }. By the definition of the cover, there exists ti1 T such that a1 - ti1 . Let A1 = {ti1 , a2 , . . . , aK }. Since Z B2 (0, R), hA - hA1 (2R)2 - (2R - )2 4R. We iterate through all the ai 's, replacing them by the members of T . After K steps, hA - hAK 4RK and all centers of AK belong to T . Hence, each function hA H can be approximated to within 4RK by functions with centers in a finite set T . The upper bound on the number of functions in mK 4 functions cover HK to within 4RK in HK with centers in T is N K . Hence, N K = R+ the L norm. The Lemma follows by setting = 4RK .\n\n\f\n4\n\nGeometry of HK and Stability\n\nThe above Lemma shows that HK is not too rich, as its covering numbers are polynomial. This is the first important aspect in the study of clustering stability. The second aspect is the geometry of HK with respect to the measure P . In particular, stability of K -means clustering depends on the number of functions h HK with the minimum expectation Eh. Note that the number of minimizers depends only on P and K , and not on the data. Since Z is closed, the number of minimizers is at least one. The three important cases are: unique minimum, a finite number of minimizers (greater than one), and an infinite number of minimizers. The first case is the simplest one, and is a good starting point. Definition 4.1. For > 0 define QP = {h HK : Eh inf Eh \nh HK +\n\n},\n\nthe set of almost-minimizers of the expected error. In the case of a unique minimum of Eh, one can show that the diameter of Q tends to zero as P 0.2 Lemma 3.1 implies that the class HK is VC-type. In particular, it is uniform Donsker, as well as uniform Glivenko-Cantelli. Hence, empirical averages of functions in HK uniformly converge to their expectations: E > s = n 1i h- lim P up 0. h(Zi ) n n =1 hHK s E\nn 1i h(Zi ) h- n =1\n\nTherefore, for any , > 0\n\nP\n\nup\n\nhHK\n\n>\n\n\n\n<\n\n\n\nfor n > n, . Denote by hA the function corresponding to a minimum of W (C ) on Z1 , . . . , Zn . Suppose hC = argminhHK Eh, i.e. C is the best clustering, which can be computed only with the knowledge of P . Then, with probability at least 1 - , EhA \nn 1i hA (Zi ) + n =1\n\nand\n\nn 1i hC (Zi ) EhC + n =1\n\nfor n > n, . Furthermore,\n\nby the optimality of hA on the data. Combining the above,\n\nn n 1i 1i hA (Zi ) hC (Zi ) n =1 n =1\n\nEhA EhC + 2 with probability at least 1 - for n > n, . Another way to state the result is EhA - inf Eh . \nh HK P\n\nAssuming the existence of a unique minimizer, i.e. diamL1 (P ) QP 0, we obtain hA - hC L1 (P ) - 0. By triangle inequality, we immediately obtain the following Proposition.\nThis can be easily proved by contradiction. Let us assume that the diameter does not tend to zero. Then (t) there is a sequence of functions {h(t)} in QP with (t) 0 such that h(t)-h L1 (P ) for some > 0. Hence, by the compactness of HK , the sequence {h(t)} has an accumulation point h , and by the continuity of expectation, Eh = inf h HK Eh . Moreover, h - h L1 , which contradicts the uniqueness of the minimizer.\n2\n\nP\n\n\f\nProposition 4.1. Let Z1 , . . . , Zn , Z1 , . . . , Zn be i.i.d. samples. Suppose the clustering A minimizes W (C ) over the set {Z1 , . . . , Zn } while B is the minimizer over {Z1 , . . . , Zn }. Then hA - hB L1 (P ) - 0. We have shown that in the case of a unique minimizer of the objective function (with respect to the distribution), two clusterings over independently drawn sets of points become arbitrarily close to each other with increasing probability as the number of points increases. If there are finite (but greater than one) number of minimizers h HK of Eh, multinomial distri bution estimates tell us thawe expect stability with respect to o( n) changes of points, while no t stability is expected for ( n) changes, as the next example shows.\n1 Example 1. Consider 1-mean minimization over Z = {x1 , x2 }, x1 = x2 , and P = 2 (x1 + x2 ). It is clear that, given the training set Z1 , . . . , Zn , the center of the minimizer of W (C ) is either x1 or x2 , according to the majority vote over the training set. Since the difference between the number of points on x1 and x2 is distributed according to a binomial with zero mean and the variance scaling as n, it is clear that by changing ( n) points from Z1 , . . . , Zn , it is possible to swap the majority vote with constant probability. M eover, with probability approaching one, it is not possible to or achieve the swap by a change of o( n) points. A similar result can be shown for any K -means over a finite Z . P\n\nThe above example shows that, in general, it is not possible to prove closeness of clusterings over two sets of samples differing on ( n) elements. In fact, this is a sharp threshold. Indeed, by employing the following Theorem, proven in [8, 9], we can show that even in the case of an infinite number of minimizers, clusterings over two sets of samples differing on o( n) elements become arbitrarily close with increasing probability as the number of samples increases. This result cannot be deduced from the multinomial estimates, as it relies on the control of fluctuations of empirical means over a Donsker class. Recall that a class is Donsker if it satisfies a version of the central limit theorem for function classes. Theorem 4.1 (Corollary 11 in [9] or Corollary 2 in [8]). Assume that the class of functions F over Z is uniformly bounded and P -Donsker, for some probability measure P over Z . Let f (S ) and f (T ) be minimizers over F of the empirical verages with respect to the sets S and T of n points i.i.d. a according to P . Then, if |S T | = o( n), it holds f (S ) - f (T ) L1 (P ) - 0. We apply the above theorem to HK which is P -Donsker for any P because its covering numbers in L scale polynomially (see Lemma 3.1). The boundedness condition is implied by the assumption that Z B2 (0, R). We note that if the class HK were richer than P -Donsker, the stability result would not necessarily hold. Corollary 4.1. Suppose the clusterings A and B are minimize of the K -means objective W (C ) rs over the sets S and T , respectively. Suppose that |S T | = o( n). Then hA - hB L1 (P ) - 0. The above Corollary holds even if the number of minimizers h HK of Eh is infinite. This concludes the analysis of stability of K -means for the three interesting cases: unique minimizer, finite number (greater than one) of minimizers, and infinite number of minimizers. We remark that the distribution P and the number K alone determine which one of the above cases is in evidence. We have proved that stability of K -means clustering is characterized by the geometry of the class HK with respect to P . It is evident that the choice of K maximizing stability of clustering aims to choose K for which there is a unique minimizer. Unfortunately, r \"small\" n, stability with respect fo to a complete change of the data and stability with respect to o( n) changes are indistinguishable, making this rule of thumb questionable. Moreover, as noted in [3], small changes of P lead to drastic changes in the number of minimizers.\nP P\n\n\f\n5\n\nStability of the Centers\n\nIntuitively, stability of functions hA with respect to perturbation of the data Z1 , . . . , Zn implies stability of the centers of the clusters. This intuition is made precise in this section. Let us first define a notion of distance between centers of two clusterings. Definition 5.1. Suppose {a1 , . . . , aK } and {b1 , . . . , bK } are centers of two clusterings A and B , respectively. Define a distance between these clusterings as dmax ({a1 , . . . , aK }, {b1 , . . . , bK }) := max min ( ai - bj + aj - bi )\n\n1iK 1j K\n\nLemma 5.1. Assume the density of P (with respect to the Lebesgue measure over Z ) is bounded away from 0, i.e. dP > c d for some c > 0. Suppose hA - hB L1 (P ) . Then \nm +2\n\ndmax ({a1 , . . . , aK }, {b1 , . . . , bK }) where cc,m depends only on c and m.\n\ncc,m\n\n1\n\nProof. First, we note that m ax\n\nW ax ({a1 , . . . , aK }, {b1 , . . . , bK }) 2 max dm\n\n1iK 1j K\n\nmin\n\nai - bj , max\n\n1iK 1j K\n\nmin\n\naj - bi\n\nithout loss of generality, assume that the maximum on the right-hand side is attained at a1 and b1 such that b1 is the closest center to a1 out of {b1 , . . . , bK }. Suppose a1 - b1 = d. Since dmax ({a1 , . . . , aK }, {b1 , . . . , bK }) 2d, it is enough to show that d is small (scales as a power of ) . Consider B2 (a1 , d/2), a ball of radius d/2 centered at a1 . Since any point z B2 (a1 , d/2) is closer to a1 than to b1 , we have z - a1 2 z - b1 2. Refer to Figure 2 for the pictorial representation of the proof. Note that bj B2 (a1 , d/2) for any j {2 . . . K }. Also note that for any z Z , / z - a1 2 iK z - ai 2I(ai is closest to z ) = hA (z ).\n\n=1\n\n\f\n( d )2 2 a1 B (a1 , d/2) d Figure 2: To prove Lemma 5.1 it is enough to show that the shaded area is upperbounded by the L1 (P ) distance between the functions hA and hB and lower-bounded by a power of d. We deduce that d cannot be large. b1\n\nCombining all the information, we obtain the following chain of inequalities | hA - hB L1 (P ) = hA (z ) - hB (z )| dP (z ) B |hA (z ) - hB (z )| dP (z ) 2 (a1 ,d/2) B h d = P (z ) A (z ) - z - b1 2 2 (a1 ,d/2) B z d = - b1 2 - hA (z ) P (z )\n2 (a1 ,d/2)\n\n= \n\nB\n\n2 (a1 ,d/2)\n\nz\n\n- b1 2 -\n\nB\n\niK\n\n=1\n\nz - ai 2I(ai is closest to z ) d P (z )\n\nd\n\nP (z )\n\nB2\n\n(a1 ,d/2)\n\n2 (a1 ,d/2)\n\nc =c Since, by assumption, we obtain\n\n2 m/2 (m/2)\nm/2\n\n( d d/2)2 - z - a1 2 P (z )\n0\n\nz\n\n- b1 2 - z - a1 2\n\n2 2 (d/2)m+2 = cc,m dm+2 . (m/2) m(m + 2) hA - hB L1 (P ) , d cc,m \nm +2\n\nd/ 2\n\n( r d/2)2 - r2 m-1 dr\n\n1\n\n.\n\nFrom the above lemma, we immediately obtain the following Proposition.\n\n\f\nProposition 5.1. Assume the density of P (with respect to the Lebesgue measure over Z ) is bounded away from 0, i.e. dP > c d for some c > 0. Suppose the clusterings A and B are minimizers ofhe K -means objective W (C ) over the sets S and T , respectively. Suppose that t |S T | = o( n). Then dmax ({a1 , . . . , aK }, {b1 , . . . , bK }) - 0. Hence, theenters of the minimizers of the within-point scatter are stable with respect to perturbac tions of o( n) points. Similar results can be obtained for other procedures which optimize some function of the data by applying Theorem 4.1.\nP\n\n6\n\nConclusions\n\nWe showed that K -means clustering can be phrased as empirical risk minimization over a class HK . Furthermore, stability of clustering is determined by the geometry of HK with respect to P . We proved that in the case of a unique minimizer, K -means is stable with respect to a complete change of the data, while for multiple minimizers, we still expect stability with respect to o( n) changes. The rule for choosing K by maximizing stability can be viewed then as an attempt to select K such that HK has a unique minimizer with respect to P . Although used in practice, this choice of K is questionable, especially for small n. We hope that our analysis serves as a starting point for finding theoretically grounded recipes for choosing the number of clusters. References\n\n[1] Shai Ben-David. A framework for statistical clustering with a constant time approximation algorithms for k-median clustering. In COLT, pages 415426, 2004. [2] Ulrike von Luxburg and Shai Ben-David. Towards a statistical theory of clustering. PASCAL Workshop on Statistics and Optimization of Clustering, 2005. [3] Shai Ben-David, Ulrike von Luxburg, and David Pal. A sober look at clustering stability. In COLT, 2006. [4] A. Rakhlin. Stability of clustering methods. NIPS Workshop \"Theoretical Foundations of Clustering\", December 2005. [5] A. Ben-Hur, A. Elisseeff, and I. Guyon. A stability based method for discovering structure in clustered data. In Pasific Symposium on Biocomputing, volume 7, pages 617, 2002. [6] T. Lange, M. Braun, V. Roth, and J. Buhmann. Stability-based model selection. In NIPS, 2003. [7] Joachim M. Buhmann. Empirical risk approximation: An induction principle for unsupervised learning. Technical Report IAI-TR-98-3, 3, 1998. [8] A. Caponnetto and A. Rakhlin. Some properties of empirical risk minimization over Donsker classes. AI Memo 2005-018, Massachusetts Institute of Technology, May 2005. [9] A. Caponnetto and A. Rakhlin. Stability properties of empirical risk minimization over Donsker classes. Journal of Machine Learning Research. Accepted. Available at http://cbcl.mit.edu/people/rakhlin/erm.pdf, 2006. [10] Trevor Hastie, Robert Tibshirani, and Jerome Friedman. The Elements of Statistical Learning - Data Mining, Inference, and Prediction. Springer, 2002. [11] Marina Meila. Comparing clusterings: an axiomatic view. In ICML '05: Proceedings of the 22nd international conference on Machine learning, pages 577584, New York, NY, USA, 2005. ACM Press. [12] S.A. van de Geer. Empirical Processes in M-Estimation. Cambridge University Press, 2000.\n\n\f\n", "award": [], "sourceid": 3116, "authors": [{"given_name": "Alexander", "family_name": "Rakhlin", "institution": null}, {"given_name": "Andrea", "family_name": "Caponnetto", "institution": null}]}