The computational complexity of some explainable clustering problems

We study the computational complexity of some explainable clustering problems in the framework proposed by [Dasgupta et al., ICML 2020], where explainability is achieved via axis-aligned decision trees. We consider the $k$-means, $k$-medians, $k$-centers and the spacing cost functions. We prove that the first three are hard to optimize while the latter can be optimized in polynomial time.


Introduction
Machine learning models and algorithms have been used in a number of systems that take decisions that affect our lives. Thus, explainable methods are desirable so that people are able to have a better understanding of their behavior, which allows for comfortable use of these systems or, eventually, the questioning of their applicability [1].
Recently, there has been some effort to devise explainable methods for unsupervised learning tasks, in particular, for clustering [2,3]. We investigate the framework discussed by [2], where an explainable clustering is given by a partition, induced by the leaves of an axis-aligned decision tree, that optimizes some predefined objective function. Figure 1 shows a decision tree that defines a clustering for the Iris dataset. The clustering has three groups, each of them corresponding to a leaf. The explanation of the group associated with the rightmost leaf is Sepal Length >0.4 AND Petal Width < 0.5.
Following [2], a series of papers [4,5,6,7,8] provided algorithms, with provable guarantees, to build decision trees that induce explainable clustering. Several cost functions to guide the clustering construction were investigated as the k-means, k-centers, k-medians and maximum-spacing. Despite this active research, the only work on the field that tackles the computational complexity of building explainable clustering is [9], where it was proved that optimizing the k-means and the k-medians cost functions is NP-Complete. Here, we improve

Problem definition
Let X be a finite set of points in R d . We say that a decision tree is standard if each internal node v is associated with a test (cut), specified by a coordinate i v ∈ [d] and a real value θ v , that partitions the points in X that reach v into two sets: those having the coordinate i v smaller than or equal to θ v and those having it larger than θ v . The leaves of a standard decision tree induce a partition of R d into axis-aligned boxes and, naturally, a partition of X into clusters.
Let k ≥ 2 be an integer. The clustering problems considered here consist of finding a partition of X into k groups, among those that can be induced by a standard decision tree with k leaves, that optimizes a given objective function. For the k-means, k-medians and k-centers cost functions, in addition to the partition, a representative µ(C) ∈ R d for each group C must also be output.
For the k-means problem the objective (cost function) to be minimized is the Sum of the Squared Euclidean Distances (SSED) between each point x ∈ X and the representative of the cluster where x lies. Mathematically, the cost (SSED) of a partition C = (C 1 , . . . , C k ) for X is given by For the k-medians problem the cost of a partition C = (C 1 , . . . , C k ) is given by The k-centers problem is also a minimization problem; its cost function for a partition C = (C 1 , . . . , C k ) is given by Let dist : X × X → R + be a distance function. The meximum-spacing problem consists of finding a partition with at least k groups that has maximum spacing, where the spacing sp(C) of a partition C is defined as sp(C) = min{dist(x, y) : x and y lie in distinct groups of C} In contrast to the other criteria, the spacing is an inter-clustering criterion.
We note that an optimal solution of the unrestricted version of any of these problems, in which the decision tree constraint is not enforced, might be a partition that is hard to explain in terms of the input features. Thus, the motivation for using standard decision trees.
For the sake of simplicity, throughout of this text, by explainable clustering we mean a clustering that is obtained via decision trees.

Our contributions
In Section 2, we first show that the problem of building a partition via decision trees that minimizes the k-means cost function does not admit an (1 + )approximation in polynomial time, for some > 0, unless P = N P . Then, we show that analogous results hold for both the k-median and k-centers cost functions. Our results for both the k-means and k-medians are stronger than the NP-Hardness result established recently by [9] and they formally help to justify the quest for approximation algorithms and/or heuristics for these cost functions.
In Section 3 we propose a polynomial time algorithm that produces an explainable clustering of maximum spacing. As far as we know, this is the first efficient method that produces optimal explainable clustering with respect to some well studied metric.

