knitr::opts_chunk$set(collapse = TRUE, comment = "#>") library(arules) set.seed(1234)
Association rule mining can produce more rules than are practical to inspect. An effective workflow constrains the search, filters and ranks the result, and then removes rules that add no information.
trans <- transactions(list( T1 = c("bread", "butter", "milk"), T2 = c("bread", "butter"), T3 = c("bread", "milk"), T4 = c("bread", "butter", "jam"), T5 = c("bread", "butter", "milk"), T6 = c("butter", "jam"), T7 = c("bread", "milk", "cereal"), T8 = c("bread", "butter", "jam") ))
Support, confidence, and rule length constrain the rule set while Apriori is
searching. The appearance argument can also restrict items to the left- or
right-hand side. Here, Apriori generates only rules that predict butter or
milk.
rules <- apriori( trans, parameter = list( support = 0.25, confidence = 0.6, maxlen = 3 ), appearance = list( rhs = c("butter", "milk"), default = "lhs" ) ) inspect(rules)
These constraints produce only r length(rules) rules. Constraining the search
also reduces its memory and computation requirements.
Filter by criteria appropriate for the task, then rank the remaining rules. Keeping these criteria in the code makes the selection reproducible.
selected <- subset(rules, lift > 1 & confidence >= 0.7) ranked <- sort(selected, by = "lift", decreasing = TRUE) inspect(ranked)
Many interest measures are available in addition to support, confidence, and
lift. The vignette
Interest measures
(vignette("interest-measures", package = "arules")) introduces the use
of additional interest measures.
A rule is redundant if a more general rule with the same consequent performs at least as well according to the selected measure. Removing redundant rules produces a more concise result.
non_redundant <- rules[!is.redundant(rules)] inspect(sort(non_redundant, by = "lift"))
The complementary subset contains the redundant rules that were removed.
inspect(rules[is.redundant(rules)])
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.