## ----IntroML-DecTree-Iris-readdata--------------------------------------- library(datasets) str(iris) ## ----IntroML-DecTree-Iris-class1, fig.width=10, fig.height=8------------- library(C50) input <- iris[,1:4] output <- iris[,5] model1 <- C5.0(input, output, control = C5.0Control(noGlobalPruning = TRUE,minCases=1)) plot(model1, main="C5.0 Decision Tree - Unpruned, min=1") ## ----IntroML-DecTree-Iris-class1res, fig.width=10, fig.height=8---------- library(ggplot2) ggplot(iris,aes(x=Petal.Length,y=Petal.Width))+ geom_point(aes(colour = factor(Species)))+ # Petal.Length = 1.9 geom_segment(aes(x=1.9,y=min(iris$Petal.Width),xend=1.9,yend=max(iris$Petal.Width)))+ # Petal.Width = 1.7 geom_segment(aes(x=1.9,y=1.7,xend=max(iris$Petal.Length),yend=1.7))+ # Petal.Length = 4.9 geom_segment(aes(x=4.9,y=1.7,xend=4.9,yend=min(iris$Petal.Width)))+ # Petal.Width = 1.5 geom_segment(aes(x=4.9,y=1.5,xend=max(iris$Petal.Length),yend=1.5))+ # Petal.Length = 5.4 geom_segment(aes(x=5.4,y=1.5,xend=5.4,yend=min(iris$Petal.Width)))+ ggtitle("Petal Length x Petal Width") ## ----IntroML-DecTree-Iris-class1a---------------------------------------- summary(model1) C5imp(model1,metric='usage') ## ----IntroML-DecTree-Iris-predict---------------------------------------- newcases <- iris[c(1:3,51:53,101:103),] newcases predicted <- predict(model1, newcases, type="class") predicted ## ----IntroML-DecTree-Iris-class2, fig.width=10, fig.height=8------------- model2 <- C5.0(input, output, control = C5.0Control(noGlobalPruning = FALSE,minCases=1)) plot(model2, main="C5.0 Decision Tree - Pruned, min=1") model2 ## ----IntroML-DecTree-Iris-class3, fig.width=10, fig.height=8------------- model3 <- C5.0(input, output, control = C5.0Control(noGlobalPruning = FALSE,minCases=5)) plot(model3, main="C5.0 Decision Tree - Pruned, min=5")