所以我一直在使用 Apyori 从泰坦尼克号幸存者的数据集中获得最低限度的支持。
rules = apriori(titanic, min_support = 0.1, min_confidence = 1.0)
print(list(rules))
这是我将作为输出获得的元素之一的示例
[RelationRecord(items=frozenset({'Crew', 'Adult'}),
support=0.4020899591094957, ordered_statistics=
[OrderedStatistic(items_base=frozenset({'Crew'}),
items_add=frozenset({'Adult'}), confidence=1.0, lift=1.0521032504780115)])
但是,我正在尝试按升力排序,但我不确定如何解决这个问题,因为升力元素似乎在元组内,但我不确定我将如何去关于排序。
非常感谢任何帮助。
谢谢。
最佳答案
您可以将输出放在 Pandas DataFrame 中,然后按升力排序
你有这个:
rules = apriori(titanic, min_support = 0.1, min_confidence = 1.0)
让我们创造成果
results = list(rules)
现在我们要将结果写入 Pandas DataFrame,然后按 Lift 排序
df = pd.DataFrame(columns=('Items','Antecedent','Consequent','Support','Confidence','Lift'))
Support =[]
Confidence = []
Lift = []
Items = []
Antecedent = []
Consequent=[]
for RelationRecord in results:
for ordered_stat in RelationRecord.ordered_statistics:
Support.append(RelationRecord.support)
Items.append(RelationRecord.items)
Antecedent.append(ordered_stat.items_base)
Consequent.append(ordered_stat.items_add)
Confidence.append(ordered_stat.confidence)
Lift.append(ordered_stat.lift)
df['Items'] = list(map(set, Items))
df['Antecedent'] = list(map(set, Antecedent))
df['Consequent'] = list(map(set, Consequent))
df['Support'] = Support
df['Confidence'] = Confidence
df['Lift']= Lift
按提升度对结果数据框进行排序
df.sort_values(by ='Lift', ascending = False, inplace = True)
关于Python Apyori 按提升排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52688220/