Hierarchical Clustering

Hirarchichal clustering is one of the unsupervised non-linear algorithm where clusters are made with a hierarchy. An example is given of a family where all the family members are grouped together to form a hierachchy. The hierarchical clustering is has two branches the Agglomerative Hierarchichal clustering which is also known as the bottom up approach and the Divisive clustering which is the top down approach. The Agglomerative Hierarchical clustering starts at individual leaves and successfully merges clusters together while the Divisive Hierarchical clustering commence at the root and recursively split the clusters. The hierarchical clustering analysis practice was performed on the Rstudio datasets and the output displayed as follows;

## Warning: package 'dplyr' was built under R version 4.1.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00
##   speed dist
## 1     4    2
## 2     4   10
## 3     7    4
## 4     7   22
## 5     8   16
## 6     9   10

Finding distance matrix

##             1          2          3          4          5          6          7
## 2    8.000000                                                                  
## 3    3.605551   6.708204                                                       
## 4   20.223748  12.369317  18.000000                                            
## 5   14.560220   7.211103  12.041595   6.082763                                 
## 6    9.433981   5.000000   6.324555  12.165525   6.082763                      
## 7   17.088007  10.000000  14.317821   5.000000   2.828427   8.062258           
## 8   24.738634  17.088007  22.203603   5.000000  10.198039  16.031220   8.000000
## 9   32.557641  24.738634  30.149627  12.369317  18.110770  24.020824  16.000000
## 10  16.552945   9.899495  13.601471   6.403124   3.162278   7.280110   1.414214
## 11  26.925824  19.313208  24.331050   7.211103  12.369317  18.110770  10.049876
## 12  14.422205   8.944272  11.180340   9.433981   4.472136   5.000000   4.472136
## 13  19.697716  12.806248  16.763055   5.385165   5.656854  10.440307   2.828427
## 14  23.409400  16.124515  20.615528   5.385165   8.944272  14.317821   6.324555
## 15  27.202941  19.697716  24.515301   7.810250  12.649111  18.248288  10.198039
## 16  25.632011  18.357560  22.803509   7.211103  11.180340  16.492423   8.544004
## 17  33.241540  25.632011  30.594117  13.416408  18.681542  24.331050  16.278821
## 18  33.241540  25.632011  30.594117  13.416408  18.681542  24.331050  16.278821
## 19  44.911023  37.107951  42.426407  24.738634  30.413813  36.221541  28.160256
## 20  26.000000  18.867962  23.086793   8.062258  11.661904  16.763055   8.944272
## 21  35.440090  27.856777  32.756679  15.652476  20.880613  26.476405  18.439089
## 22  58.855756  50.990195  56.435804  38.639358  44.407207  50.249378  42.190046
## 23  78.638413  70.710678  76.321688  58.420887  64.280635  70.178344  62.128898
## 24  21.095023  14.866069  17.888544   8.246211   8.062258  11.661904   5.385165
## 25  26.400758  19.416488  23.409400   8.944272  12.206556  17.088007   9.433981
## 26  53.150729  45.354162  50.635956  32.984845  38.639358  44.407207  36.345564
## 27  32.310989  25.059928  29.410882  13.453624  17.888544  23.086793  15.231546
## 28  39.849718  32.310989  37.107951  20.124612  25.298221  30.805844  22.803509
## 29  32.695565  25.553865  29.732137  14.142136  18.357560  23.409400  15.652476
## 30  40.162171  32.695565  37.363083  20.591260  25.632011  31.048349  23.086793
## 31  49.729267  42.059482  47.074409  29.732137  35.171011  40.792156  32.756679
## 32  42.379240  34.928498  39.560081  22.825424  27.856777  33.241540  25.298221
## 33  55.785303  48.083261  53.150729  35.735137  41.231056  46.872167  38.832976
## 34  75.312682  67.468511  72.835431  55.108983  60.827625  66.610810  58.549125
## 35  83.186537  75.312682  80.752709  62.968246  68.731361  74.545288  66.483081
## 36  37.161808  30.016662  34.176015  18.439089  22.825424  27.856777  20.124612
## 37  46.486557  39.000000  43.680659  26.832816  31.953091  37.363083  29.410882
## 38  67.683085  59.908263  65.115282  47.539457  53.150729  58.855756  50.803543
## 39  34.000000  27.202941  30.870698  16.401219  20.000000  24.596748  17.204651
## 40  48.703183  41.231056  45.880279  29.068884  34.176015  39.560081  31.622777
## 41  52.497619  44.944410  49.729267  32.695565  37.947332  43.416587  35.440090
## 42  56.320511  48.703183  53.600373  36.400549  41.761226  47.296934  39.293765
## 43  64.031242  56.320511  61.392182  43.965896  49.477268  55.108983  47.074409
## 44  66.483081  58.821765  63.788714  46.486557  51.923020  57.489129  49.477268
## 45  55.362442  47.927028  52.497619  35.777088  40.853396  46.173586  38.275318
## 46  70.880181  63.245553  68.154237  50.921508  56.320511  61.846584  53.851648
## 47  92.195445  84.403791  89.627005  72.034714  77.665951  83.360662  75.312682
## 48  93.171884  85.375641  90.609050  73.006849  78.644771  84.344532  76.295478
## 49 119.682914 111.803399 117.239072  99.463561 105.223572 111.018017 102.956301
## 50  85.615419  77.884530  82.975900  65.520989  71.063352  76.687678  68.658576
##             8          9         10         11         12         13         14
## 2                                                                              
## 3                                                                              
## 4                                                                              
## 5                                                                              
## 6                                                                              
## 7                                                                              
## 8                                                                              
## 9    8.000000                                                                  
## 10   9.055385  17.029386                                                       
## 11   2.236068   6.082763  11.000000                                            
## 12  12.165525  20.099751   3.162278  14.035669                                 
## 13   6.324555  14.142136   3.162278   8.062258   6.000000                      
## 14   2.828427  10.198039   7.071068   4.123106  10.000000   4.000000           
## 15   2.828427   6.324555  11.045361   1.000000  14.000000   8.000000   4.000000
## 16   3.000000   8.544004   9.219544   2.828427  12.041595   6.082763   2.236068
## 17   8.544004   3.000000  17.117243   6.324555  20.024984  14.035669  10.049876
## 18   8.544004   3.000000  17.117243   6.324555  20.024984  14.035669  10.049876
## 19  20.223748  12.369317  29.068884  18.110770  32.015621  26.019224  22.022716
## 20   4.000000   8.944272   9.486833   3.605551  12.165525   6.324555   2.828427
## 21  10.770330   4.472136  19.235384   8.544004  22.090722  16.124515  12.165525
## 22  34.234486  26.305893  43.104524  32.140317  46.043458  40.049969  36.055513
## 23  54.147945  46.173586  63.071388  52.086467  66.030296  60.033324  56.035703
## 24   7.810250  14.866069   5.000000   8.944272   6.708204   3.000000   5.000000
## 25   5.000000   9.433981   9.848858   4.472136  12.369317   6.708204   3.605551
## 26  28.442925  20.615528  37.215588  26.305893  40.112342  34.132096  30.149627
## 27   8.485281   6.324555  15.811388   6.403124  18.439089  12.649111   8.944272
## 28  15.231546   8.485281  23.537205  13.000000  26.305893  20.396078  16.492423
## 29   9.219544   7.280110  16.155494   7.211103  18.681542  13.000000   9.433981
## 30  15.652476   9.219544  23.769729  13.416408  26.476405  20.615528  16.763055
## 31  25.000000  17.464249  33.541020  22.803509  36.345564  30.413813  26.476405
## 32  17.888544  11.313708  25.961510  15.652476  28.635642  22.803509  18.973666
## 33  31.048349  23.409400  39.623226  28.861739  42.426407  36.496575  32.557641
## 34  50.635956  42.755117  59.413803  48.507731  62.289646  56.320511  52.345009
## 35  58.549125  50.635956  67.364679  56.435804  70.256672  64.280635  60.299254
## 36  13.453624   9.219544  20.615528  11.313708  23.086793  17.464249  13.892444
## 37  21.931712  15.000000  30.083218  19.697716  32.756679  26.925824  23.086793
## 38  42.953463  35.171011  51.623638  40.792156  54.451814  48.507731  44.553339
## 39  11.661904  10.198039  17.492856   9.848858  19.697716  14.422205  11.313708
## 40  24.166092  17.204651  32.280025  21.931712  34.928498  29.120440  25.298221
## 41  27.856777  20.591260  36.138622  25.632011  38.832976  32.984845  29.120440
## 42  31.622777  24.166092  40.024992  29.410882  42.755117  36.878178  32.984845
## 43  39.293765  31.622777  47.853944  37.107951  50.635956  44.721360  40.792156
## 44  41.761226  34.176015  50.219518  39.560081  52.952809  47.074409  43.174066
## 45  30.870698  23.853721  38.897301  28.635642  41.484937  35.735137  31.953091
## 46  46.173586  38.626416  54.571055  43.965896  57.271284  51.419841  47.539457
## 47  67.468511  59.665736  76.118329  65.306967  78.917679  72.993150  69.050706
## 48  68.447060  60.638272  77.103826  66.287254  79.906195  73.979727  70.035705
## 49  95.036835  87.132084 103.817147  92.913939 106.677083 100.717426  96.747093
## 50  60.876925  53.160135  69.426220  58.694122  72.180330  66.287254  62.369865
##            15         16         17         18         19         20         21
## 2                                                                              
## 3                                                                              
## 4                                                                              
## 5                                                                              
## 6                                                                              
## 7                                                                              
## 8                                                                              
## 9                                                                              
## 10                                                                             
## 11                                                                             
## 12                                                                             
## 13                                                                             
## 14                                                                             
## 15                                                                             
## 16   2.236068                                                                  
## 17   6.082763   8.000000                                                       
## 18   6.082763   8.000000   0.000000                                            
## 19  18.027756  20.000000  12.000000  12.000000                                 
## 20   2.828427   1.000000   8.062258   8.062258  20.024984                      
## 21   8.246211  10.049876   2.236068   2.236068  10.049876  10.000000           
## 22  32.062439  34.014703  26.019224  26.019224  14.035669  34.000000  24.000000
## 23  52.038447  54.009258  46.010868  46.010868  34.014703  54.000000  44.000000
## 24   8.544004   6.324555  14.142136  14.142136  26.076810   6.082763  16.031220
## 25   3.605551   2.000000   8.246211   8.246211  20.099751   1.000000  10.049876
## 26  26.172505  28.071338  20.099751  20.099751   8.246211  28.017851  18.027756
## 27   5.656854   6.708204   3.605551   3.605551  14.317821   6.324555   4.472136
## 28  12.649111  14.317821   6.708204   6.708204   6.708204  14.142136   4.472136
## 29   6.403124   7.211103   4.472136   4.472136  14.560220   6.708204   5.000000
## 30  13.000000  14.560220   7.211103   7.211103   7.211103  14.317821   5.000000
## 31  22.561028  24.331050  16.492423  16.492423   5.656854  24.186773  14.317821
## 32  15.231546  16.763055   9.433981   9.433981   6.403124  16.492423   7.211103
## 33  28.635642  30.413813  22.561028  22.561028  11.180340  30.265492  20.396078
## 34  48.373546  50.249378  42.296572  42.296572  30.413813  50.159745  40.199502
## 35  56.320511  58.215118  50.249378  50.249378  38.327536  58.137767  48.166378
## 36  10.630146  11.661904   6.324555   6.324555  11.661904  11.180340   5.000000
## 37  19.313208  20.880613  13.416408  13.416408   6.000000  20.615528  11.180340
## 38  40.607881  42.426407  34.525353  34.525353  22.803509  42.296572  32.388269
## 39   8.944272   9.219544   7.280110   7.280110  15.652476   8.485281   7.211103
## 40  21.540659  23.086793  15.652476  15.652476   7.280110  22.803509  13.416408
## 41  25.298221  26.925824  19.313208  19.313208   9.219544  26.683328  17.088007
## 42  29.120440  30.805844  23.086793  23.086793  12.206556  30.594117  20.880613
## 43  36.878178  38.639358  30.805844  30.805844  19.313208  38.470768  28.635642
## 44  39.293765  41.000000  33.241540  33.241540  21.931712  40.792156  31.048349
## 45  28.231188  29.732137  22.360680  22.360680  12.806248  29.410882  20.124612
## 46  43.680659  45.354162  37.643060  37.643060  26.400758  45.122057  35.440090
## 47  65.115282  66.910388  59.033889  59.033889  47.296934  66.753277  56.885851
## 48  66.098411  67.896981  60.016664  60.016664  48.270074  67.742158  57.870545
## 49  92.779308  94.641429  86.700634  86.700634  74.813100  94.530418  84.593144
## 50  58.463664  60.207973  52.392748  52.392748  40.804412  60.016664  50.219518
##            22         23         24         25         26         27         28
## 2                                                                              
## 3                                                                              
## 4                                                                              
## 5                                                                              
## 6                                                                              
## 7                                                                              
## 8                                                                              
## 9                                                                              
## 10                                                                             
## 11                                                                             
## 12                                                                             
## 13                                                                             
## 14                                                                             
## 15                                                                             
## 16                                                                             
## 17                                                                             
## 18                                                                             
## 19                                                                             
## 20                                                                             
## 21                                                                             
## 22                                                                             
## 23  20.000000                                                                  
## 24  40.012498  60.008333                                                       
## 25  34.014703  54.009258   6.000000                                            
## 26   6.082763  26.019224  34.000000  28.000000                                 
## 27  28.071338  48.041649  12.041595   6.082763  22.022716                      
## 28  20.099751  40.049969  20.024984  14.035669  14.035669   8.000000           
## 29  28.160256  48.093659  12.165525   6.324555  22.090722   1.000000   8.062258
## 30  20.223748  40.112342  20.099751  14.142136  14.142136   8.062258   1.000000
## 31  10.440307  30.149627  30.066593  24.083189   4.472136  18.027756  10.049876
## 32  18.439089  38.209946  22.203603  16.278821  12.369317  10.198039   2.828427
## 33   5.656854  24.331050  36.124784  30.149627   3.605551  24.083189  16.124515
## 34  16.492423   5.656854  56.080300  50.089919  22.203603  44.045431  36.055513
## 35  24.331050   5.656854  64.070274  58.077534  30.149627  52.038447  44.045431
## 36  24.515301  44.283180  16.492423  10.770330  18.439089   5.000000   5.000000
## 37  14.866069  34.365681  26.305893  20.396078   8.944272  14.317821   6.708204
## 38   9.433981  13.000000  48.166378  42.190046  14.560220  36.124784  28.160256
## 39  28.635642  48.373546  13.000000   7.810250  22.561028   4.000000   8.944272
## 40  13.416408  32.557641  28.442925  22.561028   7.810250  16.492423   8.944272
## 41  10.000000  28.635642  32.388269  26.476405   5.385165  20.396078  12.649111
## 42   7.211103  24.738634  36.345564  30.413813   5.385165  24.331050  16.492423
## 43   7.211103  17.088007  44.283180  38.327536  11.180340  32.249031  24.331050
## 44  10.000000  16.124515  46.529560  40.607881  13.892444  34.525353  26.683328
## 45  10.816654  27.513633  34.928498  29.120440   8.000000  23.086793  15.652476
## 46  14.142136  14.142136  50.803543  44.911023  18.357560  38.832976  31.048349
## 47  33.526109  15.620499  72.560320  66.610810  39.051248  60.530984  52.611786
## 48  34.481879  16.401219  73.552702  67.601775  40.024992  61.522354  53.600373
## 49  60.827625  41.231056 100.404183  94.429868  66.610810  88.362888  80.399005
## 50  27.313001  12.083046  65.764732  59.841457  32.572995  53.758720  45.891176
##            29         30         31         32         33         34         35
## 2                                                                              
## 3                                                                              
## 4                                                                              
## 5                                                                              
## 6                                                                              
## 7                                                                              
## 8                                                                              
## 9                                                                              
## 10                                                                             
## 11                                                                             
## 12                                                                             
## 13                                                                             
## 14                                                                             
## 15                                                                             
## 16                                                                             
## 17                                                                             
## 18                                                                             
## 19                                                                             
## 20                                                                             
## 21                                                                             
## 22                                                                             
## 23                                                                             
## 24                                                                             
## 25                                                                             
## 26                                                                             
## 27                                                                             
## 28                                                                             
## 29                                                                             
## 30   8.000000                                                                  
## 31  18.000000  10.000000                                                       
## 32  10.049876   2.236068   8.062258                                            
## 33  24.020824  16.031220   6.082763  14.000000                                 
## 34  44.011362  36.013886  26.019224  34.000000  20.000000                      
## 35  52.009614  44.011362  34.014703  42.000000  28.000000   8.000000           
## 36   4.472136   4.472136  14.142136   6.082763  20.024984  40.012498  48.010416
## 37  14.142136   6.324555   4.472136   4.123106  10.049876  30.016662  38.013156
## 38  36.055513  28.071338  18.110770  26.019224  12.041595   8.062258  16.031220
## 39   3.000000   8.544004  18.248288  10.198039  24.083189  44.045431  52.038447
## 40  16.278821   8.544004   3.605551   6.324555   8.246211  28.071338  36.055513
## 41  20.223748  12.369317   3.605551  10.198039   4.472136  24.083189  32.062439
## 42  24.186773  16.278821   6.708204  14.142136   2.000000  20.099751  28.071338
## 43  32.140317  24.186773  14.317821  22.090722   8.246211  12.165525  20.099751
## 44  34.365681  26.476405  16.763055  24.331050  10.770330  10.770330  18.439089
## 45  22.803509  15.231546   7.211103  13.000000   5.385165  22.561028  30.413813
## 46  38.639358  30.805844  21.189620  28.635642  15.231546   8.485281  15.231546
## 47  60.406953  52.469038  42.579338  50.358713  36.496575  17.088007  10.000000
## 48  61.400326  53.460266  43.566042  51.351728  37.483330  18.027756  10.816654
## 49  88.277970  80.305666  70.349129  78.230429  64.280635  44.407207  36.496575
## 50  53.600373  45.705580  35.902646  43.566042  29.832868  11.401754   7.071068
##            36         37         38         39         40         41         42
## 2                                                                              
## 3                                                                              
## 4                                                                              
## 5                                                                              
## 6                                                                              
## 7                                                                              
## 8                                                                              
## 9                                                                              
## 10                                                                             
## 11                                                                             
## 12                                                                             
## 13                                                                             
## 14                                                                             
## 15                                                                             
## 16                                                                             
## 17                                                                             
## 18                                                                             
## 19                                                                             
## 20                                                                             
## 21                                                                             
## 22                                                                             
## 23                                                                             
## 24                                                                             
## 25                                                                             
## 26                                                                             
## 27                                                                             
## 28                                                                             
## 29                                                                             
## 30                                                                             
## 31                                                                             
## 32                                                                             
## 33                                                                             
## 34                                                                             
## 35                                                                             
## 36                                                                             
## 37  10.000000                                                                  
## 38  32.000000  22.000000                                                       
## 39   4.123106  14.035669  36.013886                                            
## 40  12.041595   2.236068  20.024984  16.000000                                 
## 41  16.031220   6.082763  16.031220  20.000000   4.000000                      
## 42  20.024984  10.049876  12.041595  24.000000   8.000000   4.000000           
## 43  28.017851  18.027756   4.123106  32.000000  16.000000  12.000000   8.000000
## 44  30.149627  20.223748   3.605551  34.058773  18.110770  14.142136  10.198039
## 45  18.439089   8.944272  14.560220  22.203603   6.708204   3.605551   3.605551
## 46  34.365681  24.515301   5.385165  38.209946  22.360680  18.439089  14.560220
## 47  56.222771  46.270941  24.515301  60.133186  44.181444  40.199502  36.221541
## 48  57.218878  47.265209  25.495098  61.131007  45.177428  41.194660  37.215588
## 49  84.148678  74.168727  52.239832  88.090862  72.111026  68.117545  64.124878
## 50  49.365980  39.458839  18.027756  53.235327  37.336309  33.376639  29.427878
##            43         44         45         46         47         48         49
## 2                                                                              
## 3                                                                              
## 4                                                                              
## 5                                                                              
## 6                                                                              
## 7                                                                              
## 8                                                                              
## 9                                                                              
## 10                                                                             
## 11                                                                             
## 12                                                                             
## 13                                                                             
## 14                                                                             
## 15                                                                             
## 16                                                                             
## 17                                                                             
## 18                                                                             
## 19                                                                             
## 20                                                                             
## 21                                                                             
## 22                                                                             
## 23                                                                             
## 24                                                                             
## 25                                                                             
## 26                                                                             
## 27                                                                             
## 28                                                                             
## 29                                                                             
## 30                                                                             
## 31                                                                             
## 32                                                                             
## 33                                                                             
## 34                                                                             
## 35                                                                             
## 36                                                                             
## 37                                                                             
## 38                                                                             
## 39                                                                             
## 40                                                                             
## 41                                                                             
## 42                                                                             
## 43                                                                             
## 44   2.828427                                                                  
## 45  10.440307  12.041595                                                       
## 46   7.211103   4.472136  16.031220                                            
## 47  28.284271  26.076810  38.013156  22.000000                                 
## 48  29.274562  27.073973  39.012818  23.000000   1.000000                      
## 49  56.142675  54.037024  66.007575  50.000000  28.000000  27.000000           
## 50  21.587033  19.235384  31.064449  15.033296   7.071068   8.062258  35.014283

