HW4_Sol - maxcompete=0, maxsurrogate=0, usesurrogate=0,...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework 4 Solutions 1) Read Chapter 4 (all sections) and Chapter 5 (Section 5.7 only). 2) a) b)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
c) d) e)
Background image of page 2
3) b) c)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4) b)
Background image of page 4
c) d)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
e) 5) Here are the correct predictions: Age Number Start Prediction middle 5 10 present young 2 17 absent old 10 6 present young 2 17 absent old 4 15 absent middle 5 15 absent young 3 13 absent old 5 8 present young 7 9 absent middle 3 13 absent
Background image of page 6
6) install.packages("rpart") library(rpart) train<-read.csv("sonar_train.csv",header=FALSE) y<-as.factor(train[,61]) x<-train[,1:60] test<-read.csv("sonar_test.csv",header=FALSE) y_test<-as.factor(test[,61]) x_test<-test[,1:60] train_error<-rep(0,6) test_error<-rep(0,6) for (dep in 1:6) { fit<-rpart(y~.,x, control=rpart.control(minsplit=0,minbucket=0,cp=-1,
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: maxcompete=0, maxsurrogate=0, usesurrogate=0, xval=0,maxdepth=dep)) train_error[dep]<- 1-sum(y==predict(fit,x,type="class"))/length(y) test_error[dep]<- 1- sum(y_test==predict(fit,x_test,type="class"))/length(y_test) } plot(seq(1,6),test_error,type="o",pch=19,ylim=c(0,.5), ylab="Error Rate", xlab="Tree Depth",main="Rajan Patel's Tree Error Plot") points(train_error,type="o",pch=19,lwd=4,col="blue") legend(4,.5,c("Test Error","Training Error"), col=c("black","blue"),pch=19,lwd=c(1,4)) The plot suggests a depth of 5 is optimal. 1 2 3 4 5 6 0.0 0.1 0.2 0.3 0.4 0.5 Rajan Patel's Tree Error Plot Tree Depth Error Rate Test Error Training Error 7) a) c)...
View Full Document

This note was uploaded on 08/20/2011 for the course STATS 202 taught by Professor Taylor during the Summer '09 term at Stanford.

Page1 / 9

HW4_Sol - maxcompete=0, maxsurrogate=0, usesurrogate=0,...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online