我只是想知道是否有办法仅显示“支持”和“信心”列?我不需要显示前一列,后续列或提升列。
这是我下面的代码:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from apyori import apriori
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
dataset = [['plates', 'forks', 'knives'],
['plates', 'bowls', 'glasses'],
['forks', 'knives'],
['glasses', 'forks', 'knives'],
['microwave', 'blender'],
['dumbbell', 'workout bands', 'water bottle'],
['dumbbell', 'sneakers'],
['workout bands', 'sneakers'],
['bike', 'earbuds'],
['yoga mat', 'headphones'],
['camera'],
['iPad', 'earbuds', 'phone charger'],
['iPad', 'laptop', 'laptop charger'],
['headphones', 'laptop', 'laptop charger'],
['iPad', 'bluetooth speaker', 'phone charger'],
['microwave', 'coffee maker'],
['camping tent', 'water bottle', 'flashlight'],
['sleeping bag', 'yoga mat', 'sneakers'],
['tv ', 'tv remote'],
['tv', 'tv remote', 'bluetooth speaker']]
te = TransactionEncoder()
te_ary = te.fit(dataset).transform(dataset)
df = pd.DataFrame(te_ary, columns=te.columns_)
frequent_itemsets = apriori(df, min_support=0.1, use_colnames=True)
frequent_itemsets
association_rules(frequent_itemsets, metric="confidence", min_threshold=0.25)
谢谢!
我不知道该库,但是API文档说association_rules
的返回类型是pandas Dataframe。
所以您可以用它来做标准的熊猫东西:
df = association_rules(frequent_itemsets, metric="confidence", min_threshold=0.25)
print(df[["support", "confidence"]])