## Example 1: create a first-matching-rule classifier with non-redundant rules
## sorted by confidence.
data("iris")
# discretize and create transactions
iris.disc <- discretizeDF.supervised(Species ~., iris)
trans <- as(iris.disc, "transactions")
# create rule base with CARs
cars <- mineCARs(Species ~ ., trans, parameter = list(support = .01, confidence = .8))
cars <- cars[!is.redundant(cars)]
cars <- sort(cars, by = "conf")
# create classifier and use the majority class as the default if no rule matches.
cl <- CBA_ruleset(Species ~ .,
rules = cars,
default = uncoveredMajorityClass(Species ~ ., trans, cars),
method = "first")
cl
# look at the rule base
inspect(cl$rules)
# make predictions
prediction <- predict(cl, trans)
table(prediction, response(Species ~ ., trans))
accuracy(prediction, response(Species ~ ., trans))
# Example 2: use weighted majority voting.
cl <- CBA_ruleset(Species ~ .,
rules = cars,
default = uncoveredMajorityClass(Species ~ ., trans, cars),
method = "majority", weights = "lift")
cl
prediction <- predict(cl, trans)
table(prediction, response(Species ~ ., trans))
accuracy(prediction, response(Species ~ ., trans))
## Example 3: Create a classifier with no rules that always predicts
## the majority class. Note, we need cars for the structure and subset it
## to leave no rules.
cl <- CBA_ruleset(Species ~ .,
rules = cars[NULL],
default = majorityClass(Species ~ ., trans))
cl
prediction <- predict(cl, trans)
table(prediction, response(Species ~ ., trans))
accuracy(prediction, response(Species ~ ., trans))
Run the code above in your browser using DataLab