Fitting Hierarchical clustering Model

## 
## Call:
## hclust(d = distance_mat, method = "average")
## 
## Cluster method   : average 
## Distance         : euclidean 
## Number of objects: 50

The model has it that, the cluster method is average, distance is euclidean and no. of objects are 50. ## Plotting dendrogram

The plot dendrogram is shown with x-axis as distance matrix and y-axis as height.

Differences between HCA and k means

HCA can’t handle big data as well as kmeans
Results are responsible in hierarchical clustering unlike kmeans.
*K means mostly works well with globular clusters.
## Linkage The linkage methods in statistics is applied by evaluating the distances or similarities between all objects. Then the closest pair of clusters are combined into a single cluster, reducing the number of clusters remaining. The process is then repeated until there is only a single cluster left.

MARKET BASKET ANALYSIS

It is the investigation of any collection of commodities to uncover affinities that may be exploited.

Market Basket Analysis uses the information to:

Capable of recognizing customer purchasing patterns
To identify who customers are(not by name)
Understand why you buy certain items.

The Groceries Dataset

The Groceries dataset has been used in this analysis and all the out put generetad accordingly.

## Warning: package 'arules' was built under R version 4.1.3
## Loading required package: Matrix
## 
## Attaching package: 'arules'
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
## Warning: package 'arulesViz' was built under R version 4.1.3
## Formal class 'transactions' [package "arules"] with 3 slots
##   ..@ data       :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
##   .. .. ..@ i       : int [1:43367] 13 60 69 78 14 29 98 24 15 29 ...
##   .. .. ..@ p       : int [1:9836] 0 4 7 8 12 16 21 22 27 28 ...
##   .. .. ..@ Dim     : int [1:2] 169 9835
##   .. .. ..@ Dimnames:List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : NULL
##   .. .. ..@ factors : list()
##   ..@ itemInfo   :'data.frame':  169 obs. of  3 variables:
##   .. ..$ labels: chr [1:169] "frankfurter" "sausage" "liver loaf" "ham" ...
##   .. ..$ level2: Factor w/ 55 levels "baby food","bags",..: 44 44 44 44 44 44 44 42 42 41 ...
##   .. ..$ level1: Factor w/ 10 levels "canned food",..: 6 6 6 6 6 6 6 6 6 6 ...
##   ..@ itemsetInfo:'data.frame':  0 obs. of  0 variables

