data("iris")
m1 <- J48(Species ~ ., data = iris)
m1
table(iris$Species, predict(m1))
write_to_dot(m1)
if(require("party", quietly = TRUE)) plot(m1)
## Using some Weka data sets ...
## J48
DF2 <- read.arff(system.file("arff", "contact-lenses.arff",
package = "RWeka"))
m2 <- J48(`contact-lenses` ~ ., data = DF2)
m2
table(DF2$`contact-lenses`, predict(m2))
if(require("party", quietly = TRUE)) plot(m2)
## M5P
DF3 <- read.arff(system.file("arff", "cpu.arff", package = "RWeka"))
m3 <- M5P(class ~ ., data = DF3)
m3
if(require("party", quietly = TRUE)) plot(m3)
## Logistic Model Tree.
DF4 <- read.arff(system.file("arff", "weather.arff", package = "RWeka"))
m4 <- LMT(play ~ ., data = DF4)
m4
table(DF4$play, predict(m4))
## Larger scale example.
if(require("mlbench", quietly = TRUE)
&& require("party", quietly = TRUE)) {
## Predict diabetes status for Pima Indian women
data("PimaIndiansDiabetes", package = "mlbench")
## Fit J48 tree with reduced error pruning
m5 <- J48(diabetes ~ ., data = PimaIndiansDiabetes,
control = Weka_control(R = TRUE))
plot(m5)
## (Make sure that the plotting device is big enough for the tree.)
}
Run the code above in your browser using DataLab