前言: “尿布和啤酒”的故事,电商中的个性化商品推荐怎么实现的
代码示例:
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
frequent_itemsets = apriori(slim_dummy_df, min_support=0.05, use_colnames=True)
vaild_frequent_itemsets = frequent_itemsets[frequent_itemsets.itemsets.apply(lambda x: len(x)) >= 3]
association_rule = association_rules(frequent_itemsets,metric='confidence',min_threshold=0.9) # metric可以有很多的度量选项,返回的表列名都可以作为参数
association_rule.sort_values(by='leverage',ascending=False,inplace=True) #关联规则可以按leverage排序