How to do it...

Perform the following steps to analyze the association rules:

  1. First, you need to load the Groceries dataset:
        > data(Groceries)  
  1. You can then examine the summary of the Groceries dataset:
        > summary(Groceries)  
  1. Next, you can use itemFrequencyPlot to examine the relative item frequency of itemsets:
        > itemFrequencyPlot(Groceries, support = 0.1, cex.names=0.8,
topN=5)
The top five item frequency bar plot of groceries transactions
  1. Use apriori to discover rules with support over 0.001 and confidence over 0.5:
        > rules = apriori(Groceries, parameter = list(supp = 0.001, conf =
0.5, target= "rules")) > summary(rules) Output set of 5668 rules rule length distribution (lhs + rhs):sizes 2 3 4 5 6 11 1461 3211 939 46 Min. 1st Qu. Median Mean 3rd Qu. Max. 2.00 3.00 4.00 3.92 4.00 6.00 summary of quality measures: support confidence lift Min. :0.001017 Min. :0.5000 Min. : 1.957 1st Qu.:0.001118 1st Qu.:0.5455 1st Qu.: 2.464 Median :0.001322 Median :0.6000 Median : 2.899 Mean :0.001668 Mean :0.6250 Mean : 3.262 3rd Qu.:0.001729 3rd Qu.:0.6842 3rd Qu.: 3.691 Max. :0.022267 Max. :1.0000 Max. :18.996 mining info: data ntransactions support confidence Groceries 9835 0.001 0.5
  1. We can then inspect the first few rules:
        > inspect(head(rules))
        Output
        lhsrhs              support confidence     lift
        1 {honey}             => {whole milk} 0.001118454  0.7333333
2.870009 2 {tidbits} => {rolls/buns} 0.001220132 0.5217391
2.836542 3 {cocoa drinks} => {whole milk} 0.001321810 0.5909091
2.312611 4 {pudding powder} => {whole milk} 0.001321810 0.5652174
2.212062 5 {cooking chocolate} => {whole milk} 0.001321810 0.5200000
2.035097 6 {cereals} => {whole milk} 0.003660397 0.6428571
2.515917
  1. You can sort rules by confidence and inspect the first few rules:
        > rules=sort(rules, by="confidence", decreasing=TRUE)
> inspect(head(rules))
Output
lhsrhs support confidence lift
1 {rice,
sugar} => {whole milk} 0.001220132 1 3.913649
2 {canned fish,
hygiene articles} => {whole milk} 0.001118454 1 3.913649
3 {root vegetables,
butter,
rice} => {whole milk} 0.001016777 1 3.913649
4 {root vegetables,
whipped/sour cream,
flour} => {whole milk} 0.001728521 1 3.913649
5 {butter,
soft cheese,
domestic eggs} => {whole milk} 0.001016777 1 3.913649
6 {citrus fruit,
root vegetables,
soft cheese} => {other vegetables} 0.001016777 1 5.168156
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset