Decision Trees: Splits, Entropy, and Pruning
Learning objectives
- Compute the Gini impurity and the entropy of a node, and the weighted impurity a split leaves
- Explain how a tree chooses a split: every threshold of every log, the one that lowers the impurity most
- Read a tree's depth as how many questions it may ask, and see a tree grown until pure fit the tool's noise
- Prune a tree by cost complexity and read the price of a leaf in samples it must call right
One Question at a Time
A decision tree asks one question of one log at a time: is the log at most a threshold? It chooses the log and the threshold that make the two groups of samples it sends left and right as pure as they can be, then asks again of each group. Grown until every leaf is pure it fits everything, the tool's noise and the bed edges with the rock; pruning cuts back every branch whose leaves do not each call enough samples right. On Ogbon-1's neutron and density the tree grown until pure has 16 leaves and calls all 1201 samples the right rock; pruned at a price of 6 samples a leaf it keeps 3 leaves, the well's three rocks, and still calls 0.982 of them right.
The Data
The tree is grown on Ogbon-1, the Petrophysics book's well, as the book's own learning set holds it: 1201 samples from 5800 ft to 6400 ft, every 0.5 ft, its logs recorded by the book's own tool model, which averages a few feet of rock and adds a stated noise. The whole set is synthetic, which is why every number here can be checked. The class is the lithology of the generator's bed table: 429 samples of shale, 616 of sandstone and 156 of limestone. On average the shale reads a neutron porosity of 0.347 v/v, the sandstone 0.264 v/v and the limestone 0.107 v/v, and a density of 2.31, 2.27 and 2.56 g/cc: the limestone is the densest rock in the well and reads the least neutron, and the shale reads the most. The tree reads the two logs as they are, unscaled: a split depends only on the order of a log's values.
Impurity
A node holding samples in the shares of the classes has the Gini impurity , the chance that two samples drawn from it at random are of different rocks, and the entropy , in bits. Both are zero for a pure node and largest when the classes are even. Ogbon-1 as a whole has a Gini impurity of 0.592 and an entropy of 1.407 bits; three even classes would have 0.667 and 1.585 bits.
Choosing a Split
For each log the tree sorts the samples and tries a threshold at every midpoint between consecutive values, 1200 for each log here, and for each it computes the weighted impurity of the two children, . It takes the least. With the Gini impurity the root asks the neutron log: at most 0.316 v/v sends 784 samples left (17 shale, 611 sandstone, 156 limestone) and 417 right (412 shale, 5 sandstone), leaving 0.402 of the root's impurity. The best question of density would leave 0.711. Plate (b) draws every candidate of both logs. With entropy the root asks the same log at 0.308 v/v, leaving 0.422 of the root's entropy: the two criteria rank the splits almost alike.
Growing: Depth
Limited to one question the tree has two leaves, and the left one, sandstone and limestone together, calls them all sandstone: 0.852 of the samples are right and 89.0 ft of the well is called the wrong rock, all 156 limestone samples among it. The second question on the left is density at most 2.441 g/cc, and it puts every limestone sample in one pure leaf: 4 leaves, 0.984 right. Grown until every leaf is pure the tree reaches depth 9 with 16 leaves and calls all 1201 samples right. The last of those splits each gain a sample or two.
Pruning
Cost-complexity pruning grows the tree fully and then, for a price on each leaf, keeps the subtree that makes least, with the share of samples called wrong and the leaves. A branch is cut once the samples its leaves save, each, are no more than the price; the figure states the price in samples, . Raising it walks the pruning path: the full Gini tree loses leaves at prices of 0.6, 0.75, 2, 3 and 5.5 samples, keeping 11, 7, 6, 5 and then 3. At a price of 6 samples a leaf it keeps 3 leaves, shale, sandstone and limestone, and calls 22 samples, 11.0 ft, the wrong rock: 0.982 right. Of those 22, 10 lie within 1.5 ft of a bed boundary, where the tool averages two rocks, and the other 12 inside a bed, where the tool's noise carries a sample across a threshold. The 13 leaves pruning cut were fitting exactly such samples.
The Right Logs
How large a tree must grow depends on how well its logs part the classes. Given gamma ray and density instead, the tree's root asks gamma ray at most 77.4 API, which parts the shale, the radioactive rock, from the rest without a single mistake, and with density at most 2.441 g/cc beneath it the tree has 3 leaves at depth 2 and calls every sample right. On neutron and density every one of the pruned tree's 22 mistakes is shale called sandstone or sandstone called shale: neutron parts the shale by the water bound in its clay, and less cleanly than gamma ray parts it by its radioactivity.
What These Scores Are
Every score in this section is on the samples the tree learned from, on one well, and a tree can always score better on its own samples by growing. Whether the extra leaves help is a question about samples the tree has not seen. Section 7.2 asks it on the field's nine wells, one well held out at a time.