#install.packages('rpart') # if you haven't installed the rpart package, the above command will do so. #library(rpart) # print(names(wine2)) # ii<-sample(seq(1,dim(wine2)[1]),100) wineuse<-wine2[ii,] p<-locator() # tree1<-tree(as.factor(class)~alcohol+malicacid+alcalinity+phenols+flavanoids+proanthocyanins+colorintensity+hue,data=wineuse) plot(tree1) text(tree1) # p<-locator() # cvtree1<-cv.tree(tree1,K=5) plot(cvtree1) print(cvtree1) # p<-locator() mim<-min(cvtree1$dev[-1]) sizesel<-min(cvtree1$size[cvtree1$dev==mim]) ptree1<-prune.tree(tree1,best=sizesel) plot(ptree1) text(ptree1)