Create an item frequency plot for the top 20 items

Lets explore the data before we make any rules

## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.8    0.1    1 none FALSE            TRUE       5   0.001      1
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 9 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [157 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 6 done [0.02s].
## writing ... [410 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.8    0.1    1 none FALSE            TRUE       5   0.001      1
##  maxlen target  ext
##       3  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 9 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [157 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3
## Warning in apriori(Groceries, parameter = list(supp = 0.001, conf = 0.8, :
## Mining stopped (maxlen reached). Only patterns up to a length of 3 returned!
##  done [0.01s].
## writing ... [29 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].

Redundancies

Rules will be repeated sometimes. Redundancy means one item could be specified. You have the option of removing the item from the dataset. Otherwise, redundant rules generated can be removed. These repeated rules can be deleted using the following code snippet.

## Warning in `[<-`(`*tmp*`, as.vector(i), value = NA): x[.] <- val: x is
## "ngTMatrix", val not in {TRUE, FALSE} is coerced; NA |--> TRUE.

Targeting Items

Since we can generate rules then we minimize the output, we therefore look at the rules. For example we can choose our interested target “all milk”

##     lhs                      rhs              support confidence    coverage     lift count
## [1] {rice,                                                                                 
##      sugar}               => {whole milk} 0.001220132          1 0.001220132 3.913649    12
## [2] {canned fish,                                                                          
##      hygiene articles}    => {whole milk} 0.001118454          1 0.001118454 3.913649    11
## [3] {root vegetables,                                                                      
##      butter,                                                                               
##      rice}                => {whole milk} 0.001016777          1 0.001016777 3.913649    10
## [4] {root vegetables,                                                                      
##      whipped/sour cream,                                                                   
##      flour}               => {whole milk} 0.001728521          1 0.001728521 3.913649    17
## [5] {butter,                                                                               
##      soft cheese,                                                                          
##      domestic eggs}       => {whole milk} 0.001016777          1 0.001016777 3.913649    10
##     lhs             rhs                support    confidence coverage lift    
## [1] {whole milk} => {other vegetables} 0.07483477 0.2928770  0.255516 1.513634
## [2] {whole milk} => {rolls/buns}       0.05663447 0.2216474  0.255516 1.205032
## [3] {whole milk} => {yogurt}           0.05602440 0.2192598  0.255516 1.571735
## [4] {whole milk} => {root vegetables}  0.04890696 0.1914047  0.255516 1.756031
## [5] {whole milk} => {tropical fruit}   0.04229792 0.1655392  0.255516 1.577595
##     count
## [1] 736  
## [2] 557  
## [3] 551  
## [4] 481  
## [5] 416

Visualization