# # EPage 374 # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- save_plots = F library(DAAG) library(rpart) set.seed(0) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter11/prob_2_plot.eps", onefile=FALSE, horizontal=FALSE) } # Overfit our tree model and then prune: m = rpart( outcome ~ ., data=monica, method="class", cp=0.0001 ) plotcp(m) if( save_plots ){ dev.off() } m = prune( m, cp=0.0011 * (1+.2) ) plotcp(m) # Print the final tree: if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter11/prob_2_final_tree_plot.eps", onefile=FALSE, horizontal=FALSE) } plot(m); text(m) if( save_plots ){ dev.off() }