{'fraction_non_alphanumeric': 0.04568201082349873, 'fraction_numerical': 0.012763252265762534, 'mean_word_length': 3.8807430685389237, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Data Driven Resource Allocation for Distributed Learning

In distributed machine learning, data is dispatched to multiple machines for processing. Motivated by the fact that similar data points often belong to the same or similar classes, and more generally, classification rules of high accuracy tend to be"locally simple but globally complex"(Vapnik&Bottou 1993), we propose data dependent dispatching that takes advantage of such structure. We present an in-depth analysis of this model, providing new algorithms with provable worst-case guarantees, analysis proving existing scalable heuristics perform well in natural non worst-case conditions, and techniques for extending a dispatching rule from a small sample to the entire distribution. We overcome novel technical challenges to satisfy important conditions for accurate distributed learning, including fault tolerance and balancedness. We empirically compare our approach with baselines based on random partitioning, balanced partition trees, and locality sensitive hashing, showing that we achieve significantly higher accuracy on both synthetic and real world image and advertising datasets. We also demonstrate that our technique strongly scales with the available computing power.


Introduction
Motivation and Overview: We consider distributed learning settings where massive amounts of data are collected centrally, and for space and efficiency reasons this data must be dispatched to distributed machines in order to perform the processing needed [9,11,12,35,48,49]. The simplest approach and the focus of past work (both theoretical and empirical) is to perform the dispatching randomly [48,49]. Random dispatching has the advantage that dispatching is easy, and because each machine receives data from the same distribution, it is rather clean to analyze theoretically.
However, since the distributions of the data on each machine are identical, such techniques could lead to sub-optimal results in practice in terms of the accuracy of the resulting learning rule. Motivated by the fact that in practice, similar data points tend to have the same or similar classification, and more generally, classification rules of high accuracy tend to be "locally simple but globally complex" [45], we propose a new paradigm for performing data-dependent dispatching that takes advantage of such structure by sending similar datapoints to the same machines. For example, a globally accurate classification rule may be complicated, but each machine can accurately classify its local region with a simple classifier.
bounds, the objective functions are nondecreasing as the number of clusters k increases, but with lower bounds we show the objective function can oscillate arbitrarily with respect to k. This makes the problem especially challenging from a combinatorial optimization perspective. Existing capacitated clustering algorithms work by rounding a fractional linear program solution, but the erratic nature of the objective function makes this task more difficult for us.
The balance constraints also introduce challenges when extending a clustering-based partitioning from a small sample to unseen data. The simple rule that assigns a new point to the cluster with the nearest center provides the best objective value on new data, but it can severely violate the balance constraints. Therefore, any balanced extension rule must take into account the distribution of data.
We overcome these challenges, presenting a variety of complementary results, which together provide strong justification for our distributed learning framework. We summarize each of our main results below.
• Balanced fault-tolerant clustering: We provide the first clustering algorithms with provable guarantees that simultaneously handle upper and lower bounds on the cluster sizes, as well as fault tolerance. Clustering is NP-hard and adding more constraints makes it significantly harder, as we will see in Section 4. For this reason, we first devise approximation algorithms with strong worst-case guarantees, demonstrating this problem is tractable. Specifically, in Section 2 we provide an algorithm that produces a fault-tolerant clustering that approximately optimizes k-means, k-median, and k-center objectives while also roughly satisfying the given upper and lower bound constraints. At a high level, our algorithm proceeds by first solving a linear program, followed by a careful balance and replication aware rounding scheme. We use a novel min-cost flow technique to finish off rounding the LP solution into a valid clustering solution.
• k-means++ under stability: We give complementary results showing that for 'typical' problem instances, it is possible to achieve better guarantees with simpler, more scalable algorithms. Specifically, in Section 3 we show the popular k-means++ algorithm outputs a balanced clustering with stronger theoretical guarantees, provided the data satisfies a natural notion of stability. We make nontrivial extensions of previous work to ensure the upper and lower size constraints on the clusters are satisfied. No previous work gives provable guarantees while satisfying both upper and lower bounds on the cluster sizes, and Sections 2 and 3 may be of independent interest beyond distributed learning.
• Structure of balanced clustering: We show that adding lower bound constraints on the cluster sizes makes clustering objectives highly nontrivial. Specifically, we show that for k-means, k-median, and k-center, the objective values may oscillate arbitrarily with respect to k. In light of this structure, our aforementioned algorithmic results are more surprising, since it is not obvious that algorithms with constant-factor guarantees exist.
• Efficient clustering by subsampling: For datasets large enough to require distributed processing, clustering the entire dataset is prohibitively expensive. A natural way to avoid this cost is to only cluster a small subset of the data and then efficiently extend this clustering to the entire dataset. In Section 5 we show that assigning a new example to the same p clusters as its nearest neighbor in the clustered subsample approximately preserves both the objective value and all constraints. We also use this technique at prediction time to send new examples to the most appropriate machines.
• Experimental results: We conduct experiments with both our LP rounding algorithms and k-means++ together with our nearest neighbor extension technique. We include empirical (and theoretical) comparisons which show the effectiveness of both algorithms in different situations. The k-means++ algorithm is competitive on real world image and advertising datasets, complementing the results of Section 3 by showing empirically that k-means++ produces high-quality balanced clusterings for 'typical' datasets. We then compare the performance of our framework (using k-means++ with nearest neighbor extension) against three baseline methods (random partitioning, balanced partition trees, and locality sensitive hashing) in large scale learning experiments where each machine trains an SVM classifier. We find that for all datasets and across a wide range of k values, our algorithm achieves higher accuracy than any of the baselines. Finally, we show that our technique strongly scales, meaning that doubling the available computational power while keeping the workload fixed reduces the running time by a constant factor, demonstrating that our method can scale to very large datasets. Related Work: Currently, the most popular method of dispatch in distributed learning is random dispatch [48,49]. This may not produce optimal results because each machine must learn a global model. Another notion is to dispatch the data to pre-determined locations e.g., Yahoo!'s geographically distributed database, PNUTS [20]. However, it does not look at any properties of the data other than physical location.
In a recent paper, Wei et al. [46] study partitioning for distributed machine learning, however, they give no formal the upper (resp. lower) bounds are extremely tight or the number of clusters is a small constant.
guarantees on balancing the data each machine receives. You et al. [47] use k-means clustering to distribute data for parallel training of support vector machines, but their clustering algorithms do not have approximation guarantees and are applied to the entire dataset, so their clustering step is much slower than ours. There is also work on distributed graph partitioning [7,15,24], in which the data points are set up in a graph structure, and must be distributed to different machines, minimizing the number of edges across machines. These techniques do not apply more generally for non graph-based objectives, e.g. k-means, k-median, or k-center. Previous work in theoretical computer science has considered capacitated clustering, or clustering with upper bounds [5,18,21,30,36,37], and lower bounds [3,4], but our algorithm is the first to solve a more general and challenging question of simultaneously handling upper and lower bounds on the cluster sizes, and p-replication. See Section 8 in the Appendix for a more detailed discussion about related work.

Fault Tolerant Balanced Clustering
In this section, we give an algorithm to cluster a small initial sample of data to create a dispatch rule that sends similar points to the same machine. There are many ways to measure the similarity of points in the same cluster. We consider three classic clustering objectives while imposing upper and lower bounds on the cluster sizes and replication constraints. It is well-known that solving the objectives optimally are NP-hard, even without the capacity and fault tolerance generalizations [28]. In Section 4, we show that the objectives with balance constraints behave erratically with respect to the number of clusters k, in particular, there may exist an arbitrary number of local minima and maxima. In light of this difficulty, one might ask whether any approximation algorithm is possible for this problem. We answer affirmatively, by extending previous work [36] to fit our more challenging constrained optimization problem. Our algorithm returns a clustering whose cost is at most a constant factor multiple of the optimal solution, while violating the capacity and replication constraints by a small constant factor. This is the first algorithm with provable guarantees to simultaneously handle both upper and lower bounds on the cluster sizes. Theorem 1. Algorithm 1 returns a constant factor approximate solution for the balanced k-clustering with p-replication problem for p > 1, where the upper capacity constraints are violated by at most a factor of p+2 p , and each point can be assigned to each center at most twice.
A clustering instance consists of a set V of n points, and a distance metric d. Given two points i and j in V , denote the distance between i and j by d(i, j). The task is to find a set of k centers C = {c 1 , . . . , c k } and assignments of each point to p of the centers f : V → C p , where C p represents the subset of C p with no duplicates. In this paper, we study three popular clustering objectives: (1) k-median: min C,f i∈V j∈f (i) d(i, j) (2) k-means: min C,f i∈V j∈f (i) d(i, j) 2 (3) k-center: min C,f max i∈V max j∈f (i) d(i, j) In this section, we focus on the first two, and put the details for k-center in the appendix. We add size constraints 0 < ≤ L < 1, also known as capacity constraints, so each cluster must have a size between n and nL. For simplicity, we assume these values are integral (or replace them by n and nL respectively).
At a high level, our algorithm proceeds by first solving a linear program, followed by careful rounding. In particular, we set up an LP whose optimal integral solution is the optimal clustering. We can use an LP solver which will give a fractional solution (for example, the LP may open up 2k 'half' centers). Then, using a greedy procedure from Charikar et al. [19], we pick ≤ k points (called the 'monarchs') which are spread out. Furthermore, the distance from a non-monarch to its closest monarch is a constant-factor multiple of the non-monarch's connection cost in the LP solution. The empire of a monarch is defined to be its cell in the Voronoi partition induced by the monarchs. By a Markov inequality, every empire has ≥ p/2 total fractional centers, which is at least one for p ≥ 2. Then we merely open the innermost points in the empires as centers, ending with ≤ k centers. Once we have the centers, we find the optimal assignments by setting up a min-cost flow problem.
The key insight is that p-replication helps to mitigate the capacity violation in the rounding phase. Together with a novel min-cost flow technique, this allows us to simultaneously handle upper and lower bounds on the cluster sizes. The procedure is summarized in Algorithm 1, and below we provide details, together with the key ideas behind its correctness (see Appendix 9 for the full details).
Step 1: Linear Program The first step is to solve a linear program (LP) relaxation of the standard integer program (IP) formulation of our constrained clustering problem. The variables are as follows: for each i ∈ V , let y i be an indicator for whether i is opened as a center. For i, j ∈ V , let x ij be an indicator for whether point j is assigned to center i. In the LP, the variables may be fractional, so y i represents the fraction to which a center is opened (we will refer to this as the "opening" of i), and x ij represents the fractional assignment of j to i. One can use an LP solver to get a fractional solution which must then be rounded. Let (x, y) denote an optimal solution to the LP. For any points i and j, let c ij be the cost of assigning point j to center i. That is, for k-median, c ij = d(i, j), and for k-means c ij = d(i, j) 2 (we discuss k-center in the appendix). Define C j = i c ij x ij , the average cost from point j to its centers in the LP solution (x, y).
It is well-known that the LP in Algorithm 1 has an unbounded integrality gap (the ratio of the optimal LP solution over the optimal integral LP solution), even when the capacities are violated by a factor of 2 − [36]. However, with fault tolerance, the integrality is only unbounded when the capacities are violated by a factor of p p−1 (see the appendix for the integrality gap). Intuitively, this is because the p centers can 'share' this violation.
1. Find a solution to the following linear program: 2. Greedily place points into a set M from lowest C j to highest (called "monarchs"), adding point j to M if it is not within distance 4C j of any monarch. Partiton the points into coarse clusters (called "empires") using the Voronoi partitioning of the monarchs. 3. For each empire E u with total fractional opening Y u i∈Eu y i , give opening Yu / Yu to the Y u closest points to u and all other points opening 0. 4. Round the x ij 's by constructing a minimum cost flow problem on a bipartite graph of centers and points, setting up demands and capacities to handle the bounds on cluster sizes.

Algorithm 1: Balanced clustering with fault tolerance
Step 2: Monarch Procedure Next, partition the points into "empires" such that every point is ≤ 4C j from the center of its empire (the "monarch") by using a greedy procedure from Charikar et al. [19] (for an informal description, see step 2 of Algorithm 1). By Markov's inequality, every empire has total opening ≥ p/2, which is crucially ≥ 1 for p ≥ 2 under our model of fault tolerance. We obtain the following guarantees, and we show a proof sketch for the k-median objective, with the full proof in Appendix 9.
Lemma 2. The output of the monarch procedure satisfies the following properties: (1a) The clusters partition the point set; (1b) Each point is close to its monarch: ∀j ∈ E u , u ∈ M, c uj ≤ 4C j ; (1c) Any two monarchs are far apart: ∀u, u ∈ M s.t. u = u , c uu > 4 max{C u , C u }; (1d) Each empire has a minimum total opening: ∀u ∈ M, j∈Eu y j ≥ p 2 . Proof sketch. The first three properties follow easily from construction (for property (1c), recall we greedily picked monarchs by the value of C j ). For the final property, note that for some u ∈ M, if d(i, u) ≤ 2C u , then i ∈ E u (from the triangle inequality and property (1c)). Now, note that C u is a weighted average of costs c iu with weights x iu /p, i.e., C u = i c iu xiu /p. By Markov's inequality, in any weighted average, values greater than twice the average have to get less than half the total weight. That is, Combining these two facts, for each u ∈ M: j∈Eu y j ≥ j:cju≤2Cu Step 3: Aggregation The point of this step is to end up with ≤ k centers total. Since each empire has total opening at least 1, we can aggregate openings within each empire. For each empire E u , we move the openings to the Y u innermost points of E u , where Y u = i∈Eu y i . This shuffling is accomplished by greedily calling a suboperation called Move, which is the standard way to transfer openings between points to maintain all LP constraints [36]. To perform a Move from i to j of size δ, set y i = y i − δ and y j = y j + δ, and change all x's so that the fractional demand switches from i to j: ∀u ∈ V , x iu = x iu (1 − δ /yi) and similarly increase the demand to all x ju . The Move operation preserves all LP constraints, except we may violate the capacity constraints if we give a center an opening greater than one.
In each empire E u , start with the point i with nonzero y i that is farthest away from the monarch u. Move its opening to the monarch u, and then iteratively continue with the next-farthest point in E u with nonzero opening. Continue this process until u has opening exactly Yu Yu , and then start moving the farthest openings to the point j closest to the monarch u. Continue this until the Y u closest points to u all have opening Yu Yu . Call the new variables (x , y ). They have the following properties. (2b) Each cluster satisfies the capacity constraints: i ∈ V, y i ≤ j∈V x ij n ≤ Ly i ; (2c) The total fractional opening is k: i∈V y i = k; (2d) Points are only assigned to open centers: ∀i, j ∈ V, x ij ≤ y i ; (2e) Each point is assigned to p centers: ∀i ∈ V, j x ji = p; (2f) The number of points with non-zero opening is at most k: |{i | y i > 0}| ≤ k.
Proof. For the first property, recall that each cluster E u has total opening ≥ p 2 , so by construction, all i with nonzero y i has y i ≥ 1. We also have Yu Yu ≤ Yu +1 Yu ≤ p+2 p , which gives the desired bound. The next four properties are checking that the LP constraints are still satisfied (except for y i ≤ 1). These follow from the fact that Move does not violate the constraints. The last property is a direct result of Properties (2a) and (2c).
We obtain the following guarantee on the moving costs. Lemma 4. ∀j ∈ V whose opening moved from i to i, We include the proof for k-means in Appendix 9.
Step 4: Min cost flow Now we must round the x's. We set up a min cost flow problem, where an integral solution corresponds to an assignment of points to centers. We create a bipartite graph with V on the left (each with supply p) and the k centers on the right (each with demand n ), and a sink vertex with demand np − kn . We carefully set the edge weights so that the minimum cost flow that satisfies the capacities corresponds to an optimal clustering assignment. See Figure 2.
Then using the Integral Flow Theorem, we are guaranteed there is an integral assignment that achieves the same optimal cost (and finding the min cost flow is a well-studied polynomial time problem [41]). Thus, we can round the x's without incurring any additional cost to the approximation factor. This is the first time this technique has been used in the setting of clustering.
In Section 10 of the appendix, we show a more involved algorithm specifically for k-center which achieves a 6-approximation with no violation to the capacity or replication constraints.

Balanced Clustering under Stability
In the previous section, we showed an LP-based algorithm which provides theoretical guarantees even on adversarially chosen data. Often real-world data has inherent structure that allows us to use more scalable algorithms and achieve even better clusters [10,40]. In our distributed ML framework, this translates to being able to use a larger initial sample for the same computational power (Section 5 analyzes the effect of sample size). In this section, we prove the popular k-means++ algorithm as well as a greedy thresholding algorithm output clusters very close to the optimal solution, provided the data satisfies a natural notion of stability called approximation stability [2,8,10,13,27].
Specifically, we show that given a balanced clustering instance in which clusterings close in value to OPT are also close in terms of the clusters themselves, assuming L ∈ O( ), then k-means++ with a simple pruning step [40] outputs a solution close to optimal. For the k-median objective, we show that under the same stability condition, Balcan et al.'s greedy thresholding algorithm outputs a solution that is close to optimal [10]. For the k-center objective, we show a simple thresholding algorithm is sufficient to optimally cluster the data, and this result is tight up to the level of stability. That is, assuming any strictly weaker version of stability makes the problem NP-hard. We overcome key challenges that arise when we add upper and lower bounds to the cluster sizes. We present the intuition here, and give the full details in Appendix 11. Approximation Stability: Given a clustering instance (S, d) and inputs and L, let OPT denote the cost of the optimal balanced clustering. Two clusterings C and C are -close, if only an -fraction of the input points are clustered differently in the two clusterings, i.e., min σ Definition 1 (Balcan et al. [10]). A clustering instance (S, d) satisfies (1 + α, )-approximation stability with respect to balanced clustering if all clusterings C with cost(C) ≤ (1 + α) · OPT are -close to C. k-means: We show that sampling k log k centers using k-means++, followed by a greedy center-pruning step, (introduced by Ostrovsky et al. [40]) is sufficient to cluster well with high probability, assuming (1 + α, )-approximation stability for balanced clustering. Our results improve over Agarwal et al. [2], who showed this algorithm outputs a good clustering with probability Ω( 1 k ) for standard (unbalanced) clustering under approximation stability. Formally, our result is the following.
Intuitively, (1 + α, )-approximation stability forces the clusters to become "spread out", i.e., the radius of any cluster is much smaller than the inter-cluster distances. This allows us to show for 2-means clustering, the k-means++ seeding procedure will pick one point from each cluster with high probability. We defer some proofs to Appendix 11. Given a point set S, let ∆ k (S) denote the optimal k-means cost of S. Lemma 6 ([40]). Given a set S ⊆ R d and any partition S 1 ∪ S 2 of S with S 1 = ∅. Let s,s 1 ,s 2 denote the centers of mass of S, S 1 , and S 2 , respectively. Then We define r i as the average radius of cluster C i , i.e. r i = 1 |Ci| x∈Ci d(x, c i ). Given a clustering instance S satisfying (1 + α, )-approximation stability, with upper and lower bounds L and on the cluster sizes. We assume that L ∈ O( ). For convenience, let |C i | = n i for all i.
Let c denote the center of mass of X. Then Therefore, n n 1 and it follows that max(r 2 Let ρ = 100 α < 1. Now we define the core of a cluster C i as Then by a Markov inequality, |X i | ≥ (1 − ρ)n i for all i. This concentration inequality, along with Lemma 7 are the key structures needed to show k-means++ produces a good clustering. Recall in k-means++, we pick seeds {ĉ 1 , . . . ,ĉ k } so that we pick point x forĉ i+1 with probability proportional to d(x, {ĉ 1 , . . . ,ĉ i }) 2 . We defer the proof of the following lemma to the appendix.
This lemma, combined with Lemma 3.3 from [40], immediately gives us the following theorem.
Theorem 9. k-means++ seeding with a Lloyd step outputs a solution that is 1 1−ρ close to the optimal solution with probability > 1 − O(ρ), for clustering instances satisfying (1 + α, )-approximation stability for the balanced 2-means objective, with L ∈ O(1). Now we have a proof for k = 2, however, if we induct on the number of clusters, the probability of success becomes exponentially small in k. We circumvent this issue in a manner similar to Ostrovsky et al. [40], by sampling k log k centers, and carefully deleting centers greedily, until we are left with one center per cluster with high probability. The rest of the details in proving Theorem 5 are presented in Appendix 11. k-median: We show that the greedy thresholding algorithm of Balcan et al. [10] is sufficient to give a good clustering even for the balanced k-median or k-means objective, under approximation stability. At a high level, their algorithm works by first creating a threshold graph for a specific distance, and then iteratively picking the node with the highest degree in the threshold graph and removing its neighborhood. In Appendix 11, we show balanced clustering instances where the analysis in Balcan et al. [10] is not sufficient to guarantee good clusterings are outputted. We provide a new technique which overcomes the difficulties in adding upper and lower balance constraints, and we obtain the following theorem.
Theorem 10. There is an efficient algorithm which returns a valid clustering that is O( α )-close to the optimal, for balanced k-median or k-means clustering under (1 + α, )-approximation stability, provided all clusters are size ≥ 3 n(1 + 3 α ). A key point in the argument of Balcan, Blum, and Gupta is that for (1 + α, )-approximation stable instances, there are less than n points v for which the distance between their closest and second-closest center is small. Otherwise, these points could switch clusters and cause a contradiction. With balance constraints, this logic breaks down, since a point may not be able to switch clusters if the new cluster is at capacity. We provide a new structural result to handle this problem: there are only n 2 distinct pairs of points from different clusters that are close to each other. This allows us to show the algorithm returns a clustering that is near-optimal. We provide the details of this argument in Appendix 11. k-center: For k-center, we obtain a tight result with respect to the level of approximation stability needed. In particular, we show the exact level of stability for which the problem of finding the optimal balanced k-center solution switches from NP-hard to efficiently computable. This is shown in the following theorems. Theorem 11 is a generalization of the lower bound in [13].
Theorem 11. There is an efficient algorithm such that if a clustering instance satisfies (2, 0)-approximation stability for the balanced k-center objective, then the algorithm will return the optimal clustering. Furthermore, for > 0, there does not exist an efficient algorithm that returns optimal clusterings for balanced k-center instances under (2 − , 0)-approximation stability, unless N P = RP .

Structure of Balanced Clustering
In this section, we show that adding lower bounds to clustering makes the problem highly nontrivial. Specifically, our main result is that the k-means, k-median, and k-center objective values may oscillate arbitrarily with respect to k (Theorem 15). In light of this structure, our results from Sections 2 and 3 are more surprising, since it is not obvious that algorithms with constant-factor guarantees exist.
We give a variety of clustering instances which do not have monotone cost functions with respect to k. For readability and intuition, these examples start out simple, and grow in complexity until we eventually prove Theorem 15.
First, consider a star graph with n points and lower bound , such that n ≥ 3 (see Figure 3). The center c is at distance 1 to the 10n leaves, and the leaves are at distance 2 from each other. When k = 1, each point is distance 1 to the center c. However as we increase k, the new centers must be leaves, distance 2 from all the other points, so n − 1 points must pay 2 instead of 1 for each extra center. It is also easy to achieve an objective that strictly decreases up to a local minimum k , and then strictly increases onward, by adding k copies of the center of the star.
Lemma 12. Given a star graph with parameters n and such that n ≥ 3, then the cost of the k-means and k-median objectives strictly increase in k. c Figure 3: A graph in which the objective function strictly increases with k. Each edge signifies distance 1, and all other distances are 2.  Proof. Let the size of the star graph be n. Clearly, the optimal center for k = 1 is c. Then OPT 1 = n − 1. Then for k = 2, we must choose another center p that is not c. p is distance 2 to all points other than c, so the optimal clustering is for p's cluster to have the minimum of n points, and c's cluster has the rest. Therefore, OPT 2 = n + n − 2. This process continues; every time a new center is added, the new center pays 0 instead of 1, but n − 1 new points must pay 2 instead of 1. This increases the objective by n − 2. As long as n ≥ 3, this ensures the objective function is strictly increasing in k.
Note for this example, the problem goes away if we are allowed to place multiple centers on a single point (in the literature, this is called "soft capacities", as opposed to enforcing one center per point, called "hard capacities"). The next lemma shows there can be a local minimum for hard capacities.
Lemma 13. For all k , there exists a balanced clustering instance in which the k-means or k-median objective as a function of k has a local minimum at k .
Proof. Given l ≥ 3, we create a clustering instance as follows. Define k sets of points G 1 , . . . , G k , each of size 2n − 1. For any two points in some G i , set their distance to 0. For any two points in different sets, set their distance to 1. Then for 1 ≤ k ≤ k , the objective value is equal to (k − k)(2n − 1), since we can put k centers into k distinct groups, but (k − k) groups will not have centers, incurring cost 2n − 1. When k > k , we cannot put each center in a distinct group, so there is some group G i with two centers. Since |G i | = 2n − 1, the two centers cannot satisfy the capacity constraint with points only from G i , so the objective value increases.
Local maxima: So far, we have seen examples in which the objective decreases with k, until it hits a minimum (where capacities start to become violated), and then the objective strictly increases. The next natural question to ask, is whether the objective can also have a local maximum. We show the answer is yes in the following lemma.

Lemma 14.
There exists a balanced clustering instance in which the k-center, k-median, and k-means objectives contain a local maximum with respect to k. . . .
2n5 2n5 2n5 2n5 2n5 2n5 2n5 2n5 2n5 2n5 2n5 Figure 5: An example when m = 3. Each X k is a different color. Each edge signifies distance 1, and all other distances are 2. The middle points are replicated as many times as their label suggests (but each pair of replicated points are still distance 2 away).
Proof sketch. Consider Figure 4, where n = 86, and set n = 21. Since the distances are all 1 or 2, this construction is trivially a valid distance metric. From Figure 4, we see that k = 2 and k = 4 have valid clusterings using only length 1 edges, using centers {y 1 , y 2 } and {x 1 , x 2 , x 3 , x 4 }, respectively. But now consider k = 3. The crucial property is that by construction, y 1 and any x i cannot simultaneously be centers and each satisfy the capacity to distance 1 points, because the union of their distance 1 neighborhoods is less than 2n . In the appendix, we carefully check all other sets of 3 centers do not achieve a clustering with distance 1 edges, which completes the proof.
The previous example does not work for the case of soft capacities, since the set of centers {x 1 , y 2 , y 2 } allows every point to have an edge to its center. Now we prove our main theorem. Note, this theorem holds even for soft capacities.
Theorem 15. For all m ∈ N, there exists a balanced clustering instance in which the k-center, k-median, and k-means objectives contain m local maxima, even for soft capacities.
Proof. As in the previous lemma, we will construct a set of points in which each pair of points are either distance 1 or 2. It is convenient to define a graph on the set of points, in which an edge signifies a distance of 1, and all non-edges denote distance 2. We will construct a clustering instance where the objective value for all even values of k between 10m and 12m is low and the objective value for all odd values of k between 10m and 12m is high. The m odd values will be the local maxima. We will set the lower bound n to be the product of all the even integers between 10m and 12m.
We start by creating a distinct set of "good" centers, X k , for each even value of k between 10m and 12m. Let X be the union of these sets. The set X k contains k points which will be the optimal centers for a k-clustering in our instance. Then we will add an additional set of points, Y , and add edges from Y to the centers in X with the following properties.
1. For each even value of k between 10m and 12m, there is an assignment of the points in Y to the centers in X k so that points in Y are only assigned to adjacent centers and the capacity constraints are satisfied.
2. Each of the good centers in X is adjacent to no more than 6 5 · n points in Y .
3. For each good center x in X k , there is at least one point x in every other set X k (for k = k) so that the number of points in Y adjacent to both x and x is at least 2 5 · n .
4. Any subset of the centers in X that does not contain any complete set of good centers X k for some even k is non-adjacent to at least one point in Y .
Whenever we add a point to Y , we give it an edge to exactly one point from each X k . This ensures that each X k partitions Y . We first create connected components as in Figure 5 that each share 2 5 · n points from Y , to satisfy Property 3.
For property 4, we add one additional point to Y for every combination of picking one point from each X k . This ensures that any set which does not contain at least one point from each X k will not be a valid partition for Y . Note that in the previous two steps, we did not give a single center more than 6 5 · n edges, satisfying property 2. Then we add "filler" points to bring every center's capacity up to at least n , which satisfies property 1. Now we explain why properties 1-4 are sufficient to finish off the proof. Property 1 guarantees that the for each even value of k there is a clustering where the cost of each point in Y is one, which results in a good clustering objective. Properties 2 and 3 guarantee that any set including a full X k and a point from a different X k cannot achieve cost 1 for each point without violating the capacities. Property 4 guarantees that any set without a full X k cannot achieve cost 1 for each point. This completes the proof sketch.

Efficient Clustering by Subsampling
For datasets large enough to require a distributed learning system, it is expensive to apply a clustering algorithm to the entire dataset. In this section, we show that we can first cluster a small subsample of data and then efficiently extend this clustering to the remaining data. In our technique, each point in the dataset is assigned to the same p clusters as its nearest neighbor in the clustered subsample. This dispatch rule extends the clustering to the entire space X containing the data (not just to the unused portion of the training set), so at prediction time it can be used to send query points to the appropriate machines. We show that the clustering induced over X approximately inherits all of the desirable properties of the clustered subsample: good objective value, balanced clusters, and replication. Note that the simpler approach of assigning a new example x to the p clusters with the nearest centers achieves the lowest cost for new examples, but it may severely violate the capacity constraints if the data distribution is not evenly distributed among the centers.
Each clustering of X can be represented as a pair (f, C) where C = {c 1 , . . . , c k } is a set of centers and f : X → C p is a function that assigns each point in X to p of the k centers. We measure the quality of a clustering of X as follows: given a data distribution µ over X , our goal is to find a clustering with centers C and an assignment function f : X → C p that minimizes either the k-median objective Q (1) or the k-means objective Q (2) given by subject to the constraint that each cluster has probability mass between and L. Specifically, we require for each cluster index i that P x∼µ (i ∈ f (x)) ∈ [ , L]. Throughout this section, we use the notation Q, Q n , andQ n as a placeholder for either the k-median or k-means objective. In our algorithm, each point x in the subsample S acts as a representative for those points in X that are closer to it than any other sample point (i.e., its cell in the Voronoi partition induced by S). Since each sample point might represent more or less of the probability mass of µ, we consider the following weighted clustering problem of a dataset S. A clustering of the data set S is a pair (g, C) for some set of centers C = {c 1 , . . . , c k } and an assignment function g : S → C p that assigns each point of S to p of the centers. The weight for point The weighted k-median and k-means objectives on S are given by where the subscript n refers to the size of the subsample S. The weighted capacity constraints require that the total weight of each cluster i, given by j:i∈g(xj ) w j , is between and L. Since the distribution µ is unknown, our algorithm uses a second sample drawn from µ to estimate the weights. Given estimatesŵ 1 , . . . ,ŵ n of the true weights, the estimated k-median and k-means objective functions arê Input: Dataset S = {x 1 , . . . , x n }, cluster parameters (k, p, , L), second sample size n . 1. Draw second sample S of size n iid from µ.

For each point
. . , c k ) and g S : S → C p be a clustering of S obtained by minimizingQ n (g, C) subject to the approximate weighted capacity constraints. 4. Returnḡ S (x) = g S (NN S (x)) and centers C S . Algorithm 6: Nearest neighbor clustering extension. and the estimated weight of a cluster is j:i∈g(xj )ŵ j . Finally, for any clustering (g, c) of S, define the nearest neighbor extension to be (ḡ, c) whereḡ(x) = g(NN S (x)). The assignment functionḡ assigns each point in X to the same p clusters as its nearest neighbor in S.
Our algorithm first runs a clustering algorithm to approximately minimize the weighted clustering objective on the sample S (where the weights are estimated using a second sample drawn from the same distribution). Then, we extend this clustering to the entire space X by assigning a new example to the same p clusters as its nearest neighbor in the subsample S. Psuedocode is given in Algorithm 6. Our main result in this section shows that the resulting clustering of X approximately satisfies the capacity constraints and has a nearly optimal objective value.
Before stating our main result, we first show that if we take the second sample size n to beÕ(n/ 2 ), then with high probability the error in any sum of the estimated weightsŵ j is at most .
Lemma 16. For any > 0 and δ > 0, if we set n = O 1 2 (n + log 1 δ ) in Algorithm 6, then with probability at least , let V I denote the union i∈I V i . Since the sets V 1 , . . . , V n are disjoint, for any index set I we have that µ(V I ) = i∈I w i and µ(V I ) = i∈Iŵ i , whereμ is the empirical measure induced by the second sample S . Therefore it suffices to show uniform convergence ofμ(V I ) to µ(V I ) for the 2 n index sets I. Applying Hoeffding's inequality to each index set and the union bound over all 2 n index sets, we have that P sup Setting n = O 1 2 (n + log 1 δ ) results in the right hand side being equal to δ.
Next we relate the weighted capacity constraints and objective over the set S to the constraints and objective over the entire space X . Lemma 17. Let (g, c) be any clustering of S that satisfies the weighted capacity constraints with parameters and L. Then the nearest neighbor extension (ḡ, c) satisfies the capacity constraints with respect to µ with the same parameters. For the k-median objective we have and for the k-means objective we have Proof. The fact thatḡ satisfies the population-level capacity constraints follows immediately from the definition of the weights w 1 , . . . , w n . By the triangle inequality, k-median objective over X with respect to µ can be bounded as follows The reverse inequality follows from an identical argument applying the triangle inequality to Q (1) n . For the k-means objective, the result follows similarly by using the following approximate triangle inequality for squared distances: Main Result: We bound the sub-optimality of the clustering (ḡ n , c n ) returned by Algorithm 6 with respect to any clustering (f * , c * ) of the entire space X . The bound will depend on 1. the quality of the finite-data algorithm, 2. the "average radius" of the Voronoi cells α 1 (S) = E x∼µ [d(x, NN S (x))] for k-median and the "average squared radius" for k-means α 2 (S) = E x∼µ [d(x, NN S (x)) 2 ] , and 3. the bias from returning clusterings that are constant over the cells in the Voronoi partition induced by S. The following definition measures the bias for k-median where the minimum is taken over all clusterings (h, c) of the sample S and (h, c) denotes the nearest neighbor extension. The bias β 2 (S, , L) for k-means is defined analogously.
Theorem 18. For any > 0, δ > 0, let (ḡ n , c n ) be the output of Algorithm 6 with parameters k, p, , L and second sample size n = O (n + log 1/δ)/ 2 . Let (f * , c * ) be any clustering of X and (g * n , c * n ) be an optimal clustering of S underQ n satisfying the estimated weighted balance constraints ( , L). Suppose the algorithm used to cluster S satisfieŝ Q(g n , c n ) ≤ r ·Q(g * n , c * n ) + s. Then w.p. ≥ 1 − δ over the second sample the output (ḡ n , c n ) will satisfy the balance constraints with = − and L = L + . For k-median we have and for k-means we have Proof. Lemma 16 guarantees that when the second sample is of size O( 1 2 (n + log 1 δ )) then with probability at least 1 − δ, for any index set I ⊂ [n], we have i∈I w i −ŵ i ≤ . For the remainder of the proof, assume that this high probability event holds.
First we argue that the clustering (g n , c n ) satisfies the true weighted capacity constraints with the slightly looser parameters = − and L = L + . Since the clustering (g n , c n ) satisfies the estimated weighted capacity constraints, the high probability event guarantees that it will also satisfy the true weighted capacity constraints with the looser parameters = − and L = L+ . Lemma 17 then guarantees that the extension (ḡ n , c n ) satisfies the population-level capacity constraints with parameters and L .
Next we bound the difference between the estimated and true weighted objectives for any clustering (g, c) of S. For each point x j in the set S, let C j = i∈g(xj ) d(x j , c(i)) be the total distance from point x j to its p assigned centers under clustering (g, c), and let J be the set of indices j for whichŵ j > w j . Then by the triangle inequality, we have the following bound for the k-median objective: where the second inequality follows from the fact that C j ≤ pD and the sum has been split so that (ŵ j − w j ) is always positive in the first sum and negative in the second. For the k-means objective, the only difference is that our upper bound on C j is D 2 instead of D, which gives |Q Finally, let (h n , c n ) be the clustering of S that attains the minimum in the definition of β(S, + , L − ). That is, the clustering of S satisfying the capacity constraints with parameters + and L − whose nearest neighbor extension has the best objective over X with respect to µ (note that this might not be the extension of (g * n , c * n )). Now we turn to bounding the k-median objective value of (ḡ n , c n ) over the entire space X . Combining Lemma 17, equation (1), the approximation guarantees for (g n , c n ) with respect toQ n , and the optimality of (g * n , c * n ), we have the following: The proof for the case of k-means is identical, except we use the corresponding result from Lemma 17 and the alternative version of equation (1).
The above theorem applies for any set S, but the quality of the bound depends on α(S) and β(S), which measure how well the set S represents the distribution µ. We now bound α(S) and β(S) when S is a large enough iid sample drawn from µ under various conditions on µ and the optimal clustering. Bounding α(S): We bound the sample size required to make α(S) small when X ⊆ R q and S is drawn randomly from an arbitrary µ. Additionally, when the distribution has a lower intrinsic dimension, we can do better. The doubling condition is one such a condition. Let B(x, r) be a ball of radius r around x with respect to the metric d. A measure µ with support X is said to be a doubling measure of dimension d 0 if for all points x ∈ X and all radii r > 0 we have Bounding β(S): Bubeck et al. [16] provide a worst case lower bound when f * is continuous almost everywhere. Again, one can do better for well-behaved input. The Probabilistic Lipschitzness (PL) condition [43,44] says that f is φ-PL if the probability mass of points that have non-zero mass of differently labeled points in a λD-ball around them is at most φ(λ). If a clustering function f is PL, it means the clusters are, in some sense, "round"-that the probability mass "close to" the boundaries of the clusters is small. Under this condition, we have the following sample complexity result for β. We can compare to a clustering with slightly tighter size constraints: Lemma 20. Let µ be a measure on R q with support X of diameter D. Let f * be the optimal clustering of µ that satisfies capacities ( + , L − ) and suppose f * is φ-PL. If we see a sample S drawn iid from µ of size O 1

Experiments
In this section, we present an empirical study of the accuracy and scalability of our technique using both the LP rounding algorithms and k-means++ together with the nearest neighbor extension. We compare against three baselines: random partitioning, balanced partition trees, and locality sensitive hashing (LSH) on both synthetic and real world image and advertising datasets. Our findings are summarized below: • Using small samples of the given datasets, we compare the clusterings produced by our LP rounding algorithms 2 and k-means++ (with balancing heuristics described shortly). We find that clusterings produced by k-means++ and the LP rounding algorithms have similar objective values and correlate well with the underlying class labels. These results complement the results of Section 3, showing that k-means++ produces high quality balanced clusterings for 'typical' data. This comparison is detailed in Sections 14 and 15 of the appendix. Based on this observation, our further empirical studies use k-means++.
• We compare the accuracy of our technique (using k-means++ and the nearest neighbor extension) to the three baselines for a wide range of values of k in large-scale learning tasks where each machine learns a local SVM classifier. For all values of k and all datasets, our algorithm achieves higher accuracy than all our baselines.
• We show that our framework exhibits strong scaling, meaning that if we double the available computing power, the total running time reduces by a constant fraction.
Experimental Setup: In each run of our experiment, one of the partitioning algorithms produces a dispatch rule from 10, 000 randomly sampled training points. This dispatch rule is then used to distribute the training data among the available worker machines. If the parameter k exceeds the number of machines, we allow each machine to process multiple partitions independently. Next we train a one-vs-all linear separator for each partition in parallel by minimizing the L2-regularized L2-loss SVM objective. This objective is minimized using Liblinear [25] when the data is small enough to fit in the each worker's memory, and L-BFGS otherwise (note that both solvers will converge to the same model). The regularization parameter is chosen via 5-fold cross validation. To predict the label of a new example, we use the dispatch rule to send it to the machine with the most appropriate model. All experimental results are averaged over 10 independent runs. Details for our technique: Our method builds a dispatch rule by clustering a small sample of data using k-means++ and uses the nearest neighbor rule to dispatch both the training and testing data. To ensure a balanced partitioning, we apply the following simple balancing heuristics: while there is any cluster smaller than n points, pick any such cluster and merge it with the cluster whose center is nearest. Then each cluster that is larger than Ln points is randomly partitioned into evenly sized clusters that satisfy the upper capacity constraint. This guarantees every cluster satisfies the capacity constraints, but the number of output clusters may differ from k. For the nearest neighbor dispatch, we use the random partition tree algorithm of Dasgupta and Sinha [22] for efficient approximate nearest neighbor search. We set = 1/(2k) and L = 2/k and p = 1, since our baselines do not support replication. Baselines: We compare against the following baselines: 3 Random Partitioning Points are dispatched uniformly at random. This baseline produces balanced partitions but does not send similar examples to the same machine.
Balanced Partition Trees Similarly to a kd-tree, this partitioning rule recursively divides the dataset by splitting it at the median point along a randomly chosen dimension. This is repeated until the tree has k leaves (where we assume k is a power of 2). This baseline produces balanced partitions and improves over random partitioning because each machine learns a local model for a different subset of the space. The drawback is that the partitioning may result in subsets that do not contain similar data points.
LSH Partitioning This baseline uses locality sensitive hash functions [6] to dispatch similar points to the same machine. Given an LSH family H, we pick a random hash h : R d → Z. Then a point x is assigned to cluster h(x) mod k. In our experiments, we use the concatenation of 10 random projections followed by binning [23]. See Section 14 in the appendix for details of the construction. This baseline sends similar examples to the same machine, but does not balance the cluster sizes (which is essential for practical data distribution).  MNIST-8M: We use the raw pixels of the MNIST-8M dataset [38]. It has 8M examples and 784 features.

CIFAR-10:
The CIFAR-10 dataset [33] is an image classification task with 10 classes. Following Krizhevsky et al. [34] we include 50 randomly rotated and cropped copies of each training example to get a training set of 2.5 million examples. We extract the features from the Google Inception network [42] by using the output of an early layer (in3c) and a later layer (in4d).

CTR:
The CTR dataset contains ad impressions from a commercial search engine where the label indicates whether the ad was clicked. It has 860K examples with 232 features.
Results: Our empirical results are shown in Figure 3. We do not report accuracies when the partitioning is imbalanced, specifically when the largest k/2 clusters contain more than 98% of the data. In practice, such a partitioning is essentially using only half of the available computing power. For all values of k and all datasets, our method has higher accuracy than all three baselines. The balanced partition tree is the most competitive baseline, but in Section 14 we present an additional synthetic distribution for which our algorithm drastically outperforms the balanced partition tree. For all datasets except CTR, the accuracy of our method increases as a function of k, until k is so large that each cluster becomes data starved. Our method combines the good aspects of both the balanced partition tree and LSH baselines by simultaneously sending similar examples to the same machines and ensuring that every machine gets roughly the same amount of data. In contrast, the balanced partition tree baseline both produce balanced clusters, but do not send similar examples to the same machines, and the LSH baseline sends similar examples to the same machine, but makes no attempt at balancing the partitions. The fact that we get higher accuracy than the LSH baseline demonstrates that it is not enough to send similar examples to the same machines without balancing, and that we get higher accuracy than balanced partition trees shows that simply balancing the cluster sizes is not sufficient.
Figure 3(f) shows the speedup obtained when running our system using 16, 32, or 64 workers compared to using 8. We clock the time taken for the entire experiment: the time for clustering a subsample, dispatch, training and testing.
In all cases, doubling the number of workers reduces the total time by a constant factor, showing that our framework strongly scales and can be applied to very large datasets.

Conclusion
In this work, we propose and analyze a new framework for distributed learning. Given that similar points tend to have similar classes, we partition the data so that similar examples go to the same machine. We cast the dispatching step as a clustering problem combined with novel fault tolerance and balance constraints necessary for distributed systems. We show the added constraints make the objective highly nontrivial, yet we provide LP rounding algorithms with provable guarantees. This is complemented by our results showing that the k-means++ algorithm is competitive on 'typical' datasets. These are the first algorithms with provable guarantees under both upper and lower capacity constraints, and may be of interest beyond distributed learning. We show that it is sufficient to cluster a small subsample of data and use a nearest neighbor extension technique to efficiently dispatch the remaining data. Finally, we conduct experiments for all our algorithms that support our theoretical claims, show that our framework outperforms several baselines and strongly scales.

Appendix 8 Related Work Continued
Capacitated k-center The (uniform) capacitated k-center problem is to minimize the maximum distance between a cluster center and any point in its cluster subject to the constraint that the maximum size of a cluster is L. It is NP-Hard, so research has focused on finding approximation algorithms. Bar-Ilan et al. [14] introduced the problem and presented the first constant factor polynomial time algorithm achieving a factor of 10, using a combinatorial algorithm which moves around clients until the capacities are satisfied, and the objective is approximately satisfied. The approximation factor was improved by Khuller et al. [30]. Cygan et al. [21] give the first algorithm for capacitated k-center with non-uniform capacities by using an LP rounding algorithm. The appoximation factor is not explicitly computed, although it is mentioned to be in the order of hundreds. [5] follows a similar procedure but with a dynamic rounding procedure, and they improve to an approximation factor of 8. Further, for the special case of uniform capacities, they show a 6-approximation.
Capacitated k-median k-median with capacities is a notoriously difficult problem in clustering. It is much less understood than k-center with capacities, and uncapacitated k-median, both of which have constant factor approximations. Despite numerous attempts by various researchers, still there is no known constant factor approximation for capacitated k-median (even though there is no better lower bound for the problem than the one for uncapacitated k-median). As stated earlier, there is a well-known unbounded integrality gap for the standard LP even when violating the capacity or center constraints by a factor of 2 − [1]. Charikar et al. gave a 16-approximation when constraints are violated by a factor of 3 [19]. Byrka et al. improved this violation to 2 + , while maintaining an O( 1 2 ) approximation [17]. Recently, Li improved the latter to O( 1 ), specifically, when constraints are violated by 2 + 2 α for α ≥ 4, they give a 6 + 10α approximation [36]. These results are all for the hard capacitated k-median problem. In the soft capacities variant, we can open a point more than once to achieve more capacity, although each extra opening counts toward the budget of k centers. In hard capacities, each center can only be opened once. The hard capacitated version is more general, as each center can be replicated enough times so that the soft capacitated case reduces to the hard capacitated case. Therefore, we will only discuss the hard capacitated case.
All of the algorithms for capacitated k-median mentioned above share the same high-level LP rounding and aggregation idea but with different refinements in the algorithm and analysis.

Universal and load balanced facility location
In the facility location problem, we are given a set of demands and a set of possible locations for facilities. We should open facilities at some of these locations, and connect each demand point to an open facility so as to minimize the total cost of opening facilities and connecting demands to facilities. Capacitated facility location is a variant where each facility can supply only a limited amount of the commodity. This and other special cases are captured by the Universal Facility Location problem where the facility costs are general concave functions. Local search techniques [39] have been proposed and applied successfully. Also, LP rounding techniques suffer from unbounded integrality gap for capacitated facility location [39].
Load-balanced facility location [29], [26], is yet another variant where every open facility must cater to a minimum amount of demand. An unconstrained facility location problem with modified costs is constructed and solved. Every open facility that does not satisfy the capacity constraint is closed and the demand is rerouted to nearby centers. The modified problem is constructed so as to keep this increase in cost bounded.

Details from Section 2
In this section, we provide the formal details for the bicriteria algorithm presented in Section 2.
For convenience, we restate Theorem 1 here.
Theorem 1 (restated). Algorithm 1 returns a constant factor approximate solution for the balanced k-clustering with p-replication problem for p > 1, where the upper capacity constraints are violated by at most a factor of p+2 p , and each point can be assigned to each cluster at most twice.
Step 1 details: We restate the LP for k-means and k-median for completeness, labeling each constraint for the proofs later.
As mentioned in Section 2, it is well-known that the standard capacitated k-median LP (this LP, without the lower bound constraint and with p = 1) has an unbounded integrality gap, even when the capacities are violated by a factor of 2 − [1]. The integrality gap is as follows. k = 2nL − 1, and there are nL groups of size 2nL − 1. Points in the same group are distance 0, and points in different groups are distance 1. Fractionally, we can open 2 − 1 nL facilities in each group to achieve cost 0. But integrally, some group contains at most 1 facility, and thus the capacity violation must be 2 − 1 nL . However, with p replication, there must be p centers per group, so the balance violation can be split among the p centers. Therefore, the integrality is only unbounded when the capacities are violated by a factor of p p−1 The k-center LP is a little different from the k-median/means LP. As in prior work [5,21,30], we guess the optimal radius, t. Since there are a polynomial number of choices for t, we can try all of them to find the minimum possible t for which the following program is feasible. Here is the LP for k-center.
For k-median and k-means, let C LP denote the objective value. For k-center, C LP would be the smallest threshold t at which the LP is feasible, however we scale it as C LP = tnp for consistency with the other objectives. For all j ∈ V , define the connection cost C j as the average contribution of a point to the objective. For k-median and k-means, it is C j = 1 p i∈V c ij x ij . That is, for k-median, it is the average distance of a point to its fractional centers while for k-means, it is the average squared distance of a point to its fractional centers. For k-center, C j is simply the threshold C j = t. Therefore, C LP = j∈V pC j in all cases.
The notation is summarized in table 1. Cost of assigning j to center i Avg cost of assignment of point j to all its centers Cost of LP j pC j ρ parameter for monarch procedure 2 4 1 Step 2 details: Let M be the set of monarchs, and for each u ∈ M, denote E u as the empire of monarch u. Recall that the contribution of an assignment to the objective c ij is d(i, j) for k-median, d(i, j) 2 for k-means, and t for k-center.
We also define a parameter ρ = 1 for k-center, ρ = 2 for k-median, and ρ = 4 for k-means, for convenience. Theorem 2 (restated). Let ρ be a parameter such that ρ = 1 for k-center, ρ = 2 for k-median, and ρ = 4 for k-means. The output of the monarch procedure satisfies the following properties: (1a) The clusters partition the point set; (1b) Each point is close to its monarch: ∀j ∈ E u , u ∈ M, c uj ≤ 2ρC j ; (1c) Any two monarchs are far apart: ∀u, u ∈ M s.t. u = u , c uu > 4 max{C u , C u }; (1d) Each empire has a minimum total opening: ∀u ∈ M, j∈Eu y j ≥ p 2 (or for k-center, j∈Eu y j ≥ p).
Proof. The first three properties follow easily from construction (for the third property, recall we ordered the points at the start of the monarch procedure). Here is the proof of the final property, depending on the objective function.
For k-center and k-median, it is clear that for some u ∈ M, if d(i, u) ≤ ρC u , then i ∈ E u (from the triangle inequality and Property (1c)). For k-means, however: if d(i, u) 2 ≤ 2C u , then i ∈ E u . Note that the factor is ρ/2 for k-means. This is because of the triangle inequality is a little different for squared distances.
To see why this is true for k-means, assume towards contradiction that ∃i ∈ V , u, u ∈ M, u = u such that u ∈ E u and d(i, u) 2 ≤ 2C u . Then d(i, u ) ≤ d(i, u) by construction. Therefore, d(u, u ) 2 ≤ (d(u, i) + d(i, u )) 2 ≤ 4d(i, u) 2 ≤ 8C u , and we have reached a contradiction by Property (1c). Now, to prove property (1d): k-center: From the LP constraints, for every u, j∈V x ju = p. But x ju is non-zero only they are separated by at most t, the threshold. Combining this with the fact that if d(j, u) ≤ C u = t, then j ∈ E u , we get, for each u ∈ M: j∈Eu y j ≥ j∈Eu x ju = p k-median and k-means: Note that C u is a weighted average of costs c iu with weights x iu /p, i.e., C u = i c iu xiu /p. By Markov's inequality, Combining this with the fact that if c ju ≤ 2C u , then j ∈ E u for both k-median and k-means , we get, for each u ∈ M: Step 3 Details: First we define the suboperation Move [36]: Definition 2 (Operation "Move"). The operation "Move" moves a certain opening δ from a to b. Let (x , y ) be the updated (x, y) after a movement of δ ≤ y a from a to b. Define y a = y a − δ It has been proven in previous work that the move operation does not violate any of the LP constraints except the constraint that y i ≤ 1 [36]. We provide a proof below for completeness. Should we require δ ≤ min(y a , 1 − y b ), the constraint y i ≤ 1 would not be violated. But to get a bicriteria approximation, we allow this violation. The amount by which the objective gets worse can then be bounded by the triangle inequality. Proof. To show that the Move operation satisfies all the LP constraints, first note that the only quantities that change are y a , y b , x au , x bu , ∀u ∈ V . Further, x, y satisfy all the constraints of the LP. Using this, • Non-negative constraint: this is true since δ ≤ y a . See Algorithm 4 for the aggregation procedure.
Let v be the point farthest from u with nonzero y v .

5
Let v be the point closest to j with y v = z u . 6 Move min{y v , z u − y v } units of opening from y v to y v .

Algorithm 4: Aggregation procedure
We restate Lemma 4 and give a full proof.
Proof. k-center. Use the fact that all C j = t, and x ij > 0 =⇒ d(i, j) ≤ t with property (1b) to get: k-median. By construction, if the demand of point j moved from i to i, then ∃u ∈ M s.t. i, i ∈ E u and d(u, i) ≤ d(u, i ). Denote j as the closest point in M to j. Then d(u, i ) ≤ d(j , i ) because i ∈ E u . Then, k-means: The argument is similar to k-median, but with a bigger constant factor because of the squared triangle inequality.
Step 4 details: Set {i | y i = 0} = Y . We show details of the min cost flow network in Algorithm 5.
Input: V , (x, y), y are integral Output: updated (x, y) with integral x's and y's 1 Create a flow graph G = (V , E) as follows. 2 Add each i ∈ V to V , and give i supply p. 3 Add each i ∈ Y to V , and give i demand n . 4 Add a directed edge (i, j) for each i ∈ V , j ∈ Y , with capacity 2 and cost c ij (for k-center, make the edge weight 5t if d(i, j) ≤ 5t and +∞ otherwise. 5 Add a sink vertex v to V , with demand np − kn . 6 Add a directed edge (i, v) for each i ∈ Y , with capacity p+2 p nL − n and cost 0. 7 Run an min cost integral flow solver on G. 8 Update x by setting x ij to 0, 1, or 2 based on the amount of flow going from i to j.
Algorithm 5: Min cost flow procedure: Set up flow problem to round x's Lemma 22. There exists an integral assignment of the x ij 's such that ∀i, j ∈ V , x ij ≤ 2 and it can be found in polynomial time.
Proof. See Algorithm 5 and Figure 2 for the details of the flow construction. In this graph, there exists a feasible flow: ∀i, j ∈ V , send x ij units of flow along the edge from i to j, and send j∈V x ij units of flow along the edge from i to v. Therefore, by the integral flow theorem, there exists a maximal integral flow which we can find in polynomial time. Also, by construction, this flow corresponds to an integral assignment of the x ij 's such that x ij ≤ 2. Now we are ready to prove Theorem 1. The approximation ratios are 5, 11, and 95 for k-center, k-median, and k-means, respectively.
Proof of Theorem 1. k-center: Recall that we defined C LP = tnp, where t is the threshold for the k-center LP. From Lemma 4, when we reassign the demand of point j from i to i, d(i, j) ≤ 5t. In other words, the y-rounded solution is feasible at threshold 5t. Then the k-center cost of the new y's is np(5t) = 5C LP . From Lemma 22, we can also round the x's at no additional cost.
k-median: From Property 4, when we reassign the demand of point j from i to i, d(i, j) ≤ 3d(i , j) + 8C j . Then we can bound the cost of the new assignments with respect to the original LP solution as follows.
i∈V j∈V Then from Lemma 22, we get a solution of cost at most 11C LP , which also has integral x's. k-means: The proof is similar to the k-median proof. From lemma 4, when we reassign the demand of point j from i to i, d(i, j) 2 ≤ 15d(i , j) 2 + 80C j . Then we can bound the cost of the new assignments with respect to the original LP solution as follows.
i∈V j∈V Then from Lemma 22, we get a solution of cost at most 95C LP , which also has integral x's.

See Algorithm 6 for the final algorithm.
Input: V Output: Integral (x, y) corresponding to bicriteria clustering solution Approach As in the previous section and in prior work [5,21,30], we start off by guessing the optimal distance t. Since there are a polynomial number of possibilities, it is still only polynomially expensive. We then construct the threshold graph G t = (V, E t ), with j being the set of all points, and (x, y) ∈ E t iff d(x, y) ≤ t.
A high-level overview of the rounding algorithm that follows is given in Algorithm 7. Connection to the previous section: The algorithm here is similar to the bicriteria algorithm presented previously. There are, however, two differences. Firstly, we work only with connected components of the threshold graph. This is necessary to circumvent the unbounded integrality gap of the LP [21]. Secondly, the rounding procedure of the y's can now move opening across different empires. Since the threshold graph is connected, the distance between any two adjacent monarchs is bounded and turns out to exactly be thrice the threshold. This enables us to get a constant factor approximation without violating any constraints. The approach is to guess the optimal threshold, construct the threshold graph at this threshold, write and round several LPs for each connected component of this graph for different values of k. The intuition behind why this works is that at the optimal threshold, each cluster is fully contained within a connected component (by definition of the threshold graph).
We the round the opening variables, but this time, open exactly k centers. Most of the work goes into rounding the openings, and showing that it is correct. Then, we simply round the assignments using a minimum cost flow again.

Linear Program
As earlier, let y i be an indicator variable to denote whether vertex i is a center, and x ij be indicators for whether j belongs to the cluster centered at i. By convention, i is called a facility and j is called a client.
Consider the following LP relaxation for the IP for each connected component of G. Note that it is exactly the same as the one from the previous section, except it is described in terms of the threshold graph G. Let us call it LP-k-center(G): Once we have the threshold graph, for the purpose of k-center, all distances can now be measured in terms of the length of the shortest path in the threshold graph. Let d G (i, j) represent the distance between i and j measured by the length of the shortest path between i and j in G.

Connected Components
It is well known [21] that even without lower bounds and replication, the LP has unbounded integrality gap for general graphs. However, for connected components of the threshold graph, this is not the case.
To begin with, we show that it suffices to be able to do the LP rounding procedure for only connected threshold graphs, even in our generalization. Theorem 23. If there exists an algorithm that takes as input a connected graph G, capacities , L, replication p, and k for which LP-k-center(G t ) is feasible, and computes a set of k centers to open and an assignment of every vertex j to p centers i such that d G (i, j) ≤ r satisfying the capacity constraints, then we can obtain a r-approximation algorithm to the balanced k-centers problem with p-replication.
Proof. Let connected component i have k i clusters. For each connected component, do a linear search on the range [1, . . . , k] to find values of k i for which the problem is feasible. These feasible values will form a range, if size constraints are to be satisfied. To see why this is the case, note that if (x 1 , y 1 ) and (x 2 , y 2 ) are fractional solutions for k = k 1 and k = k 2 respectively, then ((x 1 + x 2 )/2, (y 1 + y 2 )/2) is a valid fractional soluion for k = (k 1 + k 2 )/2.
Suppose the feasible values of k i are m i ≤ k i ≤ M i . If i m i > k or i M i < k, return NO (at this threshold t). Otherwise, start with each k i equal to m i . Increase them one by one up to M i until i k i = k. This process takes polynomial time.
From now on, the focus is entirely on a single connected component.

Rounding y
Given an integer feasible point to the IP for each connected component, we can obtain the desired clustering. Hence, we must find a way to obtain an integer feasible point from any feasible point of LP-k-center.
To round the y, we follow the approach of An et al. [5]. The basic idea is to create a coarse clustering of vertices, and have the cluster centers form a tree. The radius of each cluster will be at most 2, and the length of any edge in the tree will exactly be three, by construction. Now, to round the y, we first start from the leaves of the tree, moving opening around in each coarse cluster such that at most one node (which we pick to be the center, also called the monarch). In subsequent steps, this fractional opening is passed to the parent cluster, where the same process happens. The key to getting a constant factor approximation is to ensure that fractional openings that transferred from a child cluster to a parent cluster are not propagated further. Note that the bicriteria algorithm did not move opening from one coarse cluster (empire) to another because we didn't have an upper bound of the cost incurred by making this shift. Preliminaries.: We start with some definitions.
Definition 3 (δ-feasible solution [21]). A solution (x, y) feasible on G δ , the graph obtained by connecting all nodes within δ hops away from each other.
Next, we introduce the notion of a distance-r shift. Intuitively, a distance-r shift is a series of movements of openings, none of which traverses a distance more than r in the threshold graph. Note that the definition is similar to what is used in An et al. [5].
Definition 4 (Distance-r shift ). Given a graph G = (V, E) and y, y ∈ R |V | ≥0 , y is a distance-r shift of y if y can be obtained from y via a series of disjoint movements of the form "Move δ from i to i " where δ ≤ min(y i , 1 − y i ) and every i and i are at most a distance r apart in the threshold graph G. Further, if all y are zero or one, it is called an integral distance-r shift.
Note that, by the definition of a distance-r shift, each unit of y moves only once and if it moves more than once, all the movements are put together as a single, big movement, and this distance still does not exceed r.
Lemma 24 (Realizing distance-r shift). For every distance-r shift y of y such that 0 ≤ y i ≤ 1 ∀i ∈ V , we can find x in polynomial time such that (x , y ) is (r + 1)-feasible.
Proof. We can use the Move operation described earlier and in Cygan et al. [21] to change the corresponding x for each such a movement to ensure that the resulting (x , y ) are (r + 1)-feasible. The additional restriction δ ≤ 1 − y b ensures that y ≤ 1. Since each unit of y moves only once, all the movements put together will also lead a solution feasible in G r+1 , i.e. we get a (r + 1)-feasible solution.
From here on, we assume that x ij , x i j are adjusted as described above for every movement between i and i . The algorithm to round y [5] proceeds in two phases. In the first phase, we cluster points into a tree of coarse clusters (monarchs) such that nearby clusters are connected using the monarch procedure of Khuller et al [30]. In the second phase, fractional opening are aggregated to get an integral distance-5 shift. Monarch Procedure.: The monarch procedure is presented a little differently but is very similar to the monarch procedure presented earlier. Since the threshold graph is connected, we can get guarantees on how big the distance between two monarchs is.
Algorithm 8 describes the first phase where we construct a tree of monarchs and assign empires to each monarch. Let M be the set of all monarchs. For some monarch, u ∈ M, let E u denote its empire. For each vertex i, let m(i) denote the the monarch u to whose empire E u , i belongs.
The guarantees now translate to the following (Lemma 25): • Empires partition the point set.
• The empire includes all immediate neighbors of a monarch and additionally, some other nodes of distance two (called dependents).
• Adjacent monarchs are exactly distance 3 from each other.
Lemma 25. Algorithm 8, the monarch procedure is well-defined and its output satisfies the following: Output: Tree of monarchs, T = (M, E ), and empires for each monarch 1 Marked ← ∅ 2 foreach j ∈ V do 3 initialize ChildMonarchs(j) and Dependents(j) to ∅ 4 Pick any vertex u and make it a monarch 5 E u ← N + (u); Initialize T to be a singleton node Make u a monarch and assign its empire to be E u ← N + (u) 10 Marked Algorithm 8: Monarch Procedure: Algorithm to construct tree of monarchs and assign empires • The distance between a monarch and any node in its empire is at most 2.
• Distance between any two monarchs adjacent in T is exactly 3.
• If ChildMonarchs(j) = ∅ or Dependents(j) = ∅, then j is at distance one from some monarch.
Proof. Note that the whole graph is connected and V = ∅. For the while loop, if there exists w such that d G (w, Marked) ≥ 2, there exists u such that d G (u, Marked) = 2 because the graph is connected. By the end of the while loop, there are no vertices at a distance 2 or more from Marked. Hence, vertices not in Marked, if any, should be at a distance 1 from Marked. Thus, the algorithm is well defined.
Each time a new monarch u is created, N + (u) is added to its empire. This shows the first statement. The only other vertices added to any empire are the dependents in the foreach loop. Each dependent j is directly connected to i, a marked vertex. Hence, i has to be a neighbor of a monarch. If i were a monarch, j would have been marked in the while loop. Thus, d G (j, m(i)) = 2.
If the first statement of the while loop, v is a marked vertex, and has to be a neighbor of some monarch m(v).
Initial Aggregation.: Now, we shall turn to the rounding algorithm of An et al [5]. The algorithm begins with changing y u of every monarch u ∈ M to 1. Call this the initial aggregation. It requires transfer of at most distance one because the neighbors of the monarchs has enough opening.
Lemma 26. The initial aggregation can be implemented by a distance-1 shift.
Proof. For every vertex u ∈ V , we have j∈N (u) y j ≥ j∈N (u) x uj = p ≥ 1. Hence, there is enough y-mass within a distance of one from u. The actual transfer can happen by letting δ = min(1 − y u , y j ) for some neighbor j of u and then transferring δ from j to u. That is, y j = y j − δ and y u = y u + δ.
Rounding.: The rounding procedure now proceeds in a bottom-up manner on the tree of monarchs, rounding all y using movements of distance 5 or smaller. After rounding the leaf empires, all fractional opening, if any is at the monarch. For internal empires, the centers of child monarch (remnants of previous rounding steps) and dependents are first rounded. Then the neighbors of the monarch are rounded to leave the entire cluster integral except the monarch. The two step procedure is adopted so that the opening propagated from this monarch to its parent originates entirely from the 1-neighborhood of the monarch.
Formally, at the end of each run of round on u ∈ M, all the vertices of the set I u are integral, where I u := (E u \ u) ∪ ( j∈N (u) ChildMonarchs(j)).
Input: Tree of monarchs, T , and empires for each monarch after the initial aggregation Output: y , an integral distance-5 shift of y 1 Procedure Round(Monarch u) Choose a vertex w with non-zero opening from Move δ from j to i Algorithm 9: Algorithm to round y The rounding procedure is described in detail in Algorithm 9. The following lemma states and proves that algorithm 9 rounds all points and doesn't move opening very far.
• Round(u) makes the vertices of I u integral with a set of opening movements within I u ∪ {u}.
• This happens with no incoming movements to the monarch u after the initial aggregation.
• The maximum distance of these movements is five, taking the initial aggregation into account.
Proof. Integrality. From lemma 25, it can be seen that X j , j ∈ N (u) above form a partition of I u . Hence, it suffices to verify that each node of every X j is integral.
At the end of line 8, the total non-integral opening in X j is y(X j ) − y(X j ) , and is hence smaller than one. Line 9 moves all these fractional openings to j. By now, all openings of X j \ {j} are integral. Now, F is the set of all non-integral j ∈ N (u). So, by the end of line 13, the total non-integral opening in N (u) (and hence in all of I u ) is y(F \ W F ) = y(F ) − y(F ) , and is again smaller than one. If this is zero, we are done.
Otherwise, we choose a node w * , shift this amount to w * in line 17. To make this integral, this operations also transfers the remaining amount, i.e. 1 − y(F \ W F ) from the monarch u. If this happens, the monarch u's opening is no longer integral, but I u 's is.
This shows the first bullet. For the second one, notice that after the initial aggregation, this last operation is the only one involving the monarch u and hence, there are no other incoming movements into u.
Distance. In the first set of transfers in line 8 the distance of the transfer is at most 4. This is because dependents are a distance one away from j and child monarchs are at a distance two away. The maximum distance is when the transfer happens from one child monarch to another, and this distance is 4 (recall that there are no incoming movements into monarchs).
The transfers in line 9 moves openings from a child monarch or a dependent to j. The distances are 2 and 1 respectively. Accounting for the initial aggregation, this is at most 3.
The rounding on line 13 moves openings between neighbors of the monarch, i.e. from some j to j where j, j ∈ N (u). So, the distance between j and j is at most 2. From the preceding transfers, the openings at j moved a distance of at most three to get there, and thus, we conclude that openings have moved at most a distance of 5 so far.
The first step of rounding on line 17 moves openings from some j to w * , where j, w * ∈ N (u). As above, the maximum distance in this case is 5. The second step of rounding on line 17 moves opening from the monarch u to its neighbor w * . This distance is one, and after accounting for the initial aggregation, is 2.
From this, we see that the maximum distance any opening has to move is 5.
The algorithms, their properties in conjunction with lemma 24 leads to the following theorem, which also summarizes this subsection.
Theorem 28. There exists a polynomial time algorithm to find a 6-feasible solution with all y integral.

Rounding x
Once we have integral y, rounding the x is fairly straight-forward, without making the approximation factor any worse. Exactly the same procedure used in bicriteria algorithms works here too. But, we can have an easier construction since for k-center since we can use distances in the threshold graph instead.
Theorem 29. There exists a polynomial time algorithm that given a δ-feasible solution (x, y) with all y integral, finds a δ-feasible solution (x , y) with all x integral.
Proof. We shall use a minimum cost flow network to this. Consider a directed bipartite graph (S, T, E ), where S = V and T = {i : y i = 1} and j → i ∈ E iff x ij > 0. Add a dummy vertex s, with edges to every vertex in S, and t with edges from every vertex in T . In this network, let every edge of the bipartite graph have capacity 1. Further, all the s → S edges have capacity p. s supplies a flow of np units, while each u ∈ T has a demand of l units. To ensure no excess demand or supply, t has a demand of np − kl. All the t → T edges have a capacity of (L − ).
All the s → S edges have a cost of −1 and every other edge has a cost of zero. See figure 4. Clearly, a feasible assignment (x, y) to LP-k-center(G δ ) with integral y is a feasible flow in this network. In fact, it is a minimum-cost flow in this network. This can be verified by the absence of negative cost cycles in the residual graph (because all negative cost edges are at full capacities).
Since, the edge capacities are all integers, there exists a minimum cost integral flow by the Integral Flow Theorem. This flow can be used to fix the cluster assignments.
Piecing together theorems 28 and 29, we have the following theorem: Theorem 30. Given an instance of the k-centers problem with p-replication and for a connected graph G, and a fractional feasible solution to LP-k-center(G), there exists a polynomial time algorithm to obtain a 6-feasible integral solution. That is, for every i, j such that x ij = 0, we have d G (i, j) ≤ 6.

Proofs from Section 3 k-means++:
We provide the full details for Theorem 5.
Proof. Wlog, we set d(c 1 , c 2 ) 2 = 1 for ease of computation (scaling all distances does not affect the optimal clustering). Let A = x∈X1,y∈X2 d(x, y) 2 and B = x,y∈X d(x, y) 2 . Then the probability is A/B. Let c 1 and c 2 denote the centers of mass of X 1 and X 2 , respectively. By Lemma 6, d( B = x,y∈X d(x, y) 2 = n 2 w 2 avg + n 1 n 2 ≤ n 1 n 2 ( 5 4 · α · n 2 n1n2 + 1) ≤ n 1 n 2 (1 + ρ L 2 2 ). Therefore, 1+O( L ·ρ) . Now we prove Theorem 5. We assume k ≤ α , which is reasonable for real-world data which does not have too many clusters and is sufficiently stable. We need this assumption so that we can set ρ > ·k α . We still assume that L ∈ O( ). Assume that we sample k pointsĉ 1 , . . .ĉ k . We start with a lemma similar to Lemma 8.

Proof.
Summing over all i, j, we have the following.
Proof. This follows from the previous lemma.
Now we analyze the case where we sample more than k points. Let N = 2k 1−5ρ .
Lemma 34. Say we sample N points. The probability that for all i ∈ [k], there is some sampled point in X i , is ≥ 1 − ρ.
Proof. The proof follows from Lemma 33.
Finally, we perform a greedy removal phase. We refer the reader to [40] since the analysis is the same. This finishes the proof of Theorem 5. k-median: Given a clustering instance (S, d) which satisfies (1 + α, )-approximation stability with respect to balanced k-median, for some (l, L, k). We denote C = {C 1 , . . . , C k } as the optimal partition and c 1 , . . . , c k as the optimal centers. Denote w avg as the average distance from a point to its center in the optimal solution. Given a point x, define w(x) as the distance to its center, and in general, for all i, denote w i (x) as the distance to the center c i of cluster C i in the optimal solution. Note, we will discuss the p-replication variant at the end of this section.
Lemma 35. Assume the size of the optimal clusters are > 4 n(1 + 6 α ). Then, • For < n 2 points x, there exists a set of ≥ n 2 points y from different clusters such that d(x, y) ≤ αw 2 avg . Proof.
• Assume the statement is false. Then there exist n 2 pairs of distinct points (x, y) such that d(x, y) ≤ αw 2 avg (for example, because of Hall's theorem). Now we create a new partition C by swapping the points in each pair, i.e., for a pair x ∈ C i and y ∈ C j , put x into C j and y into C i . Then for a single swap, the increase in cost is avg . Therefore, the total difference in cost from OPT Φ to Φ(C ) is then αOPT Φ . Note that since we only performed swaps, C still satisfies all the capacity constraints of Φ. Furthermore, (C) is -close to OPT Φ (since all clusters are size > 2 n, the optimal bijection between (C) and OPT Φ is the identity). This contradicts the approximation stability property.
• This follows simply from Markov's inequality.
Define x ∈ C i as a good point if there are less than 2 points y / ∈ C i such that d(x, y) ≤ αw 2 avg , and w(x) < αw 2 avg 6 . If a point is not good, then call it bad. Denote the set of bad points by B. For all i, denote X i = {x ∈ C i | x is good}. Then Lemma 35 implies that if the optimal clusters are size > 2 n, |B| < n(1 + 6 α ). Now we show that the optimal centers are sufficiently far apart. Proof. Given a cluster C i . Since there are < n 2 and < 6 n α points which do not satisfy properties 1 and 2 from Lemma 35, then at least one point from each cluster satisfies both properties, i.e., is a good point. Then given i, j, let x i ∈ C i and x j ∈ C j be good points.
Combining Lemmas 35 an 36 implies that the threshold graph with distance 2 3 · αw 2 avg will contain mostly "good" edges between good points from the same cluster. The rest of the argument for showing correctness of the algorithm is similar to the analysis in [10]. We include it here for completeness.
The following lemma is similar to Lemma 3.5 from [10]. We need to assume the clusters are larger, but our proof generalizes to capacitated k-median.
Lemma 37. Assume the optimal cluster sizes are ≥ n 2 (1 + 3 α ). For τ = αw 2 avg 3 , the threshold graph G τ has the following properties: • There is an edge between any two good points x, y in the same cluster C i , • There is not an edge between any two good points x, y in different clusters; furthermore, these points do not even share a neighbor in G τ . Proof.
• Since x and y are both good, d(x, y) ≤ w(x) + w(y) ≤ by the triangle inequality.
• Assume x and y have a common neighbor z. Consider a point y 2 from y's cluster such that w(y 2 ) ≤ αw 2 avg 6 .
By assumption, there are at least n 2 such points. Furthermore, d(x, y 2 ) ≤ d(x, z) + d(z, y) + d(y, y 2 ) ≤ 2τ + w(y) + w(y 2 ) ≤ avg . Since x is close to at least n 2 points from different clusters, x cannot be a good point, so we have reached a contradiction.
Then the threshold graph is as follows. Each X i forms a clique, the neighborhood of X i is exactly X i ∪ B, and for all i = j, N (X i ) ∪ N (X j ) = ∅. This facilitates an algorithm for clustering in this setting, following analysis that is similar to [10].

Lemma 38 ([10]
). There is an efficient algorithm such that, given a graph G satisfying the properties of Lemma 37, and given b ≥ |B| such that each |X i | ≥ b + 2, outputs a k-clustering with each X i in a distinct cluster.
The proof of this theorem, given in [10], depends solely on the properties of Lemma 37.

Lemma 39.
There is an efficient algorithm such that if a clustering instance satisfies (1 + α, )-approximation stability for the balanced k-median objective and all clusters are size ≥ 3 n(1 + 3 α ), then the algorithm will produce a clustering that is O( α )-close to the optimal clustering.
Proof. First we use the proof of Theorem 3.7 from [10] (which assumes w 2 avg is known) to the point where they achieve error O( α ) by using their version of Lemma 38. They go on to lower the error to , but this part of the proof breaks down for us. For the case of unknown w 2 avg , we can use the same fix as in the proof of Theorem 3.8 from [10].
However, there is a problem with Lemma 39: even though it returns a clustering with small error, the capacity constraints might be violated. We can fix the capacity violations if we double our error.
Lemma 40. Given an > 0 and a clustering C , if C is -close to the optimal clustering, then it is possible in polynomial time to construct a valid clustering C which is 2 -close to the optimal clustering. Proof. For each cluster C i in C, let v i be the number of points for which C i violates the capacity, i.e., |C i | − L or l − |C i | or 0. Clearly, i v i ≤ n, or else C would not be -close to the optimal. Then we can iteratively take a point from the largest cluster, and place it into the smallest cluster. In each iteration, i v i is reduced by at least 1. So in ≤ n rounds, we reach a valid clustering, and the error is only more than C .
Theorem 10 follows immediately from the previous lemma. Note that all of the proofs in this section can be trivially extended to the case where there is p-replication. However, p-replication does not mesh well with stability assumptions. Although Theorem 10 works completely under p-replication, all but an -fraction of the data appears to have "trivial" replication, in which there are k p groups of data, each of which have nearly the same p centers. This makes the problem similar to a k p -clustering problem, up to n points. The reason for this phenomenon is the following. If good points x i and x j share center c in addition to having other centers c i and c j , then by the triangle inequality, c i and c j are close together. This would contradict Lemma 36 unless each pair of good points either have p centers in common, or no centers in common.

Examples of balanced approximation stable instances:
In this section, we explicitly construct clustering instances which satisfy approximation stability for balanced clustering, but not for approximation stability for unbalanced clustering.
Given n, α, , , L, and let k = 2. Denote the two optimal centers as c 1 and c 2 . Let d(c 1 , c 2 ) = 1.9. We place x ≤ n α points at distance 1 from c 1 , and .9 from c 2 . Call this set of points A. Then we place n − x points at distance 0 from c 1 (denote by B 1 ), and we place the rest of the points at distance 0 from c 2 (denote by B 2 ). We need to assume that n − x ≥ 0. Then for balanced clustering, C 1 = A ∪ B 1 , and C 2 = B 2 , because C 1 must contain at least n points. The optimal cost is x. For standard clustering, C 1 = B 1 , and C 2 = A ∪ B 2 , and the optimal cost is .9x. This clustering instance is not ( 10 9 , x n )approximation stable for standard clustering: all points in A can move from C 2 to C 1 , incurring a cost of .1x to the objective.
However, this clustering instance is (1+α, )-approximation stable for the balanced clustering objective. Moving any point to a different cluster incurs a cost of at least 1. Given a partition with cost (1+α)x = x+α·x ≤ x+α n α ≤ x+ n. Then less than n points have switched clusters. k-center: Now we will prove Theorem 11. Given a clustering instance, denote its optimal balanced k-center radius by r * .
Lemma 41. Given a clustering instances satisfying (2, 0)-approximation stability for balanced k-center, then for all Proof. Consider the graph in Figure 4, where n = 86, and set n = 21. Since the distances are all 1 or 2, this construction is trivially a valid distance metric. From Figure 4, we see that k = 2 and k = 4 have valid clusterings using only length 1 edges, using centers {y 1 , y 2 } and {x 1 , x 2 , x 3 , x 4 }, respectively. But now consider k = 3. The crucial property is that by construction, y 1 and any x i cannot simultaneously be centers and each satisfy the capacity to distance 1 points, because the union of their distance 1 neighborhoods is less than 2n . So we cannot just take the centers from k = 2 and add a center from k = 4. Formally, we show no possible set of 3 centers can be distance 1 to all points without violating the lower bound on the cluster sizes. Case 1: the set of centers includes a point p not in {x 1 , x 2 , x 3 , x 4 , y 1 , y 2 }. The rest of the points are only distance 1 from exactly two points, so p cannot hit the lower bound of 21 using only distance 1 assignments.
Case 2: the set of centers is a subset of {x 1 , x 2 , x 3 , x 4 }. Then there are clearly 20 points which are not distance 1 from the three centers.
Case 3: the set of centers includes both y 1 and y 2 . Then we need to pick one more center, x i . x i is distance 1 from 20 middle points, plus {x 1 , x 2 , x 3 , x 4 , y 1 , y 2 }, so 26 total. y 1 is also distance 1 from 20 middle points and {x 1 , x 2 , x 3 , x 4 , y 1 , y 2 }. y 1 and x i share exactly 5 neighbors from the middle points, plus {x 1 , x 2 , x 3 , x 4 , y 1 , y 2 } as neighbors. Then the union of points that x i and y 1 are distance 1 from, is 26 + 26 − 11 = 41, which implies that x i and y 1 cannot simultaneously reach the lower bound of 21 with only distance 1 points.
Case 4: the set of centers does not include x i nor y j . By construction, for each pair x i and y j , there exists some middle points which are only distance 1 from x i and y j .
These cases are exhaustive, so we conclude OPT 3 must be strictly larger than OPT 2 and OPT 4 (no matter what objective we use). Now we give the full proof for Theorem 15.
Lemma 15 (restated). For all m ∈ N, there exists a balanced clustering instance in which the k-center, k-median, and k-means objectives contain m local maxima, even for soft capacities.
Proof. Setup. Set k min = 10 · m, and k max = 12m. Define K good = {k | k min ≤ k ≤ k max and 2 | k}. Similarly, let K bad = {k | k min ≤ k ≤ k max and 2 k}. Note |K bad | = m and |K good | = m + 1. For all k ∈ K good , define Just like in the last proof, the edges later correspond to a distance of 1, and all other distances are 2. We will construct Y and E such that for all k ∈ K good , all the neighbors of X k form a partition of Y , i.e. ∀k ∈ K good , i N (x So taking X k as the centers corresponds to a k-clustering in which all points are distance 1 from their center. We will also show that for all k ∈ K bad , it is not possible to find a valid set of centers for which every point has an edge to its center, unless the capacities are violated. This implies that all m points in K bad are local maxima. For all k ∈ K good , X k will have exactly kmax k l edges in Y Thus, set n = k∈K good k to make all of these values integral. Note that some points (those in X kmax ) have exactly n edges, and all points have ≤ 6 5 n edges (which is tight for the points in X kmin ). Now we define the main property which drives the proof. We say x n . Note this immediately implies it is not possible to include them in the same set of centers such that each point has an edge to its center, since N (x i2 ) < 2 · 6 5 n − 2 5 n = 2n . Outline. We will construct Y in three phases. First, we add edges to ensure that for all x i2 . It follows that if we are trying to construct a set of centers from X for k ∈ K bad , we will not be able to use any complete X k as a subset. These are called the backbone edges.
The next phase is to add enough edges among points in different X k 's so that no subset of X (other than the X k 's) is a complete partition of Y . We will accomplish this by adding a bunch of points to Y shared by various x ∈ X, so that each x has edges to k max points in Y . These are called the dispersion edges.
The final phase is merely to add edges so that all points reach their assigned capacity. We do this arbitrarily. These are called the filler edges.
Note whenever we add a point to Y , for all k ∈ K good , we need to add an edge to exactly one x ∈ X k , which will ensure that all X k 's form a partition of Y .
Phase 1: Backbone edges. Recall that for k, k ∈ K good , we want ∀i, ∃j such that x (k) i overlaps with x (k ) j . Since k max = 6 5 k min , some x's will be forced to overlap with two points from the same X k . However, we can ensure no point overlaps with three points from the same X k .
We satisfy all overlappings naturally by creating k min components, CC 1 to CC kmin . Each component CC i contains point x (kmin) i . The rest of the sets X k are divided so that one or two points are in each component, as shown in Figure 5. Formally, in component CC i , sets X kmin to X kmin+ i 2 have one point in the component, and all other sets have two points in the component.
For each component CC i , we add 4 5 n points to Y , split into two groups of 2 5 n . The points from sets X kmin+ i 2 have edges to all 4 5 n points, and the points from the rest of the sets (since there are two from each set) have edges to one group of 2 5 n points. Therefore, for all k, k ∈ K good , each point x ∈ X k belongs to some component CC i , and overlaps with some x ∈ X k , so all of the overlapping requirements are satisfied (only using points within the same component).
This completes phase 1. Each point in X had at most 4 5 n edges added, so every point can still take at least n 5 more edges in subsequent phases.
Phase 2: Dispersion edges. Now we want to add points to Y to ensure that no set of at most k max points from X create a partition of Y , except sets that completely contain some X k .
We have a simple way of achieving this. For every (x 1 , x 2 , . . . , x m+1 ) ∈ X kmin × X kmin+2 × · · · × X kmax , add one point to Y with edges to x 1 , x 2 , . . . , x m+1 . Then we have added k∈K good k total points to Y in this phase.
This completes phase 2. Phase 3: Filler edges. The final step is just to fill in the leftover points, since we want every point x (k) i to have kmin k l points total. All of the mechanisms for the proof have been set up in phases 1 and 2, so these final points can be arbitrary.
We greedily assign points. Give each point x , the number of extra points it needs. Take the point x ∈ X k with the minimum t, and create t points in Y with x. For each layer other than X k , add edges to the point with the smallest number. Continue this process until t = 0 for all points.
Final Proof. Now we are ready to prove that G has m local maxima. By construction, for all k ∈ K good , X k is a set of centers which satisfy the capacity constraints, and every point has an edge to its center. Now, consider a set C of centers of size k ∈ K bad . We show in every case, C cannot satisfy the capacity constraints with all points having edges to their centers.
Case 1: C contains a point y ∈ Y . y only has m edges, which is much smaller than n . Case 2: There exists k ∈ K good such that X k ⊆ C. Then since |C| / ∈ K good , ∃x ∈ C \ X k . By construction, there exists x (k) i ∈ X k such that x and x (k) i are overlapping. Therefore, both centers cannot satisfy the capacity constraints with points they have an edge to.
Case 3: For all k ∈ K good , there exists x ∈ X k such that x / ∈ C. Take the set of all of these points, x 1 , x 2 , . . . , x m+1 . By construction, there is a point y ∈ Y with edges to only these points. Therefore, y will not have an edge to its center in this case.
This completes the proof.

Proofs from Section 5
We begin by introducing some notation for the classes of clusterings that satisfy the capacity constraints over the entire space with respect to µ, the weighted capacity constraints over the set S, and the estimated capacity constraints on the set S: For any lower bound and upper bound L on the cluster capacities, we denote the set of cluster assignments over X that satisfy the capacity constraints by Similarly, for the samples S, for true and estimated weights, define the sets of feasible assignments respectively as: Ĝ n ( , L) = g : S → k p : Bounding α(S): In this section, we prove the following Lemma bounding the α term from Theorem 18: Lemma 19. For any , δ > 0, and X ⊆ R q , if a randomly drawn S from µ is of size O(q q/2 −(q+1) (q log √ q + log 1 δ )) in the general case, or First we show that when the set X is bounded in R q , then for a large enough sample S drawn from µ, every point x ∈ X will have a close neighbor uniformly with high probability. Proof. Let C be the smallest cube containing the support X . Since the diameter of X is D, the side length of C is at most D. Let s = r/ √ q be the side-length of a cube in R q that has diameter r. Then it takes at most m = D/s q cubes of side-length s to cover the set C. Let C 1 , . . . , C m be such a covering of C, where each C i has side length s. Let C i be any cube in the cover that has probability mass at least /m under the distribution µ. The probability that a sample of size S drawn from µ does not contain a sample in C i is at most (1 − /m) n . Let I denote the index set of all those cubes with probability mass at least /m under µ. Applying the union bound over the cubes indexed by I, the probability that there exists a cube C i with i ∈ I that does not contain any sample from S is at most m(1 − /m) n ≤ me −n /m . Setting n = m (ln m + log 1 ) results in this upper bound being δ. For the remainder of the proof, suppose that this high probability event occurs.
Define Y = i∈I C i . Each cube from our cover not used in the construction of Y has probability mass at most /m and, since there are at most m such cubes, their total mass is at most . It follows that P x∼µ (x ∈ Y) ≥ 1 − . Moreover, every point x in Y belongs to one of the cubes, and every cube C i with i ∈ I contains at least one sample point. Since the diameter of the cubes is r, it follows that the nearest sample to x is at most r away.
Setting r = D , we obtain the results for both k-median and k-means in the first half of Lemma ??.
For the remainder of this section, suppose that µ is a doubling measure of dimension d 0 with support X and that the diameter of X is D > 0. First, we shall prove general lemmas about doubling measures. They are quite standard, and are included here for the sake of completion. See, for example, [32,31].

Lemma 43.
For any x ∈ X and any radius of the form r = 2 −T D for some T ∈ N, we have Proof. Since X has diameter D, for any point x ∈ X we have that X ⊂ B(x, D), which implies that µ(B(x, D)) = 1. Applying the doubling condition T times gives µ(B(x, r)) = µ(B(x, 2 −T D)) ≥ 2 −T d0 = (r/D) d0 .
Lemma 44. For any radius of the form r = 2 −T D for some T ∈ N, there is a covering of X using balls of radius r of size no more than (2D/r) d0 .
Proof. Consider the following greedy procedure for covering X with balls of radius r: while there exists a point x ∈ X that is not covered by our current set of balls of radius r, add the ball B(x, r) to the cover. Let C denote the set of centers for the balls in our cover. When this procedure terminates, every point in X will be covered by some ball in the cover.
We now show that this procedure terminates after adding at most (2D/r) d0 balls to the cover. By construction, no ball in our cover contains the center of any other, implying that the centers are at least distance r from one another. Therefore, the collection of balls B(x, r/2) for x ∈ C are pairwise disjoint. Lemma 43 tells us that µ(B(x, r/2)) ≥ (r/2D) d0 , which gives that 1 ≥ µ x∈C B(x, r/2) = x∈C µ(B(x, r/2)) ≥ |C|(r/2D) d0 . Rearranging the above inequality gives |C| ≤ (2D/r) d0 .
The next lemma tells us that we need a sample of size O ( D r ) d0 (d 0 log D r + log 1 δ ) in order to ensure that there is a neighbor from the sample no more than r away from any point in the support with high probability. The second half of Lemma 19 is an easy corollary.
Proof. By Lemma 44 there is a covering of X with balls of radius r/2 of size (4D/r) d0 . For each ball B in the cover, the probability that no sample point lands in B is (1 − µ(B)) n ≤ (1 − (r/2D) d0 ) n ≤ exp(−n(r/2D) d0 ). Let E be the event that there exists at least one ball B in our cover that does not contain one of the n sample points. Applying the union bound over the balls in the cover, we have that P(E) ≤ (4D/r) d0 exp(−n(r/2D) d0 ). Setting n = (2D/r) d0 (d 0 log(4D/r) + log(1/δ)) = O ( D r ) d0 (d 0 log D r + log 1 δ ) , we have that P(E) < δ. When the bad event E does not occur, every ball in our covering contains at least one sample point. Since every point x ∈ X belongs to at least one ball in our covering and each ball has diameter r, we have sup x∈X d(x, NN S (x)) ≤ r.
Bounding β(S): In this section, we bound the bias term β under the condition that the optimal clustering satisfies the following probabilistic Lipschitz condition: Definition 5 (Probabilistic Lipschitzness). Let (X , d) be some metric space of diameter D and let φ : Lemma 20. Let µ be a measure on R q with support X of diameter D. Let f * be the optimal clustering of µ that satisfies capacities ( + , L − ) and suppose f * is φ-PL. If we see a sample S drawn iid from µ of size O 1 Proof. Suppose P x∼µ (f * (NN S (x)) = f * (x)) ≤ .
Given a clustering f of the entire space X , define the restriction f S : S → k p to be f S (x) = f (x) for x ∈ S. First, we show that the cluster sizes of f * S can be bounded. Recall that the weights of cluster i in a clustering f of X and the extension of a clustering g of the sample S are P x∼µ (i ∈ f (x)) and P x∼µ (i ∈ḡ(x)), respectively. By the triangle inequality, | P x∼µ (i ∈f * S (x)) − P x∼µ (i ∈ f * (x))| ≤ P x∼µ (f * S (x) = f * (x)) = P x∼µ (f * (NN S (x)) = f * (x)) and this is at most , by our assumption.
Consider β 1 (S) for k-median. Since f * ∈ F ( + 2 , L − 2 ), we have that f * S ∈ G n ( − , L + ) and so The first conditional expectation is zero, since the assignments for x and x are identical. The second conditional expectation is at most pD, since the cost for any given point can change by at most pD when we assign it to new centers. It follows that β 1 (S) ≤ pD . For k-means, the second expectation is at most pD 2 . It remains to show that show that P x∼µ (f * (NN S (x)) = f * (x)) ≤ for big enough n. Lemma 46 lists the conditions when this is true.
We require the following lemma for nearest neighbor classification, similar in spirit to that of Urner et al [44]. Note that since f is a set of p elements, this lemma holds for multi-label nearest neighbor classification.
Lemma 46. Let µ be a measure on R q with support X of diameter D. Let the labeling function, f be φ-PL. For any accuracy parameter and confidence parameter δ, if we see a sample S of size at least then nearest neighbor classification generalizes well. That is, with probability at least 1 − δ over the draw of S, the error on a randomly drawn test point, P x∼µ (f (x) = f (NN S (x))) ≤ .
Proof. Let λ = φ −1 ( ). We know that most of X can be covered using hypercubes in the general case, as in Lemma 42 or entirely covered using balls in the case when µ is a doubling measure, as in Lemma 44, both of diameter λD. In case we have cubes in the cover, we shall use a ball of the same diameter instead. This does not change the sample complexity, since a cube is completely contained in a ball of the same diameter.
Formally, let C be the covering obtained from Lemma 42 or Lemma 44, depending on whether or not the measure is a doubling measure. Define B(x) to be the set of all the balls from C that contain the point x. A point will only be labeled wrongly if it falls into a ball with no point from S, or a ball that contains points of other labels. Hence, Since each ball is of diameter λD, the second term is at most P x∼µ (∃y ∈ B(x, λD) : f (y) = f (x)). By the PL assumption, this is at most φ(λ) = , independent of the covering used.
For the first term, our analysis will depend on which covering we use: • From Lemma 42, we know that all but 1 − fraction of the space is covered by the covering C. When the sample is of size O( 1 ( √ q λ ) q (q log( √ q λ ) + log 1 δ )), each C ∈ C sees a sample point. For a sample this large, the first term is ≤ . Substituting with /2 completes this part of the proof.
• When µ is a doubling measure, we can do better. If every ball of the cover sees a sample point, the first term is necessarily zero. From the proof of Lemma 45, we know that if we draw a sample of size n = (2/λ) d0 (d 0 log(4/λ) + log(1/δ)) samples, then every ball of the cover sees a sample point with probability at least 1 − δ over the draw of S. This completes the proof.
14 Details for the Experiments Experimental System Setup: We now describe the distributed implementation used for the experiments. We start one worker process on each of the available processing cores. First, a single worker subsamples the data, clusters the subsample into k clusters, and then builds a random partition tree for fast nearest neighbor lookup. The subsample, clustering, and random partition tree describe a dispatching rule, which is then copied to every worker. Training the system has two steps: first, the training data is dispatched to the appropriate workers, and then each worker learns a model for the clusters they are responsible for. During the deployment phase, the workers load the training data in parallel and send each example to the appropriate workers (as dictated by the dispatch rule). To minimize network overhead examples are only sent over the network in batches of 10,000. During the training phase, each worker calls either Liblinear or an L-BFGS solver to learn a one-vs-all linear classifier for each of their clusters. For testing, the testing data is loaded in parallel by the workers and the appropriate workers are queried for predictions. Details of LSH-baseline: The LSH family used by our LSH baseline is the concatenation of t random projections followed by binning. Each random projection is constructed by sampling a direction u from the standard Gaussian distribution in R d . An example x is then mapped to the index u x/w , where w is a scale parameter. Two points x and y map to the same bin if they agree under all t hash functions. In our experiments, the parameter t was set to 10 and w is chosen so that hashing the training data results in approximately 2k non-empty bins. We tried several other values of t and w but performance did not change significantly. Details for Synthetic Data Distribution: The synthetic distribution used in Section 6 is an equal-weight mixture of 200 Gaussians in R 20 with means chosen uniformly at random from the unit cube [0, 1] 20 . Each Gaussian is associated with one of 30 class labels. To decide the class labels, we construct a hierarchical clustering of the Gaussian centers using complete linkage and assign labels using a simple recursive procedure: each internal node of the subtree is associated with a range of permissible labels. The permissible labels assigned to the left and right children of the parent node are a partition of the parent's assigned labels, and the number of labels they receive is proportional to the number of leaves in the subtree. If a subtree has only one permissible label, both children are given that label. Finally, each leave chooses a label uniformly at random from the set of permissible labels it was assigned (in many cases, there will only be one). This labeling strategy results in nearby Gaussians having similar labels. Inception Network: The specific architecture for the neural network we used when constructing the feature representations for the CIFAR-10 dataset can be found here: https://github.com/dmlc/mxnet/blob/master/ example\/notebooks/cifar10-recipe.ipynb.
Hardware: The experiments for MNIST-8M, CIFAR10, and the CTR datasets were performed on a cluster of 15 machines, each with 8 Intel(R) Xeon(R) cores of clock rate 2.40 GHz and 32GB shared memory per machine. The experiments for the large synthetic experiment were performed on AWS. We used clusters of 8, 16, 32, and 64 m3.large EC2 instances, each with an Intel (R) Xeon E5-2670 v2 processors and 7.5 GB memory per machine. Clustering algorithm selection: In Section 3 we showed that k-means++ will find high-quality balanced clusterings of the data whenever a natural stability condition is satisfied. Since the k-means++ algorithm is simple and scalable, it is a good candidate for implementation in real systems. In this section we present an empirical study of the quality of the clusterings produced by k-means++ for the datasets used in our experiments. For each of the datasets used in our learning experiments, we find that the clustering obtained by k-means++ is very competitive with the LP rounding techniques. We also include a synthetic dataset designed specifically so that k-means++ with balancing heuristics will not perform as well as the LP-rounding algorithms. We compare the clustering algorithms on two metrics: (1) the k-means objective value of the resulting clustering and (2) the mean per-cluster class distribution entropy. Since the LP rounding algorithms may violate the replication by a factor of 2, we use an averaged version of the k-means objective which provides a fair comparison when |f (x i )| is not exactly p for all points. The second metric is the mean per-cluster class distribution entropy which measures how well the clusters are capturing information about the class labels. Each cluster has an empirical distribution over the class labels and this distribution will have low entropy when the cluster contains mostly examples from a small number of classes. Therefore, when the average class-distribution entropy per cluster is small, we expect the learning problems for each cluster to be simpler than the global learning problem, which should lead to improved accuracy. Formally, given a dataset (   is small enough to only intersect with one or two grid cells, then the learning problem is easy. If the subset intersects with many grid cells, there is not usually a low-error one-vs-all linear classifier. Intuitively, balanced partition trees fail on this dataset because in order for them to produce a good partitioning, they need to repeatedly split on one of the first two dimensions. Any time the balanced partition tree splits on another dimension, the two resulting learning problems are identical but with half the data. On the other hand, clustering-based approaches will naturally divide the data into small groups, which leads to easier learning problems. The accuracies for the balanced partition trees and k-means++ are shown in Figure 8. Our method is run with parameters p = 1, = 1/(2k), and L = 2/k.

Comparison of Clustering Algorithms
In this section, we empirically and theoretically compare the LP rounding and k-means++ algorithms on a data distribution designed specifically to show that in some cases, the LP rounding algorithm gives higher performance.
The synthetic distribution is a mixture of two Gaussians in R 2 , one centered at (0, 0) and the other centered at (10, 0). We set the balancing constraints to be = 1/10 and L = 1 so that no cluster can contain fewer than 10% of the data. The mixing coefficient for the Gaussian at (10, 0) is set to 0.8 = 0.08, so in a sample this Gaussian will not contain enough data points to form a cluster on its own. In an optimal 2-clustering of this data with the given constraints, cluster centered at (10, 0) will steal some additional points from the Gaussian centered at (0, 0). Running the k-means++ algorithm, however, will produce a clustering that does not satisfy the capacity constraints, and the merging heuristic described in Section 6 will simply merge the points into one cluster. The following labeling function is designed so that there is no globally accurate one-vs-all linear classifier, but for which there is an accurate classifier for each cluster in the optimal clustering.
otherwise.  Figure 9: A dataset which has two well defined clusters that are not balanced in size.
The LP rounding algorithm requires the replication parameter p to be at least two, so we run both algorithms with p = 2 and k = 4, in which case the above intuitions still hold but now each of the clusters is assigned two centers instead of one. Figure 9 shows a sample drawn from this distribution labeled according to the above target function.
We evaluate the LP rounding algorithm, k-means++, and an algorithm that optimally solves the clustering problem by solving the corresponding integer program (this is only feasible for very small input sizes). Other aspects of the experiment are identical to the large scale learning experiments described in Section 6. In all cases, we set the parameters to be k = 4, p = 2. The training size is 10,000, the testing size 1,000, and the clustering is performed on a sample of size 200. Running k-means++ results in accuracy 0.768 (averaged over 500 runs), using the LP rounding algorithm results in accuracy 0.988, and exactly solving the capacitated clustering IP results in accuracy 0.988. Since the LP rounding and IP based algorithms are deterministic, we did not run the experiment multiple times. The accuracy of k-means++ does not significantly increase even if we cluster the entire sample of training 10,000 points rather than a small sample of size 200. This experiment shows that, while the k-means++ heuristic works effectively for many real-world datasets, it is possible to construct datasets where its performance is lower than the LP rounding algorithm.
With a modification to this distribution, but with the same intuition, we can prove there is a point set in which the LP rounding algorithm outperforms k-means++.
Lemma 47. There exists a distribution such that with constant probability, classification using the k-median LP rounding algorithm as a dispatcher outperforms the k-means++ algorithm with a balancing heuristic.
Proof. The point set is as follows. All points are on a line, and there are three groups of points, group A, B, and C. Two points in the same group are at distance zero. Group A is distance 1 from group B, and group B is distance 10. Group A is distance 101 from group C. Group A contains 112 points, group B contains 111 points, and group C contains 1 point. Set k = 2, n = 112, and L = 1. For now, p = 1. All points in A, B, and C are labeled −1, 0, and 1, respectively.
Then the optimal k-median 2-means cluster is to put centers at A and B. Then the points at A and B pay zero, and the points at C pay 10 · 10 = 100 to connect to the center at B. So the total k-median score is 100.
The LP rounding algorithm is guaranteed to output an 11-approximation, so it must output a 2-clustering with score ≤ 110 (it only works when p ≥ 2, but we will modify the proof for p ≥ 1 at the end). Note, the centers must stay at A and B, because if a center is not at (wlog) A, then the center must be distance at least 1 away from A, which means the score of this clustering is ≥ 111. Now we know the LP algorithm is guaranteed to output centers at A and B. Then the clusters must be A and B ∪ C, because this assignment minimizes the flow in the graph the LP algorithm uses to assign points to clusters. Therefore, each cluster has ≤ 2 labels, which can easily be classified using a linear separator. Now we consider the k-means++ algorithm. First we calculate the probability that a center is placed in group C. Note, there is zero probability that both centers are in the same group. So this probability is the complement of the probability the centers fall in A and B. By a simple calculation, the probability is 1 − 112 224 · 1·111 1·111+11·1 − 111 224 · 1·112 1·112+10·1 = .09016. However, if a center is placed in group C, then the clusters will be A ∪ B and C, which means the k-means++ balancing heuristic will combine both clusters into a single cluster. Then, there are 3 groups of points with different labels on a line, so a linear separator must classify at least one point incorrectly.
The proof of Lemma 47 can be modified for k-means. The probability that k-means outputs a bad clustering is inversely proportional to the approximation factor of the LP algorithm, but since the LP algorithm has constant-factor approximation ratios, the probability is constant. The proof can also be modified for p = 2 similar to the explanation in the experimental evaluation. Set p = 2 and k = 4, and the problem stays the same, since the optimal clustering puts two centers at A and two centers at B.