rules-class | R Documentation |
Defines the rules
class to represent a set of association rules and methods to work
with rules
.
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)
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 |
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.
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. Use unique()
to remove duplicates and obtain a proper set. This method produces the same as the result as calling items()
, but wrapped into an itemsets object with support information.
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 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()
.
as("rules", "data.frame")
Michael Hahsler
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()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.