Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created February 8, 2021 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/fbe205fe804cbd6e82c2e2bc70966ed2 to your computer and use it in GitHub Desktop.
Save amankharwal/fbe205fe804cbd6e82c2e2bc70966ed2 to your computer and use it in GitHub Desktop.
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('display.max_colwidth', 999)
pd.options.display.float_format = "{:.3f}".format
association=data.copy()
df = pd.get_dummies(association)
min_support = 0.08
max_len = 10
frequent_items = apriori(df, use_colnames=True, min_support=min_support, max_len=max_len + 1)
rules = association_rules(frequent_items, metric='lift', min_threshold=1)
product='Wines'
segment='Biggest consumer'
target = '{\'%s_segment_%s\'}' %(product,segment)
results_personnal_care = rules[rules['consequents'].astype(str).str.contains(target, na=False)].sort_values(by='confidence', ascending=False)
results_personnal_care.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment