rules-class {arules} | R Documentation |
Class rules — A Set of Rules
Description
Defines the rules
class to represent a set of association rules and methods to work
with rules
.
Usage
rules(rhs, lhs, itemLabels = NULL, quality = data.frame())
## S4 method for signature 'rules'
summary(object, ...)
## S4 method for signature 'rules'
length(x)
## S4 method for signature 'rules'
nitems(x)
## S4 method for signature 'rules'
labels(object, ruleSep = " => ", ...)
## S4 method for signature 'rules'
itemLabels(object)
## S4 replacement method for signature 'rules'
itemLabels(object) <- value
## S4 method for signature 'rules'
itemInfo(object)
lhs(x)
## S4 method for signature 'rules'
lhs(x)
lhs(x) <- value
## S4 replacement method for signature 'rules'
lhs(x) <- value
rhs(x)
rhs(x) <- value
## S4 replacement method for signature 'rules'
rhs(x) <- value
## S4 method for signature 'rules'
rhs(x)
## S4 method for signature 'rules'
items(x)
generatingItemsets(x)
## S4 method for signature 'rules'
generatingItemsets(x)
Arguments
rhs , lhs |
itemMatrix objects or objects that can be converted using |
itemLabels |
a vector of all
possible item labels (character) or a transactions object to copy the item
coding used for |
quality |
a data.frame with quality information (one row per rule). |
object , x |
the object |
... |
further arguments |
ruleSep |
rule separation symbol |
value |
replacement value |
Details
Mined rule sets typically contain several interest measures accessible with
the quality()
method. Additional measures can be calculated via
interestMeasure()
.
To create rules manually, the itemMatrix for the LHS and the RHS of the rules need to be compatible. See itemCoding for details.
Functions
-
summary(rules)
: create a summary -
length(rules)
: returns the number of rules. -
nitems(rules)
: returns the number of items used in the current encoding. -
labels(rules)
: labels for the rules. -
itemLabels(rules)
: returns item labels for the current encoding. -
itemLabels(rules) <- value
: change the item labels in the current encoding. -
itemInfo(rules)
: returns the item info data.frame. -
lhs(rules)
: returns the LHS of the rules as an itemMatrix. -
lhs(rules) <- value
: replaces the LHS of the rules with an itemMatrix. -
rhs(rules) <- value
: replaces the RHS of the rules with an itemMatrix. -
rhs(rules)
: returns the RHS of the rules as an itemMatrix. -
items(rules)
: returns all items in a rule (LHS and RHS) an itemMatrix. -
generatingItemsets(rules)
: returns a collection of the itemsets which generated the rules, one itemset for each rule. Note that the collection can be a multiset and contain duplicated elements. Useunique()
to remove duplicates and obtain a proper set. This method produces the same as the result as callingitems()
, but wrapped into an itemsets object with support information.
Slots
lhs,rhs
itemMatrix representing the left-hand-side and right-hand-side of the rules.
quality
the quality data.frame
info
a list with mining information.
Objects from the Class
Objects are the result of calling the
function apriori()
. Objects can also be created by calls of the
form new("rules", ...)
or by using the constructor function rules()
.
Coercions
-
as("rules", "data.frame")
Author(s)
Michael Hahsler
See Also
Superclass: associations
Other associations functions:
abbreviate()
,
associations-class
,
c()
,
duplicated()
,
extract
,
inspect()
,
is.closed()
,
is.generator()
,
is.maximal()
,
is.redundant()
,
is.significant()
,
is.superset()
,
itemsets-class
,
match()
,
sample()
,
sets
,
size()
,
sort()
,
unique()
Examples
data("Adult")
## Mine rules
rules <- apriori(Adult, parameter = list(support = 0.3))
rules
## Select a subset of rules using partial matching on the items
## in the right-hand-side and a quality measure
rules.sub <- subset(rules, subset = rhs %pin% "sex" & lift > 1.3)
## Display the top 3 support rules
inspect(head(rules.sub, n = 3, by = "support"))
## Display the first 3 rules
inspect(rules.sub[1:3])
## Get labels for the first 3 rules
labels(rules.sub[1:3])
labels(rules.sub[1:3], itemSep = " + ", setStart = "", setEnd="",
ruleSep = " ---> ")
## Manually create rules using the item coding in Adult and calculate some interest measures
twoRules <- rules(
lhs = list(
c("age=Young", "relationship=Unmarried"),
c("age=Old")
),
rhs = list(
c("income=small"),
c("income=large")
),
itemLabels = Adult
)
quality(twoRules) <- interestMeasure(twoRules,
measure = c("support", "confidence", "lift"), transactions = Adult)
inspect(twoRules)