“RelationRecord object of apyori module” apriori algorithm python

我只是一个虾纸丫 提交于 2020-01-01 18:35:02

问题


Excuse me for my english, I'm trying to recognize properties that come up frequently in a set of data to deduce a categorization using the apyori package of python. i'm practicing on a dataframe of 20772 transactions and the largest transaction is 543 items.

DataFrame

I converted this DataFrame into a list :

liste = df.astype(str).values.tolist()

I got this list

list

I used the apriori function of the library apyori to generate the association rules:

from apyori import apriori
rules = apriori(liste, min_support= 0.01, min_confidence= 0.2)

to display the result I converted the rules variable to a list :

MB = list(rules)

The problem is that instead of showing me the rules but it shows the RelationRecord "RelationRecord object of apyori module".

like here

result


回答1:


To get list of rules from RelationRecord, convert RelationRecord to list

listRules = [list(MB[i][0]) for i in range(0,len(MB))]

listRules preview



来源:https://stackoverflow.com/questions/51344368/relationrecord-object-of-apyori-module-apriori-algorithm-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!