Learn R Programming

arulesCBA (version 1.2.7)

CBA_helpers: Helper Functions For Dealing with Classes

Description

Helper functions to extract the response from transactions or rules, determine the class frequency, majority class, transaction coverage and the uncovered examples per class.

Usage

classes(formula, x)

response(formula, x)

classFrequency(formula, x, type = "relative")

majorityClass(formula, transactions)

transactionCoverage(transactions, rules)

uncoveredClassExamples(formula, transactions, rules)

uncoveredMajorityClass(formula, transactions, rules)

Value

response returns the response label as a factor.

classFrequency returns the item frequency for each class label as a vector.

majorityClass returns the most frequent class label in the transactions.

Arguments

formula

A symbolic description of the model to be fitted.

x, transactions

An object of class arules::transactions or arules::rules.

type

"relative" or "absolute"` to return proportions or absolute counts.

rules

A set of arules::rules.

Author

Michael Hahsler

See Also

arules::itemFrequency(), arules::rules, arules::transactions.

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

Examples

Run this code
data("iris")

iris.disc <- discretizeDF.supervised(Species ~ ., iris)
iris.trans <- as(iris.disc, "transactions")
inspect(head(iris.trans, n = 3))

# convert the class items back to a class label
response(Species ~ ., head(iris.trans, n = 3))

# Class labels
classes(Species ~ ., iris.trans)

# Class distribution. The iris dataset is perfectly balanced.
classFrequency(Species ~ ., iris.trans)

# Majority class
# (Note: since all class frequencies for iris are the same, the first one is returned)
majorityClass(Species ~ ., iris.trans)

# Use for CARs
cars <- mineCARs(Species ~ ., iris.trans, parameter = list(support = 0.3))

#' # Class labels
classes(Species ~ ., cars)

# Number of rules for each class
classFrequency(Species ~ ., cars, type = "absolute")

# conclusion (item in the RHS) of the rule as a class label
response(Species ~ ., cars)

# How many rules (using the first three rules) cover each transactions?
transactionCoverage(iris.trans, cars[1:3])

# Number of transactions per class not covered by the first three rules
uncoveredClassExamples(Species ~ ., iris.trans, cars[1:3])

# Majority class of the uncovered examples
uncoveredMajorityClass(Species ~ ., iris.trans, cars[1:3])

Run the code above in your browser using DataLab