Related work
Our research is inspired by the recent work of [2], where the problem of building explainable clusterings, via standard decision trees, for both the k-means and the k-medians cost functions are studied. This paper proposes algorithms with provable approximation bounds for building explainable clusterings. In addition, it investigates the price of explainability for these cost functions, which is the unavoidable gap between the cost of the optimal explainable and the optimal unconstrained clustering. Among their results, they showed that the price of explainability for the k-means and k-median are respectively O(k 2 ) and O(k).
Their results were refined/improved by a series of recent papers [4,5,7,8,6]. Currently, the best upper bound for the k-medians is O(log k log log k) [5,7] while for the k-means is O(k log k) [7]. The study of bounds that depend on the dimension d was initiated in [4], where the authors present an O(d log k) upper bound for the k-medians and an O(dk log k) upper bound for the kmeans. These bounds were improved to O(d log 2 d) for the k-medians [7] and O(k 1−2/d poly(d, log k)) [6] for the k-means.
The price of explainability was also investigated for other cost functions. In [4], Laber and Murtinho considered the k-centers and maximum-spacing cost functions. In [5], Makarychev and Shan considered the k-medoids problem (k-median with 2 objective). Finally, in [8], Gamlath et. al addressed p p objectives.
The aforementioned papers, except [4] which also presents experiments, are mainly theoretical. However, there are also a number of papers that propose algorithms (without theoretical guarantees) for building explainable clustering, among them we cite [10,11,3].
The computational complexity of building explainable clustering via decision trees for both the k-means and the k-medians problems is studied in [9]. It is shown that both problems admit polynomial time algorithms when either k or d is constant and they are NP-Complete for arbitrary k and d. In addition, they show that an optimal explainable clustering cannot be found in f (k)·|X | o(k) time for any computable function f (), unless Exponential Time Hypothesis (ETH) fails.
When we turn to standard (non-explainable) clustering, the problems of optimizing the k-means, k-medians and k-centers cost functions are APX-Hard [12,13,14] and all of them admit polynomial time algorithms with constant approximation [15,16,17]. With regards to the spacing cost function, the single-link algorithm, a very popular algorithm to build hierarchical clustering, produces a partition with maximum spacing [18,Chapter 4].
2 Hardness of k-means, k-medians and k-centers cost function

Background
We start by recalling some basic definitions and facts that are useful for studying the hardness of optimization problems (see, e.g., [19, chapter 29]). Given a minimization problem A and a parameter > 0 we define the -Gap-A problem as the problem of deciding for an instance I of A and a parameter k whether: (i) I admits a solution of value at most k; or (ii) every solution of I have value at least (1 + )k. In such a gap decision problem it is tacitly assumed that the instances are either of type (i) or of type (ii). Fact 1. If for a minimization problem A there exists > 0 such that the -Gap-A problem is N P -hard, then no polynomial time (1+ )-approximation algorithm exists for A unless P = N P.
We will use the following definition of a gap-preserving reduction. Definition 1. Let A, B be minimization problems. A gap-preserving reduction from A to B is a polynomial time algorithm that, given an instance x of A and a value k, produces an instance y of B and a value κ such that there exist constants , η > 0 for which If there exists such that the -Gap-A problem is N P -hard and there exists a gap-preserving reduction from A to B then there exists η such that the η-Gap-B problem is N P -hard We will now specialize the above definitions for restricted variants of the problem of finding a minimum vertex cover in a graph and for our clustering problems.
Definition 2. For every > 0, the -Gap-MinVC-B-TF (gap) decision problem is defined as follows: given a triangle-free graph G = (V, E), with bounded degree, and an integer k, decide whether G has a vertex cover of size k or all vertex covers of G have size at least k(1 + ).
The -Gap-MinVC-3B-TF (gap) decision problem has a similar definition, the only differences is that, in addition of being triangle-free, the graphs are required to be 3-bounded, that is, all of its vertexes have degree at most 3.
The NP-Hardness of -Gap-MinVC-B-TF and -Gap-MinVC-3B-TF were established in [13] and [20], respectively. Definition 3. For every η > 0, the η-Gap-Explainable-kmeans (gap) decision problem is defined as follows: given a set of points X , an integer k, and a value κ, decide whether there exists an explainable k-clustering C = (C 1 , . . . C k ) of the points in X such that the k-means cost of C is at most κ or for each explainable k-clustering C of X it holds that the k-means cost of C is at least The η-Gap-Explainable-kmedians and η-Gap-Explainable-kcenters decision problems are analogously defined.
To prove the hardness for the k-means we use a gap-preserving reduction from the -Gap-MinVC-B-TF decision problem. To handle both the k-centers and k-medians, we use the -Gap-MinVC-3B-TF decision problem.
Our reductions have some common ingredients that we explain here. For all of them, given a graph G = (V, E), where V = {1, . . . , n}, we build an instance of the clustering problem under consideration by mapping every edge otherwise. This is exactly the mapping proposed in [13] to establish that the (standard) k-means problem is APX-Hard. We use X G := {v e |e ∈ E} to denote the input of the resulting clustering instance.
Let S = {i 1 , i 2 , . . . , i k } be a cover of size k for G, where each i j is an integer in [n] and i j < i j+1 . We define C S = (E 1 , . . . , E k ) as the k-clustering induced by S on the points in X G , where the group E j includes all points v that simultaneously satisfy: its component i j is 1 and its component i j , for j < j, is 0. Proposition 1. The clustering C S is explainable.
Proof. C S is the clustering induced by a decision tree with k − 1 internal nodes, with exactly one internal node per level. The internal node of level j is associated with cut (i j , 1/2).

