Untitled
unknown
plain_text
13 days ago
842 B
2
Indexable
Never
frommlxtend.frequent_patterns import apriori, association_rules importmatplotlib.pyplot as plt import pandas as pd import numpy as np df = pd.read_csv('C:\\Users\\aliet\\Downloads\\retail_dataset.csv') ## Print first 10 rows df.head(10) items = set() for col in df: items.update(df[col].unique()) print(items) itemset = set(items) encoded_vals = [] for index, row in df.iterrows(): rowset = set(row) labels = {} uncommons = list(itemset - rowset) commons = list(itemset.intersection(rowset)) for uc in uncommons: labels[uc] = 0 for com in commons: labels[com] = 1 encoded_vals.append(labels) #encoded_vals[0] ohe_df = pd.DataFrame(encoded_vals) freq_items = apriori(ohe_df, min_support=0.2, use_colnames=True, verbose=1) freq_items.head(7)
Leave a Comment