python中的关联规则(Apriori算法)选择适当的数据

时间:2019-04-21 17:15:15

标签: python apriori

我有以下数据集。

token

我使用apyori导入apriori中的aprori库。 现在,我使用愚蠢的代码。我创建列表列表。

Age,Height,Weight,Medal
24,180,80,No Medal
23,170,60,No Medal
24,177,73,No Medal
34,182,96,Gold

但是我得到以下结果。

for i in range(0, len(dataframe)):
    records.append([str(dataframe.values[i, j]) for j in range(0, 4)])
association_rules = apriori(records, min_support=0.0045, min_confidence=0.2, min_lift=3, min_length=2)
association_results = list(association_rules) 
for item in association_results:
    # first index of the inner list
    # Contains base item and add item
    pair = item[0]
    items = [x for x in pair]
    print("Rule: " + items[0] + " -> " + items[1])

    # second index of the inner list
    print("Support: " + str(item[1]))

    # third index of the list located at 0th
    # of the third index of the inner list

    print("Confidence: " + str(item[2][0][2]))
    print("Lift: " + str(item[2][0][3]))
    print("=====================================")

我想获得以下结果。例如

Rule: 171 -> 18
Support: 0.007242940288855357
Confidence: 0.6970954356846474
Lift: 8.665127883550587
=====================================
Rule: 171 -> 61
Support: 0.009312351799956887
Confidence: 0.8888888888888888
Lift: 11.049184232463976

Rule: 171 -> No Medal
Support: 0.04850183229144212
Confidence: 0.7560483870967741
Lift: 9.397932657400684

仅后果牌结果。我应该改变什么?

0 个答案:

没有答案