Market Basket Analysis in R
Christopher Bruffaerts
Statistician
Rules from Grocery store
library(arules)
rules = apriori(data_trx,
parameter = list(
supp = 3/7, conf=0.6, minlen=2)
)
inspect(rules)
Interactive table
library(arulesViz)
inspectDT(rules)
HTML table
Inspection of the rules
inspect(rules)
lhs rhs support confidence lift count
[1] {Bread} => {Butter} 0.4285714 1.0000000 1.1666667 3
[2] {Cheese} => {Wine} 0.4285714 0.7500000 1.0500000 3
[3] {Wine} => {Cheese} 0.4285714 0.6000000 1.0500000 3
[4] {Cheese} => {Butter} 0.4285714 0.7500000 0.8750000 3
[5] {Wine} => {Butter} 0.5714286 0.8000000 0.9333333 4
[6] {Butter} => {Wine} 0.5714286 0.6666667 0.9333333 4
Scatterplot from arulesViz
plot(rules)

Options of the plot
plot(rulesObject, measure, shading, method)
rulesObject: the rules object to be plottedmeasure: Measures for rule interestingness (Support, Confidence, lift,...)shading: Measure used to color points.method: Visualization method to be used ("scatterplot", "matrix", "two-key plot", "matrix3D")Example
plot(rules, measure = c("confidence", "lift"),
shading = "support",
method = "scatterplot")

Two-key plot
plot(rules, method = "two-key plot")

No jittering
plot(rules, method = "two-key plot")

With jittering
plot(rules, method = "two-key plot",jitter = 2)

Interactive rules
plot(rules, engine = "plotly")
From static to interactive

Market Basket Analysis in R