arXiv is now an independent nonprofit! Learn more
License: arXiv.org perpetual non-exclusive license
arXiv:1810.00029v1 [cs.DS] 28 Sep 2018

Minimization of Gini impurity via connections with the kk-means problem

Eduardo Laber Affiliation: PUC-Rio, Brazil Email: laber@inf.puc-rio.br    Lucas Murtinho Affiliation: PUC-Rio, Brazil Email: lucas.murtinho@gmail.com
Abstract

The Gini impurity is one of the measures used to select attribute in Decision Trees/Random Forest construction. In this note we discuss connections between the problem of computing the partition with minimum Weighted Gini impurity and the kk-means clustering problem. Based on these connections we show that the computation of the partition with minimum Weighted Gini is a NP-Complete problem and we also discuss how to obtain new algorithms with provable approximation for the Gini Minimization problem.

1 Introduction

Decision Trees and Random Forests are among the most popular methods for classification tasks. It is widely known that decision trees, specially small ones, are easy to interpret while random forest usually yield to more stable/accurate classifications.

A key decision during the construction of these structures is the selection of the attribute that is used for branching at each node. The standard approach for this selection is to evaluate the ability of each attribute to generate ’pure’ partitions, that is, partitions in which each branch is very homogeneous with respect to the class distribution of its examples. To measure how impure each branch is, impurity measures are often employed. An impurity measure maps a vector 𝐮=(u1,,uk)\mathbf{u}=(u_{1},\ldots,u_{k}), counting how many examples of each class we have in a node (branch), into a non-negative scalar 11 1 In the original definition an impurity measure maps a vector of probabilities into a non-negative scalar.. Arguably, two of the most classical impurity measures are the Gini impurity

iGini(𝐮)=i=1kui𝐮1(1ui𝐮1),i_{Gini}(\mathbf{u})=\sum_{i=1}^{k}\frac{u_{i}}{\|\mathbf{u}\|_{1}}\left(1-\frac{u_{i}}{\|\mathbf{u}\|_{1}}\right),

which is used in the CART package [3], and the Entropy impurity

iEntr(𝐮)=i=1kui𝐮1log(ui𝐮1),i_{Entr}(\mathbf{u})=-\sum_{i=1}^{k}\frac{u_{i}}{\|\mathbf{u}\|_{1}}\log\left(\frac{u_{i}}{\|\mathbf{u}\|_{1}}\right),

that along with its variants is used in the C4.5 decision tree inducer [8].

Given an attribute, the goal is then to find a split for the attribute values that induces a partition of the set of examples with minimum weighted impurity, where the weights are given by the number of examples that lie into each of the branches.

Here, we discuss connections between the problem of computing the partition with minimum weighted Gini and the kk-means clustering problem.

2 Connections between Gini minimization and kk-means clustering

For a vector 𝐯\mathbf{v} where all components are non-negative the weighted Gini impurity Gini(𝐯)Gini(\mathbf{v}) is defined as Gini(𝐯)=𝐯1iGini(𝐯)Gini(\mathbf{v})=\|\mathbf{v}\|_{1}\cdot i_{Gini}(\mathbf{v}). Let AA be a nominal attribute that may take nn possible values a1,,ana_{1},\ldots,a_{n}. The kk-ary Partition with Minimum Weighted Gini Problem (kk-PMWGP) can be described abstractly as follows. We are given a collection of nn vectors VdV\subset\mathbb{R}^{d}, where the iith component of the jjth vector counts the number of examples in class ii for which the attribute AA has value aja_{j}. The goal is to find a partition 𝒫{\cal P} of VV into kk disjoint groups of vectors V1,,VkV_{1},\ldots,V_{k} so as to minimize the sum of the weighted Gini impurities

Gini(𝒫)=i=1kGini(𝐯Vi𝐯).Gini({\cal P})=\sum_{i=1}^{k}Gini\bigg(\sum_{\mathbf{v}\in V_{i}}\mathbf{v}\bigg). (1)

Recently, we obtained simple constant approximation algorithms for this problem: an O(nlogn+nd)O(n\log n+nd) time 22-approximation for the case where k=2k=2 [7] and a linear time 33-approximation for arbitrary kk [5]. In fact these papers also handle a more general class of impurity measures that includes the Entropy impurity. The complexity of (kk-PMWGP) remained open.

A problem that is equivalent to the above problem from the perspective of optimality but it is different from the perspective of approximation is the problem of finding the partition 𝒫{\cal P} of VV into kk groups that minimizes

Gini(𝒫)𝐯VGini(𝐯).Gini({\cal P})-\sum_{\mathbf{v}\in V}Gini(\mathbf{v}). (2)

Using concavity properties of Gini one can prove that the above expression is always non-negative. An α\alpha-approximation with respect to goal (2) implies an α\alpha-approximation with respect to goal (1) but the converse is not necessarily true, so that approximations with respect to goal (2) are stronger.

In the geometric kk-means problem we are given a set of vectors VV in d\mathbb{R}^{d} and the goal is to find a partition 𝒫{\cal P} of VV into kk groups V1,,VkV_{1},\ldots,V_{k} and set of kk centers 𝐜1,,𝐜k\mathbf{c}_{1},\ldots,\mathbf{c}_{k} in d\mathbb{R}^{d} such that

CostKM(𝒫)=i=1k𝐯Vi𝐯𝐜i22Cost_{KM}({\cal P})=\sum_{i=1}^{k}\sum_{\mathbf{v}\in V_{i}}\|\mathbf{v}-\mathbf{c}_{i}\|_{2}^{2}

is minimized.

It is well known that if UU is a set of vectors then the vector 𝐜\mathbf{c} for which 𝐯U(𝐯𝐜)22\sum_{\mathbf{v}\in U}\|(\mathbf{v}-\mathbf{c})\|_{2}^{2} is minimum is the centroid of UU, that is, 𝐜=(𝐯U𝐯)/|U|\mathbf{c}=(\sum_{\mathbf{v}\in U}\mathbf{v})/|U|.

We argue that the following connections between kk-PMWGP and kk-means hold:

  • C1

    Let VV be an instance of kk-means where all vectors have the same 1\ell_{1} norm. If 𝒫{\cal P} is an optimal partition for instance VV then 𝒫{\cal P} is also an optimal partition for instance VV of kk-PMWGP

  • C2

    there exists a pseudo-polynomial time reduction from kk-PMWGP to the geometric kk-means problem

The key observation for establishing C1 and C2 is the following lemma.

Lemma 1.

Let XX be a set of vectors, all of them with 1\ell_{1} norm equal to LL. Then,

Gini(𝐯X𝐯)𝐯XGini(𝐯)=L×(𝐯X𝐯𝐜22),Gini\bigg(\sum_{\mathbf{v}\in X}\mathbf{v}\bigg)-\sum_{\mathbf{v}\in X}Gini(\mathbf{v})=L\times\left(\sum_{\mathbf{v}\in X}\|\mathbf{v}-\mathbf{c}\|_{2}^{2}\right),

where 𝐜\mathbf{c} is the centroid of the set of vectors in XX.

Proof.

Let 𝐮=𝐯X𝐯\mathbf{u}=\sum_{\mathbf{v}\in X}\mathbf{v}. We have that

Gini(𝐮)𝐯XGini(𝐯)=𝐮1(i=1d(1ui𝐮1)(ui𝐮1))𝐯Xi=1d𝐯1(1vi𝐯1)(vi𝐯1)Gini(\mathbf{u})-\sum_{\mathbf{v}\in X}Gini(\mathbf{v})=\|\mathbf{u}\|_{1}\left(\sum_{i=1}^{d}\left(1-\frac{u_{i}}{\|\mathbf{u}\|_{1}}\right)\left(\frac{u_{i}}{\|\mathbf{u}\|_{1}}\right)\right)-\sum_{\mathbf{v}\in X}\sum_{i=1}^{d}\|\mathbf{v}\|_{1}\left(1-\frac{v_{i}}{\|\mathbf{v}\|_{1}}\right)\left(\frac{v_{i}}{\|\mathbf{v}\|_{1}}\right)

On the other hand,

𝐯X𝐯𝐜22=i=1d𝐯X(vici)2\sum_{\mathbf{v}\in X}\|\mathbf{v}-\mathbf{c}\|_{2}^{2}=\sum_{i=1}^{d}\sum_{\mathbf{v}\in X}(v_{i}-c_{i})^{2}

