# rysunek 2.16 library("MASS") library("class") library("nnet") library("tree") attach(spam) set.seed(123) m <-length(spam$spam) ucz <- sample(1:m, size = round(m/3), replace = FALSE, prob = rep(1/m, m)) spam.ucz <- data.frame(spam[ucz,]) spam.test <- data.frame(spam[-ucz,]) ks<-c(3:10,15, 20, 25, seq(30,100,by=10)) nks<-length(ks) blad.ucz<-numeric(length=nks) blad.test<-numeric(length=nks) names(blad.ucz)<-names(blad.test)<-ks spam.tr<-tree(spam~.,spam.ucz, mindev = 0, minsize = 2) # rys. 2.16a plot(spam.tr,main="Drzewo pełne") # rys. 2.16b spam.pr<-prune.tree(spam.tr,k=25.0) # spam.pr<-prune.tree(spam.tr,best=10,method='misclass') plot(spam.pr)