I am trying to understand the use of R to run the apriori algorithm to mine association rules.Referencing an online exam question with solutions provided on Studocs Q2.2, it is expected that I get 8 association rules which fulfill the minimum support and minimum confidence criteria. However, I tried to run it in R and I only got 7, the missing rule being milk -> bread,butter
.
May I know if anyone knows what I can do to allow the R snippet to produce the 8th rule or any rule that has an RHS length of more than 1.
Here is the snippet of R code which contains the transaction data as described in the question and the use of apriori
. Let me know if more information is required to solve the problem.
library('arules')
library('arulesViz')
dataset = list(
c("Bread", "Butter", "Milk"),
c("Bread", "Butter"),
c("Beer", "Cookies", "Diapers"),
c("Milk", "Diapers", "Bread", "Butter"),
c("Beer", "Diapers")
)
Groceries = transactions(dataset)
itemsets <- apriori(Groceries,
parameter=list(
support=0.4, confidence = 0.7))
inspect(sort(itemsets, by = "support"))