Apriori model not showing obvious associations

I am doing Apriori model for the first time. I have created a test dataset as attached. Clearly there are strong associations like {A,C} -> {K}, {A,C,G} -> {K} etc. But the Apriori model gives me 0 rules with LHS populated.

The data used is:

Items
A,B,J,K
A,B
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,G,K
A,C,K
A,C,K
A,C,K
A,C,K
A,C,K
A,C,K
A,C,K
A,C,K

The code that I am using is:

file6 <- read.transactions("C:/.../Test.csv", sep=',')
rules1 <- apriori(file6, parameter = list(sup = 0.001, conf = 0.005, minlen = 2))
rules1

The result is:

set of 0 rules

I think I am missing something. Please help me find what the issue is.

Thanks

@samit could you pls share Test.csv?

Hi Nuno, thank you for responding. I have put the data in a format which you can copy and paste in excel.

Ok, I tried this:

library(arules)
dados <- read.transactions("data.csv", sep = ",")
summary(dados)
inspect(dados[1:5])
itemFrequency(dados[, 1:3])
dadosrules <- apriori(dados, 
                        parameter = list(support = 0.01, confidence = 0.25, minlen = 2))
inspect(dadosrules[1:3])

And got this, as expected:

transactions as itemMatrix in sparse format with
 25 rows (elements/itemsets/transactions) and
 6 columns (items) and a density of 0.6 

most frequent items:
      A       K       C       G       B (Other) 
     25      24      23      15       2       1 

element (itemset/transaction) length distribution:
sizes
 2  3  4 
 1  8 16 

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    2.0     3.0     4.0     3.6     4.0     4.0 

includes extended item information - examples:
  labels
1      A
2      B
3      C
> inspect(dados[1:5])
    items    
[1] {A,B,J,K}
[2] {A,B}    
[3] {A,C,G,K}
[4] {A,C,G,K}
[5] {A,C,G,K}
> itemFrequency(dados[, 1:3])
   A    B    C 
1.00 0.08 0.92 
inspect(dadosrules[1:3])
    lhs    rhs support confidence coverage lift      count
[1] {J} => {B} 0.04    1.0        0.04     12.500000 1    
[2] {B} => {J} 0.04    0.5        0.08     12.500000 1    
[3] {J} => {K} 0.04    1.0        0.04      1.041667 1   

Thank you very much for your help.

I am still not able to get the obvious rules (like {A,C} -> {K}, etc.).

Can you please try it once again. This time I have loaded the file in Github and fetching data directly. This will make sure that we are using the same data and format.

Can you please run the following program:

myfile <- read.csv(url("https://raw.githubusercontent.com/samitChak/datatable/master/Test.csv"), header = F)
write.csv(myfile, "test_samit_1.csv")


library(arules)
dados <- read.transactions("test_samit_1.csv", sep = ",")
summary(dados)
inspect(dados[1:5])
itemFrequency(dados[, 1:3])
dadosrules <- apriori(dados, 
                      parameter = list(support = 0.01, confidence = 0.25, minlen = 2))
inspect(dadosrules)

The output that I am receiving is:

> inspect(dadosrules)
     lhs          rhs       support    confidence coverage   lift      count
[1]  {24}      => {A,C,K}   0.03846154 1          0.03846154  3.250000 1    
[2]  {23}      => {A,C,K}   0.03846154 1          0.03846154  3.250000 1    
[3]  {22}      => {A,C,K}   0.03846154 1          0.03846154  3.250000 1    
[4]  {21}      => {A,C,K}   0.03846154 1          0.03846154  3.250000 1    
[5]  {20}      => {A,C,K}   0.03846154 1          0.03846154  3.250000 1    
[6]  {19}      => {A,C,K}   0.03846154 1          0.03846154  3.250000 1    
[7]  {18}      => {A,C,K}   0.03846154 1          0.03846154  3.250000 1    
[8]  {17}      => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[9]  {16}      => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[10] {15}      => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[11] {14}      => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[12] {13}      => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[13] {12}      => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[14] {11}      => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[15] {10}      => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[16] {9}       => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[17] {8}       => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[18] {7}       => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[19] {6}       => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[20] {5}       => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[21] {4}       => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[22] {3}       => {A,C,G,K} 0.03846154 1          0.03846154  1.733333 1    
[23] {A,B}     => {2}       0.03846154 1          0.03846154 26.000000 1    
[24] {2}       => {A,B}     0.03846154 1          0.03846154 26.000000 1    
[25] {A,B,J,K} => {1}       0.03846154 1          0.03846154 26.000000 1    
[26] {1}       => {A,B,J,K} 0.03846154 1          0.03846154 26.000000 1    
[27] {25}      => {A,C,K}   0.03846154 1          0.03846154  3.250000 1    
> 