Thus, it suffices to show that for any ii

𝐮1(1ui𝐮1)(ui𝐮1)𝐯X𝐯1(1vi𝐯1)(vi𝐯1)=L(𝐯X(vici)2)\|\mathbf{u}\|_{1}\left(1-\frac{u_{i}}{\|\mathbf{u}\|_{1}}\right)\left(\frac{u_{i}}{\|\mathbf{u}\|_{1}}\right)-\sum_{\mathbf{v}\in X}\|\mathbf{v}\|_{1}\left(1-\frac{v_{i}}{\|\mathbf{v}\|_{1}}\right)\left(\frac{v_{i}}{\|\mathbf{v}\|_{1}}\right)=L\left(\sum_{\mathbf{v}\in X}(v_{i}-c_{i})^{2}\right)

The left side is equal to

ui(ui)2𝐮1(𝐯Xvi|X|𝐯X(vi)2𝐮1)=|X|𝐯X(vi)2𝐮1(ui)2𝐮1=𝐯X(vi)2L(ui)2L|X|u_{i}-\frac{(u_{i})^{2}}{\|\mathbf{u}\|_{1}}-\left(\sum_{\mathbf{v}\in X}v_{i}-|X|\frac{\sum_{\mathbf{v}\in X}(v_{i})^{2}}{\|\mathbf{u}\|_{1}}\right)=\frac{|X|\sum_{\mathbf{v}\in X}(v_{i})^{2}}{\|\mathbf{u}\|_{1}}-\frac{(u_{i})^{2}}{\|\mathbf{u}\|_{1}}=\frac{\sum_{\mathbf{v}\in X}(v_{i})^{2}}{L}-\frac{(u_{i})^{2}}{L|X|}

Moreover, the righthand side is equal to

𝐯X(vi)2(𝐯Xvi)2|X|=𝐯X(vi)2(ui)2|X|,\sum_{\mathbf{v}\in X}(v_{i})^{2}-\frac{(\sum_{\mathbf{v}\in X}v_{i})^{2}}{|X|}=\sum_{\mathbf{v}\in X}(v_{i})^{2}-\frac{(u_{i})^{2}}{|X|},

which established the lemma. ∎

We should note that the result presented in the previous lemma is mentioned in the appendix of [4] where the Gini index is discussed.

The connection C1 is a direct consequence of Lemma 1 since it implies that for all kk-partitions 𝒫{\cal P} of VV

Gini(𝒫)=LCostKM(𝒫)+𝐯VGini(𝐯)Gini({\cal P})=L\cdot Cost_{KM}({\cal P})+\sum_{\mathbf{v}\in V}Gini(\mathbf{v})

From the connection C1 and the hardness of geometric kk-means established in [2] we obtain:

Theorem 1.

The Partition with Minimum Weighted Gini Problem (PMWGP) is NP-Complete with respect to goal (1) and APX-Hard with respect to goal (2).

Proof.

The result follows from [2], where a polynomial time reduction from the vertex cover problem on triangle free graphs to the kk-means problem is presented. In this reduction, given a graph G=(V,E)G=(V,E), every edge ee in EE is mapped into a vector 𝐯\mathbf{v} in |V|\mathbb{R}^{|V|} where the ii-th component viv_{i} is 11 if ii is incident on ee and it is 0, otherwise. It is proved that if the minimum vertex cover of GG has size kk then the optimum cost of the corresponding kk-means problem is at most |E|k|E|-k and if the minimum vertex cover has size at least (1+ϵ)k(1+\epsilon)k then the minimum cost is at least |E|(1Ω(ϵ)kCLOSE|E|-(1-\Omega(\epsilon)k.

Our result follows from Lemma 1 and from the fact that in the instance of kk-means above described all vectors have 1\ell_{1} norm equals 2. ∎

With regards to the connection C2, let VV be an input of kk-PMWGP and let VV^{\prime} be an instance of kk-means obtained from VV as follows: for each vector 𝐯V\mathbf{v}\in V we add to the input set VV^{\prime} exactly 𝐯1\|\mathbf{v}\|_{1} copies of vector 𝐯=𝐯/𝐯1\mathbf{v}^{\prime}=\mathbf{v}/\|\mathbf{v}\|_{1}. Using Lemma 1 and also the fact that in any optimal solution for kk-means identical vectors are in the same partition, we conclude that the optimum value of VV and VV^{\prime} differ by exactly 𝐯VGini(𝐯)\sum_{\mathbf{v}\in V}Gini(\mathbf{v}). Note that instance VV^{\prime} is obtained from VV in pseudo-poytime.

From this reduction one we can obtain new algorithms for kk-PMWGP with provable approximation. As an example, we discuss how to obtain a PTAS for kk-PMWGP with respect to the objective function (2) when kk is fixed. First, in our reduction, we keep each distinct vector and its multiplicity rather than all the 𝐯V𝐯1\sum_{\mathbf{v}\in V}\|\mathbf{v}\|_{1} vectors of instance VV^{\prime}. Thus, we can construct the instance VV^{\prime} from VV in polytime. Next, we run over instance VV^{\prime} an adapted version of the recursive PTAS for kk-means proposed in [6]. This version efficiently handles copies of the same vector and it is explained refering to the presentation of the PTAS that is given in Figure 1 of [1].

Let W=𝐯V𝐯1W=\sum_{\mathbf{v}\in V}\|\mathbf{v}\|_{1}. The adapted version is as follows:

  1. 1.

    The set of vectors in VV^{\prime} is represented using the distinct vectors and its multiplicities.

  2. 2.

    In the step 6 of the algorithm described in Figure 1 of [1] a constant number of vectors is sampled from a set of at most nn vectors. In our adaptation we sample from a set of WW vectors, with at most nn of them being distinct. This incurs an extra O(logW)O(\log W) factor to the running time.

  3. 3.

    At Step 12 of the same Figure one needs to compute, from a set of vectors RR, the |R|/2|R|/2 closest vectors to a given set of centroids CC. Since this computation can be performed with time complexity proportional to the number of distinct vectors in RR, rather than in O(|R|)O(|R|) time, we do not incur any additional cost.

This adapted version also incurs an extra factor of O(log(W)k)O(\log(W)^{k}) with respect to the original one (executed over nn vectors) due to the number of nodes in the recursion tree. Thus, it runs in polynomial time when kk is fixed. Without efficiently handling the copies we would have a pseudo-polynomial time approximation scheme.

References

  • [1] M. R. Ackermann, J. Blömer, and C. Sohler. Clustering for metric and nonmetric distance measures. ACM Trans. Algorithms, 6(4):59:1–59:26, 2010.
  • [2] P. Awasthi, M. Charikar, R. Krishnaswamy, and A. K. Sinop. The Hardness of Approximation of Euclidean k-Means. In L. Arge and J. Pach, editors, 31st International Symposium on Computational Geometry (SoCG 2015), volume 34 of Leibniz International Proceedings in Informatics (LIPIcs), pages 754–767, Dagstuhl, Germany, 2015. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik.
  • [3] L. Breiman, J. J. Friedman, R. A. Olshen, and C. J. Stone. Classification and Regression Trees. Wadsworth, 1984.
  • [4] P. A. Chou. Optimal partitioning for classification and regression trees. IEEE Transactions on Pattern Analysis and Machine Intelligence, 13(4), 1991.
  • [5] F. Cicalese and E. Laber. Approximation Algorithms for Clustering via Weighted Impurity Measures. ArXiv e-prints, July 2018.
  • [6] A. Kumar, Y. Sabharwal, and S. Sen. A simple linear time (1+ϵ)(1+\epsilon)-approximation algorithm for kk-means clustering in any dimensions. In IEEE, editor, Proceedings: 45th Annual IEEE Symposium on Foundations of Computer Science: FOCS 2004, 17–19 October, 2004, Rome, Italy, pages 454–462, pub-IEEE:adr, 2004. IEEE Computer Society Press.
  • [7] E. S. Laber, M. Molinaro, and F. de A. Mello Pereira. Binary partitions with approximate minimum impurity. In ICML, 2018.
  • [8] J. R. Quinlan. C4.5: Programs for Machine Learning. Morgan Kaufmann, 1992.