-->

“RelationRecord object of apyori module” apriori a

2019-04-13 09:20发布

问题:

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