CBA_ruleset {arulesCBA}R Documentation

Constructor for Objects for Classifiers Based on Association Rules

Description

Objects for classifiers based on association rules have class CBA. A creator function CBA_ruleset() and several methods are provided.

Usage

CBA_ruleset(
  formula,
  rules,
  default,
  method = "first",
  weights = NULL,
  bias = NULL,
  model = NULL,
  discretization = NULL,
  description = "Custom rule set",
  ...
)

Arguments

formula

A symbolic description of the model to be fitted. Has to be of form class ~ .. The class is the variable name (part of the item label before =).

rules

A set of class association rules mined with mineCARs() or arules::apriori() (from arules).

default

Default class. If not specified then objects that are not matched by rules are classified as NA.

method

Classification method "first" found rule or "majority".

weights

Rule weights for the majority voting method. Either a quality measure available in the classification rule set or a numeric vector of the same length are the classification rule set can be specified. If missing, then equal weights are used

bias

Class bias vector.

model

An optional list with model information (e.g., parameters).

discretization

A list with discretization information used by predict() to discretize data supplied as a data.frame.

description

Description field used when the classifier is printed.

...

Additional arguments added as list elements to the CBA object.

Details

CBA_ruleset() creates a new object of class CBA using the provides rules as the rule base. For method "first", the user needs to make sure that the rules are predictive and sorted from most to least predictive.

Value

A object of class CBA representing the trained classifier with fields:

formula

used formula.

rules

the classifier rule base.

default

default class label (uses partial matching against the class labels).

method

classification method.

weights

rule weights.

bias

class bias vector if available.

model

list with model description.

discretization

discretization information.

description

description in human readable form.

rules returns the rule base.

Author(s)

Michael Hahsler

See Also

mineCARs()

Other classifiers: CBA(), CBA_helpers, FOIL(), LUCS_KDD_CBA, RCAR(), RWeka_CBA

Other preparation: discretizeDF.supervised(), mineCARs(), prepareTransactions(), transactions2DF()

Examples

## 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))

[Package arulesCBA version 1.2.7 Index]