7

I have a dataset which looks like this:

"user.get","search_restaurants","cuisines.get"
"user.get","search_restaurants","user.get","search_restaurants"
"order/address/get_user_addresses"
"search_restaurants","search_restaurantssearch_restaurants"
"restaurant.get","search_restaurants","order/menu","restaurant.get","restaurant.get","restaurant.get","order/menu","order/menu","restaurant.get","restaurant.getsearch_restaurantsrestaurant.get","user.get","order/menu","order/menu","get_user_reviews_filtered","order/menu","restaurant.get"

When I run the apriori algorithm on it:

txn1 = read.transactions(file="path", rm.duplicates=TRUE)
basket_rules <- apriori(txn1, parameter = list(sup = 0.01, conf = 0.01,target="rules"))
inspect(basket_rules)

I get blank lhs's. which are:

{} => {cuisines.get}, etc

Any idea why this might be happening? An how to solve this issue?

Dawny33
  • 10,543
  • 21
  • 82
  • 134

2 Answers2

19

From help("apriori"):

The default value in APparameter for minlen is 1. This means that rules with only one item (i.e., an empty antecedent/LHS) like

{} => {beer}

will be created. These rules mean that no matter what other items are involved the item in the RHS will appear with the probability given by the rule's confidence (which equals the support). If you want to avoid these rules then use the argument parameter=list(minlen=2).

lukeA
  • 53,097
  • 5
  • 97
  • 100
0

The answer by luke is correct. In addition, we can say that apriori always gives us information about the consequent which is RHS in the program. That's why for a single item set having min support equal to min confidence is also given in the resulting output if no 'minlen' is used.

Eg.

  > inspect(rules)
    lhs            rhs     support confidence lift count
[1] {}          => {Soup}  0.8     0.8        1.0  4    
[2] {}          => {Pasta} 0.8     0.8        1.0  4    
[3] {Salad}     => {Ham}   0.4     1.0        1.7  2 

I hope this explains the output(other rules are not shown in this example). The above given is the partial output of this table.

Customer ID       Food 
 1          -Salad, Hamburger, Taco  
 2          -Soup, Hamburger, Pasta 
 3          -Salad, Soup, Hamburger, Pasta 
 4          -Soup, Pasta 
 5          -Taco, Pasta, Soup
Abhishek Rai
  • 19
  • 1
  • 1
  • 8