Stats 202 - Lecture 7

# 79012346 020987654 2 start85 62 6 absent 090322581

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: * 9) Start< 13.5 23 2 absent (0.91304348 0.08695652) * 5) Age=middle 14 4 absent (0.71428571 0.28571429) 10) Start>=12.5 10 1 absent (0.90000000 0.10000000) * 11) Start< 12.5 4 1 present (0.25000000 0.75000000) * 3) Start< 8.5 19 8 present (0.42105263 0.57894737) 6) Start< 4 10 4 absent (0.60000000 0.40000000) 12) Number< 2.5 1 0 absent (1.00000000 0.00000000) * 13) Number>=2.5 9 4 absent (0.55555556 0.44444444) * 7) Start>=4 9 2 present (0.22222222 0.77777778) 14) Number< 3.5 2 0 absent (1.00000000 0.00000000) * 15 In class exercise #25: Use rpart() in R to fit a decision tree to last column of the sonar training data at http://sites.google.com/site/stats202/data/sonar_train.csv Use all the default values. Compute the misclassification error on the training data and also on the test data at http://sites.google.com/site/stats202/data/sonar_test.csv 16 In class exercise #25: Use rpart() in R to fit a decision tree to last column of the sonar training data at http://sites.google.com/site/stats202/data/sonar_train.csv Use all the default values. Compute the misclassification error on the training data and also on the test data at http://sites.google.com/site/stats202/data/sonar_test.csv Solution: install.packages("rpart") library(rpart) train<-read.csv("sonar_train.csv",header=FALSE) y<-as.factor(train[,61]) x<-train[,1:60] fit<-rpart(y~.,x) sum(y!=predict(fit,x,type="class"))/length(y) 17 In class exercise #25: Use rpart() in R to fit a decision tree to last column of the sonar training data at http://sites.google.com/site/stats202/data/sonar_train.csv Use all the default values. Compute the misclassification error on the training data and also on the test data at http://sites.google.com/site/stats202/data/sonar_test.csv Solution (continued): test<-read.csv("sonar_test.csv",header=FALSE) y_test<-as.factor(test[,61]) x_test<-test[,1:60] sum(y_test!=predict(fit,x_test,type="class"))/ (y_...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online