When training a decision tree learning model (or an ensemble of such models) it is often nice to have a policy for deciding when a tree node can no longer be usefully split. There are a variety possibilities. For example, halting when node population size becomes smaller than some threshold is a simple and effective policy. Another approach is to halt when some measure of node purity fails to increase by some minimum threshold. The underlying concept is to have some measure of split quality, and to halt when no candidate split has sufficient quality.
In this post I am going to discuss some advantages to one of my favorite approaches to measuring split quality, which is to use a test statistic significance – aka “pvalue” – of the null hypothesis that the left and right subpopulations are the same after the split. The idea is that if a split is of good quality, then it ought to have caused the subpopulations to the left and right of the split to be meaningfully different. That is to say: the null hypothesis (that they are the same) should be rejected with high confidence, i.e. a small pvalue. What constitutes “small” is always context dependent, but popular pvalues from applied statistics are 0.05, 0.01, 0.005, etc.
update – there is now an Apache Spark JIRA and a pull request for this feature
The remainder of this post is organized in the following sections:
Consistency
Awareness of Sample Sizes
Training Results
Conclusion
Consistency
Test statistic pvalues have some appealing properties as a split quality measure. The test statistic methodology has the advantage of working essentially the same way regardless of the particular test being used. We begin with two sample populations; in our case, these are the left and right subpopulations created by a candidate split. We want to assess whether these two populations have the same distribution (the null hypothesis) or different distributions. We measure some test statistic ‘S’ (Student’s t, ChiSquared, etc). We then compute the probability that S >= the value we actually measured. This probability is commonly referred to as the pvalue. The smaller the pvalue, the less likely it is that our two populations are the same. In our case, we can interpret this as: a smaller pvalue indicates a better quality split.
This consistent methodology has a couple advantages contributing to user experience (UX). If all measures of split quality work in the same way, then there is a lower cognitive load to move between measures once the user understands the common pattern of use. A second advantage is better “unit analysis.” Since all such quality measures take the form of pvalues, there is no risk of a chosen quality measure getting misaligned with a corresponding quality threshold. They are all probabilities, on the interval [0,1], and “smaller threshold” always means “higher threshold of split quality.” By way of comparison, if an application is measuring entropy and then switches to using Gini impurity, these measures are in differing units and care has to be taken that the correct quality threshold is used in each case or the model training policy will be broken. Switching between differing statistical tests does not come with the same risk. A pvalue quality threshold will have the same semantic regardless of which statistical test is being applied: probability that left and right subpopulations are the same, given the particular statistic being measured.
Awareness of Sample Size
Test statistics have another appealing property: many are “aware” of sample size in a way that captures the idea that the smaller the sample size, the larger the difference between populations should be to conclude a given significance. For one example, consider Welch’s ttest, the twosample variation of the t distribution that applies well to comparing left and right sub populations of candidate decision tree splits:
Visualizing the effects of sample sizes n1 and n2 on these equations directly is a bit tricky, but assuming equal sample sizes and variances allows the equations to be simplified quite a bit, so that we can observe the effect of sample size:
These simplified equations show clearly that (all else remaining equal) as sample size grows smaller, the measured tstatistic correspondingly grows smaller (proportional to sqrt(n)), and furthermore the corresponding variance of the t distribution to be applied grows larger. For any given shift in left and right subpopulations, each of these trends yields a larger (i.e. weaker) pvalue. This behavior is desirable for a split quality metric. The less data there is at a given candidate split, the less confidence there should be in split quality. Put another way: we would like to require a larger difference before a split is measured as being good quality when we have less data to work with, and that is exactly the behavior the ttest provides us.
Training Results
These propreties are pleasing, but it remains to show that test statistics can actually improve decision tree training in practice. In the following sections I will compare the effects of training with test statstics with other split quality policies based on entropy and gini index.
To conduct these experiments, I modified a local copy of Apache Spark with the ChiSquared test statistic for comparing categorical distributions. The demo script, which I ran in sparkshell
, can be viewed here.
I generated an example data set that represents a twoclass learning problem, where labels may be 0 or 1. Each sample has 10 clean binary features, such that if the bit is 1, the probability of the label is 90% 1 and 10% 0. There are 5 noise features, also binary, which are completely random. There are 50 samples of each clean feature being on, for a total of 500 samples. There are also 500 samples where all clean features are 0 and the corresponding labels are 90% 0 and 10% 1. The total number of samples in the data set is 1000. The shape of the data is illustrated by the following table:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 

For the first run I use my customized chisquared statistic as the split quality measure. I used a pvalue threshold of 0.01 – that is, I would like my chisquared test to conclude that the probability of left and right split populations are the same is <= 0.01, or that split will not be used. Note, this means I can expect that around 1% of the time, it will conclude a split was good, when it was just luck. This is a reasonable falsepositive rate; random forests are by nature robust to noise, including noise in their own split decisions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 

The first thing to observe is that the resulting decision tree used exactly the 10 clean features 0 through 9, and none of the five noise features. The tree splits off each of the clean features to obtain an optimally accurate leafnode (one with 90% 1s and 10% 0s). A second observation is that the pvalues shown in the demo output are extremely small (i.e. strong) values – around 1e9 (one part in a billion) – for goodquality splits. We can also see “weak” pvalues with magnitudes such as 0.7, 0.2, etc. These are poor quality splits on the noise features that it rejects and does not use in the tree, exactly as we hope to see.
Next, I will show a similar run with the standard available “entropy” quality measure, and a minimum gain threshold of 0.035, which is a value I had to determine by trial and error, as what kind of entropy gains one can expect to see, and where to cut them off, is somewhat unintuitive and likely to be very data dependent.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 

The first observation is that the resulting tree using entropy as a split quality measure is twice the size of the tree trained using the chisquared policy. Worse, it is using the noise features – its quality measure is yielding many more false positives. The entropybased model is less parsimonious and will also have performance problems since the model has included very noisy features.
Lastly, I ran a similar training using the “gini” impurity measure, and a 0.015 quality threshold (again, hopefully optimal value that I had to run multiple experiments to identify). Its quality is better than the entropybased measure, but this model is still substantially larger than the chisquared model, and it still uses some noise features:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 

Conclusion
In this post I have discussed some advantages of using test statstics and pvalues as split quality metrics for decision tree training:
 Consistency
 Awareness of sample size
 Higher quality model training
I believe they are a useful tool for improved training of decision tree models! Happy computing!