#------------------- # Association Rules #------------------- library(arules) #Groceries data data(Groceries) #Create an item frequency plot for the top 20 items itemFrequencyPlot(Groceries, topN=20, type="absolute") #Get the rules rules <- apriori(Groceries, parameter = list(supp = 0.001, conf = 0.8)) #Show the top 5 rules, but only 2 digits options(digits=2) inspect(rules[1:5]) #Sort rules by confidence rules <- sort(rules, by="confidence", decreasing=TRUE) inspect(rules[1:5]) #Rules with max length of 3 rules <- apriori(Groceries, parameter = list(supp = 0.001, conf = 0.8, maxlen=3)) inspect(rules[1:5]) Source: http://www.salemmarafi.com/code/market-basket-analysis-with-r/