Hardness of k-means cost function
We prove that the problem of finding an explainable clustering with minimum k-means cost function is hard to approximate. The reduction employed here is the one used by [13] to show that it is hard to find an (1 + )-approximation for the k-means cost function. The extra ingredient in our proof is the construction of an explainable clustering C S from a vertex cover S that was described in the previous section. Proof. Let G be a triangle-free graph that satisfies one of the following cases: (i) G has a vertex cover of size k or (ii) all vertex covers of G have size > k(1 + ).
First, we consider the case where G has a vertex cover S = {i 1 , i 2 , . . . , i k } of size k. We show that, in this case, the cost of C S = (E 1 , . . . , E k ) is at most |E| − k. Let us consider the mean of the points in E j as the representative of E j , that is, a point that has 1 at coordinate i j and 1/|E j | in the remaining |E j | coordinates with non-zero values. The squared distance of each point in E j to its representative is given by Thus, E j contributes to the total cost with |E j |−1. The cost of the clustering C S is, then, given by k j=1 |E j | − 1 = |E| − k Now, it remains to argue that if the minimum vertex cover for G has size at least (1 + )k then every explainable clustering for the corresponding instance has cost at least |E| − (1 − Ω( ))k. This follows from [13], as in this case every clustering (and, in particular, every explainable one) has cost at least |E| − (1 − Ω( ))k.

Hardness of k-medians cost function
We prove that the problem of finding an explainable clustering with minimum k-medians cost function is hard to approximate. We show a gap preserving reduction from the -Gap-MinVC-3B-TF problem to the η-Gap-Explainablekmedians problem.
The following well-known fact will be useful. The following lemma will be also useful.
Lemma 1. Let G be a 3-bounded triangle free graph and let let C ⊆ X G be a group of points corresponding to p edges of G. We have that: (i) if C is a star then its k-medians cost is p and (ii) if C is not a star then its k-medians cost is at least (4/3)p.
Proof. From the previous fact, the representative of C that yields to the minimum k-medians cost is a point in {0, 1} n , where the coordinate i has value 1 if and only if the number of edges that touch vertex i is larger than p/2. Thus, the cost of a cluster C is given by where d C (i) is the number of edges that touch vertex i in C.
If C is a star centred on vertex j then min{p − d C (j), d C (j)} = 0 and min{p − d C (i), d C (i)} = 1 for the other vertexes i in the star. Thus, If C is not a star then we have some cases: Note that the above case covers the case p ≥ 6 since the maximum degree in G is at most 3.
Case 2) p = 5 and d C (j) = 3 for exactly one j. We have Case 3) p = 5 and d C (j) = d C (j ) = 3 for exactly two values j and j . We have Note that we cannot have 3 vertexes with degree 3 and p = 5.
Case 4) p = 4 and d C (j) = 3 for some j. We must have exactly one j with d C (j) = 3, otherwise we would have more than 4 edges. Thus, Case 5) p = 3 and d C (j) = 2 for some j. We have two possible nonisomorphic graphs. One of them consists of a path with 2 edges and an additional edge while the other is a path with 3 edges. For both cases we have The problem of building an explainable clustering, via decision trees, that minimizes the k−medians cost function does not admit an (1 + )approximation, for some > 0, in polynomial time unless P = N P .
Proof. Let G be a triangle-free graph with maximum degree not larger than 3 that satisfies one of the following cases: (i) G has a vertex cover of size k or (ii) all vertex covers of G have size at least k(1 + ).
First, consider the case where G has a vertex cover S of size k. Since the clustering C S consists of stars, it follows from the previous lemma that its cost is |E|. Now, assume that all vertex covers for G have size at least k(1 + ). Let C be a clustering with k groups for the corresponding k-medians instance.
Let t be the number of groups in C that are stars and let p be the total number of edges in the remaining clusters. Since there is no vertex cover for G of size smaller than k(1 + ) we must have t + p ≥ k(1 + ), otherwise we could obtain a cover for G with size smaller than k(1 + ) by using one vertex per star and one additional vertex for each of the p edges. Since t ≤ k it follows that p ≥ k . Moreover, we must have k ≥ |E|/3 because the degree of every vertex in G is at most 3. Thus, from the previous lemma, the cost of clustering C is at least We have concluded a gap preserving reduction from -Gap-MinVC-3B-TF to η-Gap-Explainable-kmedians.

