I'm doing a classification using rpart in R. The tree model is trained by:
> tree <- rpart(activity ~ . , data=trainData)
> pData1 <- predict(tree, testData, type="class")
The accuracy for this tree model is:
> sum(testData$activity==pData1)/length(pData1)
[1] 0.8094276
I read a tutorial to prune the tree by cross validation:
> ptree <- prune(tree,cp=tree$cptable[which.min(tree$cptable[,"xerror"]),"CP"])
> pData2 <- predict(ptree, testData, type="class")
The accuracy rate for the pruned tree is still the same:
> sum(testData$activity==pData2)/length(pData2)
[1] 0.8094276
I want to know what's wrong with my pruned tree? And how can I prune the tree model using cross validation in R? Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…