Learn R Programming

arules (version 1.7-9)

rules-class: 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 rules summary(object, ...)

# S4 method for rules length(x)

# S4 method for rules nitems(x)

# S4 method for rules labels(object, ruleSep = " => ", ...)

# S4 method for rules itemLabels(object)

# S4 method for rules itemLabels(object) <- value

# S4 method for rules itemInfo(object)

lhs(x)

# S4 method for rules lhs(x)

lhs(x) <- value

# S4 method for rules lhs(x) <- value

rhs(x)

rhs(x) <- value

# S4 method for rules rhs(x) <- value

# S4 method for rules rhs(x)

# S4 method for rules items(x)

generatingItemsets(x)

# S4 method for rules generatingItemsets(x)

Arguments

rhs, lhs

itemMatrix objects or objects that can be converted using encode().

itemLabels

a vector of all possible item labels (character) or a transactions object to copy the item coding used for encode() (see itemCoding for details).

quality

a data.frame with quality information (one row per rule).

object, x

the object

...

further arguments

ruleSep

rule separation symbol

value

replacement value

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. 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.

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

Michael Hahsler

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.

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

Run this code
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)

Run the code above in your browser using DataLab