Hardness of k-centers cost function
In this section we discuss the computational complexity of minimizing the kcenters cost function. We show a gap preserving reduction from the -Gap-MinVC-3B-TF problem to the η-Gap-Explainable-kcenters problem.
Theorem 3. The problem of building an explainable clustering, via decision trees, that minimizes the k−centers cost function does not admit an (1 + )approximation, for some > 0, in polynomial time unless P = N P .
Proof. Let G = (V, E) be a triangle-free graph with maximum degree not larger than 3 that satisfies one of the following cases: (i) G has a vertex cover of size k or (ii) all vertex covers of G have size at least k(1 + ).
First, consider the case where G has a vertex cover S of size k. In this case, the clustering C S = (E 1 , . . . , E k ) consists of stars with at most 3 edges. For the representative of E j , as in the proof of Theorem 1, we use the mean of the points that lie in E j .
Thus, the distance of each point in E i to its representative is the square root of the rightmost term of (1), which is at most 1/3 since G has maximum degree 3. Now, we assume that G does not have a vertex cover with k vertex. Let C be a clustering with k groups for the edges of E. One of the groups, say A, does not have a vertex that touches all the edges in A. Pick the vertex, say v, that touches the largest number of edges in A. Consider an edge e = yz in A that does not touch v. We show that there is another edge in A, say e , that does not have intersection with e. In fact, pick an edge f = vw. If f does not intersect e (w is not an endpoint of e) we set e = f . Otherwise, we assume w.l.o.g. that f intersects e at point y, that is, w = y. We know that vz is not an edge for otherwise we would have a triangle vwz in G. Since v is the vertex that touches the largest number of edges in A then v must touch an edge f = vz , with z = y and z = z. We set e = f . We can argue that the distance of the representative µ(A) of A to either e or e is at least 1. For that, we consider the values of µ(A) at the components of the vertexes that define the edges e and e. Let µ 1 , µ 2 , µ 3 and µ 4 be these values. We have that ) ≥ 2 Thus, either e or e is at distance at least 1 from the representative of A 3 A polynomial time algorithm for the maximumspacing cost function We describe MaxSpacing, a simple greedy algorithm that finds an explainable partition of maximum spacing in polynomial time.
To simplify its description we introduce some notation. For a set of leaves L in a decision tree, we use sp(L) to refer to the spacing of the partition of the points in X induced by the leaves in L. Given a set of leaves L, a leaf ∈ L and an axis-aligned cut γ = (i, θ), we use L γ, to denote the set of leaves obtained when γ is applied to split the points that reach . More precisely, L γ, is obtained from L by removing and adding the two leaves that are created by using γ to split the points that reach .
A pseudo-code for MaxSpacing is presented in Algorithm 1. The algorithm adopts a natural greedy strategy that at each step chooses the cut that yields to the partition of maximum spacing. We note that it runs in polynomial time because in Step 1 we just need to test at most (|X | − 1)d axis-aligned cuts: for each ∈ L and each dimension i ∈ [d] we sort the | | points that reach according to their coordinate i and consider the cuts (i, θ j ), for j = 1, . . . , | |, where θ j is the midpoint between the values of the i-th coordinate of the jth and (j + 1)th points in the sorted list.
Algorithm 1 MaxSpacing(X : set of points; k: integer) Initialize a decision tree with only one leaf and associate it with X L ← { } Repeat k − 1 times: 1. Find a cut γ and a leaf ∈ L that simultaneously satisfy: (i) γ splits the points that reach into 2 non-empty groups (ii) sp(L γ, ) ≥ sp(L γ , ) for every ∈ L and every axis-aligned cut γ that splits the points that reach into two non-empty sets.
2. Split leaf using cut γ In what follows, we show that MaxSpacing produces an explainable partition with maximum possible (optimal) spacing. The following simple fact will be useful. Proof. Let D * be a decision tree that induces a partition with i + 2 groups that has spacing d * i+1 . Let D be a decision tree obtained by removing two leaves that are siblings in D * and turning their parent into a leaf. Let x and y be two closest points among those that reach different leaves in D. Since these points also reach distinct leaves in D * we have that the spacing of the leaves in D is not smaller than that of the leaves in D * . Thus, d * i ≥ sp(Leaves of D) ≥ d * i+1 . Theorem 4. For every 1 ≤ i ≤ k − 1, the partition induced by the leaves of MaxSpacing algorithm by the end of iteration i has the maximum spacing, among the explainable partitions with i + 1 groups for X .
Proof. Let C * i be an optimal explainable partition with i + 1 groups and let d * i be its spacing. Moreover, let L i , with i < k − 1, be the set of leaves by the end of iteration i of MaxSpacing algorithm. By the greedy choice sp(L 1 ) = d * 1 . We assume by induction that the spacing of L i is d * i and show that the spacing of L i+1 is d * i+1 . For a node ν in a decision tree, let P (ν) be the set of points that reach ν. Let ν * be a node in the decision tree D * for C * i+1 that satisfies the following: (i) for each ∈ L i either P ( ) ⊆ P (ν * ) or P ( ) ∩ P (ν * ) = ∅ and (ii) some child of ν * does not satisfy (i). We will use the cut associated with ν * in D * to argue that we can properly split L i .
To prove the existence of a node ν * with such properties, it suffices to show that the root r * of D * satisfies (i) and some leaf * from D * does not satisfy (i) since, in this case, we can set ν * as the last node in the path from r * to * that satisfies (i). Clearly, r * satisfies (i). It remains to argue that some leaf * ∈ D * does not satisfy (i). Since the number of leaves in L i is smaller than the number of leaves in D * , by the pigeonhole principle, there are two leaves, say * 1 and * 2 , in D * that contain points from the same leaf in L i . Thus, neither P ( ) ∩ P ( * 1 ) = ∅ nor P ( ) ⊆ P ( * 1 ). We set * to * 1 and ν * as the last node in the path from r * to * 1 that satisfies (i). Let ν * ch be a child of ν * in D * that does not satisfy (i). Moreover, let γ be the cut associated with ν * and let be a leaf in L i such that P ( ) ⊆ P (ν * ), P ( ) ∩ P (ν * ch ) = ∅ and P ( ) ⊂ P (ν * ch ). We show that the spacing of the set of leaves L i obtained from L i by applying cut γ to is at least d * i+1 . Let 1 and 2 be the two new leaves that are created by applying γ to and let x and y be the two closest points (according to dist) among those that reach different leaves in L i . If x reaches 1 (resp. 2 ) and y reaches 2 (resp. 1 ) then because, due to the application of cut γ on ν * , x and y lies in different groups in C * i+1 . If some of them, say x, does not reach then x and y reach different leaves in L i and, thus, , where the last inequality follows from Fact 4.
We have shown that there exists a leaf in L i and a cut γ such that the application of γ to yields to a partition of spacing d * i+1 . Thus, due to the greedy choice, MaxSpacing obtains a partition of spacing d * i+1 by the end of iteration i + 1.

Conclusions
We have showed that the problems of finding explainable clustering (via decision trees) that optimize the classical k-means, k-medians and k-centers cost functions do not admit polynomial time (1 + )-approximations. These results help to formally justify the quest for heuristics and/or approximation algorithms.
The algorithms recently proposed in the literature for building explainable clustering compare their costs with the costs of optimal unrestricted clustering [2,4,5,6,7,8]. A major open question in this line of research is whether better bounds can be obtained when the comparison is made against the optimal explainable clustering.
For the spacing cost function we provided a simple polynomial time algorithm that computes the explainable partition with maximum spacing. An interesting note is that we have not used the fact that the cuts are axis-aligned in the proof of Theorem 4 and, thus, our result holds for any family of cuts.