Reputation: 81
good afternoon! I have problem with a decisional trees.
f11<-as.factor(Z24train$f1)
fit_f1 <- rpart(f11~TSU+TSL+TW+TP,data = Z24train,method="class")
plot(fit_f1, uniform=TRUE, main="Classification Tree for Kyphosis")
But this error appears:
Error in plot.rpart(fit_f1, uniform = TRUE, main = "Classification Tree for Kyphosis") :
fit is not a tree, just a root
which is the problem? thanks for the help :)
Upvotes: 7
Views: 19745
Reputation: 211
This is probably due to RPART
is not being able to create a decision tree with the given data set after using it's default control parameters.
rpart.control(minsplit = 20, minbucket = round(minsplit/3), cp = 0.01,
maxcompete = 4, maxsurrogate = 5, usesurrogate = 2, xval = 10,
surrogatestyle = 0, maxdepth = 30, ...)
If you want to create the tree you can adjust control parameters and create an over fitting tree.
tree <- rpart(f11~TSU+TSL+TW+TP,data = Z24train,method="class",control =rpart.control(minsplit =1,minbucket=1, cp=0))
Parameter description taken from r documentation (https://stat.ethz.ch/R-manual/R-devel/library/rpart/html/rpart.control.html)
minsplit
the minimum number of observations that must exist in a node in order for a split to be attempted.
minbucket
the minimum number of observations in any terminal node. If only one of minbucket or minsplit is specified, the code either sets minsplit to minbucket*3 or minbucket to minsplit/3, as appropriate.
cp
complexity parameter. Any split that does not decrease the overall lack of fit by a factor of cp is not attempted. For instance, with anova splitting, this means that the overall R-squared must increase by cp at each step. The main role of this parameter is to save computing time by pruning off splits that are obviously not worthwhile. Essentially,the user informs the program that any split which does not improve the fit by cp will likely be pruned off by cross-validation, and that hence the program need not pursue it
Upvotes: 14