Quick R Project: Understanding the Complexity Parameter
Rattle is a terrific teaching tool for R programming. In this little two-part project, you can use
Rattle to help wrap your brain around the complexity parameter (
cp) and what it entails.
The default value of the
.01. To tell you how to calculate
cp is beyond the scope of our discussion here. Just think of
cp as the “minimum benefit” that a split must add to the tree. If the split doesn’t yield at least that much benefit (the value of
rpart() doesn’t add it.
What happens if you set
.00? You get no restrictions on what a split must add. Hence, you wind up with the most complex tree possible. So here’s the first part of this quick project: Set
.00 and Execute, and then use
to draw the tree. Evaluate this tree against the Testing set, and look at the overall error rate. Compared to the original error rate (6.9 percent), is the extra complexity worth adding?
The second part of this project is to move in the other direction. Set
cp to a higher value, like
.10. This makes it restrictive to add a split. Click Execute. Then draw the tree. It looks way less complex than with
cp = .01, doesn’t it? Evaluate against the Testing set. How about that overall error rate?
On a live tree that grows outdoors in your garden, what do you call the process of cutting branches to make the tree look better? Does pruning sound familiar? That’s also the name for eliminating splits to make a decision tree less complex (which is what increasing the