Learn R Programming

arulesViz (version 1.5-2)

rules2matrix: Convert association rules into a matrix

Description

Converts a set of association rules into a matrix with unique LHS itemsets as columns and unique RHS itemsets as rows. The matrix cells contain a quality measure. The LHS itemsets can be grouped.

Usage

rules2matrix(rules, measure = "support", reorder = "measure", ...)
rules2groupedMatrix(rules, measure = "lift", measure2 = "support", k = 10, 
  aggr.fun = mean, lhs_label_items = 2)

Value

rules2matrix returns a matrix with quality values.

rules2groupedMatrix returns a list with elements

m

the grouped matrix for measure.

m2

the grouped matrix for measure2.

clustering_rules

vector with group assignment for each rule.

Arguments

rules

a rules object.

measure

quality measure put in the matrix

reorder

reorder rows and columns? Possible methods are: "none", "measure" (default), "support/confidence", "similarity".

measure2

second quality measure (organized in the same way as measure).

k

number of LHS itemset groups.

aggr.fun

function to aggregate the quality measure for groups.

lhs_label_items

number of top items used to name LHS itemset groups (columns).

...

passed on to DATAFRAME.

Author

Michael Hahsler

References

Michael Hahsler and Radoslaw Karpienko. Visualizing association rules in hierarchical groups. Journal of Business Economics, 87(3):317--335, May 2016. tools:::Rd_expr_doi("10.1007/s11573-016-0822-8").

See Also

plot for rules using method = 'matrix' and method = 'grouped matrix'.

Examples

Run this code
data(Groceries)
rules <- apriori(Groceries, parameter=list(support = 0.001, confidence = 0.8))
rules

## Matrix
m <- rules2matrix(rules[1:10], measure = "lift")
m
plot(rules[1:10], method = "matrix")

## Grouped matrix
# create a matrix with LHSs grouped in k = 10 groups
gm <- rules2groupedMatrix(rules, k = 10)
gm$m

# number of rules per group 
table(gm$clustering_rules)

# get rules for group 1
inspect(rules[gm$clustering_rules == 1])

# create the corresponding grouped matrix plot by passing the grouped matrix as the groups parameter
plot(rules, method = "grouped matrix", groups = gm)

Run the code above in your browser using DataLab