Assosiation rule learning is a method of identifying frequent if-then patterns. Thanks to that, it is feasible to determine how items are connected. In the following analysis Apriori and ECLAT method is applied to find strong assosiaction rules.
Dataset used to determine rules is Market Basket Data Analysis. It consists 999 transactions with 10 products.

Source: https://www.kaggle.com/ahmtcnbs/datasets-for-appiori

The following libraaries were used for the below analysis:

library(arules)
library(arulesViz)
library(rattle)
library(dplyr)
basket_df <- read.csv("basket_analysis.csv")

basket_df <- subset(basket_df, select = -c(X))

The logical variables are converted to the dummy ones for further analysis purpose.

basket_df <- basket_df %>% 
  mutate(across(everything(), ~+as.logical(.x)))

The dataset is checked whether is contains any missing entries.

any(is.na.data.frame(basket_df))
## [1] FALSE

Item matrix is created for further analysis.

b_matrix <- as.matrix(basket_df)
imatrix <- as(b_matrix, "itemMatrix")
itemFrequencyPlot(imatrix, topN = 20)

The Apriori assosiation algorithm is applied to search rules. The initial conditions are set to allow algorithm to learn rules. In the first attempt the support parameter is equal to 0.1 with confidence level 0.2

basket_rules <- apriori(imatrix, parameter = list(support = 0.1, confidence = 0.2))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.2    0.1    1 none FALSE            TRUE       5     0.1      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: 99 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[16 item(s), 999 transaction(s)] done [0.00s].
## sorting and recoding items ... [16 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 done [0.00s].
## writing ... [355 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
inspect(sort(basket_rules, by = "lift")[1:5])
##     lhs                  rhs         support   confidence coverage  lift    
## [1] {Cheese, Dill}    => {Onion}     0.1021021 0.5762712  0.1771772 1.428523
## [2] {Dill, Unicorn}   => {chocolate} 0.1011011 0.6011905  0.1681682 1.426578
## [3] {Dill, Milk}      => {chocolate} 0.1141141 0.6000000  0.1901902 1.423753
## [4] {Dill, chocolate} => {Milk}      0.1141141 0.5728643  0.1991992 1.413065
## [5] {Cheese, Onion}   => {Dill}      0.1021021 0.5513514  0.1851852 1.383920
##     count
## [1] 102  
## [2] 101  
## [3] 114  
## [4] 114  
## [5] 102

Support level indicates in how many transactions the product from lend hand site was chosen. Confidence level determines probability that a product from right hand site will be purchased. The Lift value describes likeliness of purchasing a good Y if X good is purchased as well. Values greater than 1 mean that product Y is more likely to be chosen if product X was picked. Lift value below 1 indicates that a consumer is averse towards product from the right hand site.

For 10 percent of all transactions, the probability that a consumer who bought cheese and dill will also but onion is 57,6 percent.

In the following attempt the desired result is to determine rules for single products with the highest support, confidence lift rate.

basket_rules <- apriori(imatrix, parameter = list(support = 0.18, confidence = 0.5))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.5    0.1    1 none FALSE            TRUE       5    0.18      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: 179 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[16 item(s), 999 transaction(s)] done [0.00s].
## sorting and recoding items ... [16 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 done [0.00s].
## writing ... [5 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
inspect(sort(basket_rules, by = "lift")[1:5])
##     lhs            rhs         support   confidence coverage  lift     count
## [1] {Milk}      => {chocolate} 0.2112112 0.5209877  0.4054054 1.236263 211  
## [2] {chocolate} => {Milk}      0.2112112 0.5011876  0.4214214 1.236263 211  
## [3] {Ice.cream} => {Butter}    0.2072072 0.5048780  0.4104104 1.200889 207  
## [4] {Bread}     => {Yogurt}    0.1931932 0.5026042  0.3843844 1.195480 193  
## [5] {Dill}      => {chocolate} 0.1991992 0.5000000  0.3983984 1.186461 199
plot(basket_rules, method = "graph", engine = "htmlwidget")

The lift value above 1 suggests that the most popular product is milk and chocolate which appears in 21 percent of transaction. The third single product with the greatest lift is butter and yoghurt.

basket_rules <- apriori(imatrix, parameter = list(support = 0.1, confidence = 0.2))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.2    0.1    1 none FALSE            TRUE       5     0.1      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: 99 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[16 item(s), 999 transaction(s)] done [0.00s].
## sorting and recoding items ... [16 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 done [0.00s].
## writing ... [355 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
inspect(sort(basket_rules, by = "lift")[1:5])
##     lhs                  rhs         support   confidence coverage  lift    
## [1] {Cheese, Dill}    => {Onion}     0.1021021 0.5762712  0.1771772 1.428523
## [2] {Dill, Unicorn}   => {chocolate} 0.1011011 0.6011905  0.1681682 1.426578
## [3] {Dill, Milk}      => {chocolate} 0.1141141 0.6000000  0.1901902 1.423753
## [4] {Dill, chocolate} => {Milk}      0.1141141 0.5728643  0.1991992 1.413065
## [5] {Cheese, Onion}   => {Dill}      0.1021021 0.5513514  0.1851852 1.383920
##     count
## [1] 102  
## [2] 101  
## [3] 114  
## [4] 114  
## [5] 102
plot(basket_rules, method = "graph", engine = "htmlwidget")
## Warning: Too many rules supplied. Only plotting the best 100 using
## 'lift' (change control parameter max if needed).

The Equivalence Class Transformer algorithm (ECLAT) is treated as another method of searching the assosiation rules.

itemsets <- eclat(imatrix, parameter = list(supp = 0.18, maxlen = 5))
## Eclat
## 
## parameter specification:
##  tidLists support minlen maxlen            target  ext
##     FALSE    0.18      1      5 frequent itemsets TRUE
## 
## algorithmic control:
##  sparse sort verbose
##       7   -2    TRUE
## 
## Absolute minimum support count: 179 
## 
## create itemset ... 
## set transactions ...[16 item(s), 999 transaction(s)] done [0.00s].
## sorting and recoding items ... [16 item(s)] done [0.00s].
## creating bit matrix ... [16 row(s), 999 column(s)] done [0.00s].
## writing  ... [94 set(s)] done [0.00s].
## Creating S4 object  ... done [0.00s].

The rules are created from the frequent itemsets

rules <- ruleInduction(itemsets, confidence = .5)

inspect(sort(rules, by = "lift")[1:5])
##     lhs            rhs         support   confidence lift    
## [1] {Milk}      => {chocolate} 0.2112112 0.5209877  1.236263
## [2] {chocolate} => {Milk}      0.2112112 0.5011876  1.236263
## [3] {Ice.cream} => {Butter}    0.2072072 0.5048780  1.200889
## [4] {Bread}     => {Yogurt}    0.1931932 0.5026042  1.195480
## [5] {Dill}      => {chocolate} 0.1991992 0.5000000  1.186461

Eclat and Apriori have the same results therefore both methods are successful For accepted support: 0.18 and confidence level 0.5 we obtained the same rules.

Conclusion Asossiation rules are useful to search an interesting patterns in customers behaviour. According to the above analysis the most popular products is milk, chocolate, butter and yoghurt.