# March 19, 2009 # Examples of the RWeka Package # Weka is a collection of machine learning algorithms. library(RWeka) quartz() #### J48 Decision Trees version of C4.5 algorithm ###### pairs(iris[,-5]) m1 <- J48(Species ~ ., data = iris) m1 ## print and summary summary(m1) ## calls evaluate_Weka_classifier() table(iris$Species, predict(m1)) ## by hand plot(m1) m1 <- J48(Species ~ ., data = iris[,c(-3)]) ## omit petal.length m1 ## print and summary table(iris$Species, predict(m1)) ## by hand plot(m1) m1 <- J48(Species ~ ., data = iris[,c(-3,-4)]) ## omit petal.length m1 ## print and summary table(iris$Species, predict(m1)) ## by hand plot(m1) m1 <- J48(Species ~ ., data = iris[,c(-2,-3,-4)]) ## omit petal.length m1 ## print and summary table(iris$Species, predict(m1)) ## by hand plot(m1) #### Swiss Bank Notes ####### swiss = read.table("SwissBankNotes.txt", TRUE, "",skip=19) swiss = as.data.frame(cbind( swiss, c(rep("Genuine",100),rep("Counterfeit",100)) )) dimnames(swiss)[[2]][7] = "Status" pairs(swiss[,-7]) s1 <- J48(status ~ ., data = swiss) ## omit petal.length summary(s1) plot(s1) ##### SPAM ########## 39.4% spam p1 <- J48(class ~ ., data = spam) plot(p1) p1 <- J48(class ~ ., data = spam[,c(1:57,59)]) plot(p1) summary(p1) ########## Pima Tribe Female Diabetes ########### pima = read.table("pima.indians.diabetes3.txt",TRUE) pairs(pima[,1:7]) pairs(pima[,1:7],col=pima[,8]+1) p2 = J48( class ~ ., data=pima[,-8] ) summary(p2) plot(p2)