{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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)
Image of page 1

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

View Full Document Right Arrow Icon
c) d) e)
Image of page 2
3) b) c)
Image of page 3

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

View Full Document Right Arrow Icon
4) b)
Image of page 4
c) d)
Image of page 5

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

View Full Document Right 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
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,
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern