0

I am trying to get matched antecedents frozensets by comparing with a list like below:

********** Edited *********

 dataset = [['Milk', 'Onion', 'Nutmeg', 'Kidney Beans', 'Eggs', 'Yogurt'],

           ['Dill', 'Onion', 'Nutmeg', 'Kidney Beans', 'Eggs', 'Yogurt'],
           ['Milk', 'Apple', 'Kidney Beans', 'Eggs'],
           ['Milk', 'Unicorn', 'Corn', 'Kidney Beans', 'Yogurt'],
           ['Corn', 'Onion', 'Onion', 'Kidney Beans', 'Ice cream', 'Eggs']]

import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori
te = TransactionEncoder()
te_ary = te.fit(dataset).transform(dataset)
df = pd.DataFrame(te_ary, columns=te.columns_)
frequent_itemsets = apriori(df, min_support=0.6, use_colnames=True)
from mlxtend.frequent_patterns import association_rules

rules = association_rules(frequent_itemsets, metric="lift", min_threshold=1.2)

frozenset(rules["antecedents"]).issubset(frozenset(list(["Eggs","Onion"]))) // it is returning False

but its not returning true even though it matches.

while in R, will like below:

rules[which(is.subset(rules@lhs,new_tran)==T)] //its working fine in R

Is it I am doing in wrong way? I appreciate if any one help me.

Sanjay Chintha
  • 326
  • 1
  • 4
  • 21

0 Answers0