text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png image_output_1.png
from mlxtend.frequent_patterns import apriori

from mlxtend.frequent_patterns import association_rules

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('../input/market_data_02.csv')
df.columns

from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
hot_encoded_df = df.groupby(['nota_fiscal_id', 'descricao'])['descricao'].count().unstack().reset_index().fillna(0).set_index('nota_fiscal_id')

def encode_units(x):
    if x <= 0:
        return 0
    if x >= 1:
        return 1
hot_encoded_df = hot_encoded_df.applymap(encode_units)

frequent_itemsets = apriori(hot_encoded_df, min_support=0.01, use_colnames=True)
rules = association_rules(frequent_itemsets, metric='lift', min_threshold=1)
rules.head(10)