As you can see, it does not help.

With that code, I get the same result as yours.

With my code, inspect(dadosrules), does generate a rule (39) like: {A,C} => {K}

Try removing the commas.

> dadosrules
set of 48 rules 
> inspect(dadosrules)
     lhs        rhs support confidence coverage lift       count
[1]  {J}     => {B} 0.04    1.0000000  0.04     12.5000000  1   
[2]  {B}     => {J} 0.04    0.5000000  0.08     12.5000000  1   
[3]  {J}     => {K} 0.04    1.0000000  0.04      1.0416667  1   
[4]  {J}     => {A} 0.04    1.0000000  0.04      1.0000000  1   
[5]  {B}     => {K} 0.04    0.5000000  0.08      0.5208333  1   
[6]  {B}     => {A} 0.08    1.0000000  0.08      1.0000000  2   
[7]  {G}     => {C} 0.60    1.0000000  0.60      1.0869565 15   
[8]  {C}     => {G} 0.60    0.6521739  0.92      1.0869565 15   
[9]  {G}     => {K} 0.60    1.0000000  0.60      1.0416667 15   
[10] {K}     => {G} 0.60    0.6250000  0.96      1.0416667 15   
[11] {G}     => {A} 0.60    1.0000000  0.60      1.0000000 15   
[12] {A}     => {G} 0.60    0.6000000  1.00      1.0000000 15   
[13] {C}     => {K} 0.92    1.0000000  0.92      1.0416667 23   
[14] {K}     => {C} 0.92    0.9583333  0.96      1.0416667 23   
[15] {C}     => {A} 0.92    1.0000000  0.92      1.0000000 23   
[16] {A}     => {C} 0.92    0.9200000  1.00      1.0000000 23   
[17] {K}     => {A} 0.96    1.0000000  0.96      1.0000000 24   
[18] {A}     => {K} 0.96    0.9600000  1.00      1.0000000 24   
[19] {B,J}   => {K} 0.04    1.0000000  0.04      1.0416667  1   
[20] {J,K}   => {B} 0.04    1.0000000  0.04     12.5000000  1   
[21] {B,K}   => {J} 0.04    1.0000000  0.04     25.0000000  1   
[22] {B,J}   => {A} 0.04    1.0000000  0.04      1.0000000  1   
[23] {A,J}   => {B} 0.04    1.0000000  0.04     12.5000000  1   
[24] {A,B}   => {J} 0.04    0.5000000  0.08     12.5000000  1   
[25] {J,K}   => {A} 0.04    1.0000000  0.04      1.0000000  1   
[26] {A,J}   => {K} 0.04    1.0000000  0.04      1.0416667  1   
[27] {B,K}   => {A} 0.04    1.0000000  0.04      1.0000000  1   
[28] {A,B}   => {K} 0.04    0.5000000  0.08      0.5208333  1   
[29] {C,G}   => {K} 0.60    1.0000000  0.60      1.0416667 15   
[30] {G,K}   => {C} 0.60    1.0000000  0.60      1.0869565 15   
[31] {C,K}   => {G} 0.60    0.6521739  0.92      1.0869565 15   
[32] {C,G}   => {A} 0.60    1.0000000  0.60      1.0000000 15   
[33] {A,G}   => {C} 0.60    1.0000000  0.60      1.0869565 15   
[34] {A,C}   => {G} 0.60    0.6521739  0.92      1.0869565 15   
[35] {G,K}   => {A} 0.60    1.0000000  0.60      1.0000000 15   
[36] {A,G}   => {K} 0.60    1.0000000  0.60      1.0416667 15   
[37] {A,K}   => {G} 0.60    0.6250000  0.96      1.0416667 15   
[38] {C,K}   => {A} 0.92    1.0000000  0.92      1.0000000 23   
[39] {A,C}   => {K} 0.92    1.0000000  0.92      1.0416667 23   
[40] {A,K}   => {C} 0.92    0.9583333  0.96      1.0416667 23   
[41] {B,J,K} => {A} 0.04    1.0000000  0.04      1.0000000  1   
[42] {A,B,J} => {K} 0.04    1.0000000  0.04      1.0416667  1   
[43] {A,J,K} => {B} 0.04    1.0000000  0.04     12.5000000  1   
[44] {A,B,K} => {J} 0.04    1.0000000  0.04     25.0000000  1   
[45] {C,G,K} => {A} 0.60    1.0000000  0.60      1.0000000 15   
[46] {A,C,G} => {K} 0.60    1.0000000  0.60      1.0416667 15   
[47] {A,G,K} => {C} 0.60    1.0000000  0.60      1.0869565 15   
[48] {A,C,K} => {G} 0.60    0.6521739  0.92      1.0869565 15   

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.