Plot a Complexity Parameter Table for an Rpart Fit
Gives a visual representation of the cross-validation results in an
plotcp(x, minline = TRUE, lty = 3, col = 1, upper = c("size", "splits", "none"), …)
an object of class
whether a horizontal line is drawn 1SE above the minimum of the curve.
line type for this line
colour for this line
what is plotted on the top axis: the size of the tree (the number of leaves), the number of splits or nothing.
additional plotting parameters
The set of possible cost-complexity prunings of a tree from a nested
set. For the geometric means of the intervals of values of
cp for which
a pruning is optimal, a cross-validation has (usually) been done in
the initial construction by
cptable in the fit contains
the mean and standard deviation of the errors in the cross-validated
prediction against each of the geometric means, and these are plotted
by this function. A good choice of
cp for pruning is often the
leftmost value for which the mean lies below the horizontal line.
A plot is produced on the current graphical device.
Load the required libraries ```r library(rpart) library(rpart.plot) ``` Load a sample dataset ```r data(Titanic) ``` Create a decision Tree ```r decisionTree <- rpart(Survived~., data = Titanic) ``` The raw data in the CP table of the decision tree can be printed using ```r decisionTree$cptable ``` Plot the CP table using the plotcp function ```r plotcp(decisionTree) ```