xerror是交叉验证的估计误差
xval才是10折交叉验证
对于拟合的准确性,不能判断的,因为rpart包提供了复杂度损失修剪的修剪方法,printcp会告诉分裂到每一层,cp是多少,平均相对误差是多少。
其中,cp全称为complexity parameter,指某个点的复杂度,对每一步拆分,模型的拟合优度必须提高的程度,那么,可以选择具有最小xerror的cp的办法:
## prune(fit, cp= fit$cptable[which.min(fit$cptable[,"xerror"]),"CP"])
fit2 <- prune(fit, cp=0.01);
rpart.plot(fit2, branch=1, branch.type=2, type=1, extra=102,
shadow.col="gray", box.col="green",
border.col="blue", split.col="red",
split.cex=1.2, main="Kyphosis决策树")