# **************************************************************** # Lababoratorio 22: Regresion usando arboles de decision # Usa la libreria tree de Ripley # Mayo 2003, Edgar Acuna #**************************************************************** library(tree) arbol<-tree(ozone~radiation+temperature,data=air) arbol summary(arbol) win.graph() plot.tree(arbol, type="u") text(arbol) mejorarbol<-prune.tree(arbol,best=5) mejorarbol win.graph() plot.tree(mejorarbol, type="u") text(mejorarbol) gtemp<-seq(min(air$temperature),max(air$temperature),length=50) gradiation<-seq(min(air$radiation),max(air$radiation),length=50) grid<-cbind(gtemp,gradiation) grid1<-list(radiation=gradiation,temperature=gtemp) grid1<-expand.grid(grid1) estimado<-predict.tree(arbol,grid1) grid2<-as.data.frame(grid1) matest<-matrix(estimado,50,50) persp(gradiation,gtemp,matest, theta=30, phi=45, xlab="radiation", ylab="temperature", zlab="ozone")