Skip to content

After using .transform(...,sparse=True), how to make a DataFrame for input to .fpgrowth()? #878

Answered by geoffreya
geoffreya asked this question in Q&A
Discussion options

You must be logged in to vote

I found the solution. You need to make a couple of small changes where you encode the transactions.
`
#te_ary = te.fit(itemSetList).transform(itemSetList)

#df = pd.DataFrame(te_ary, columns=te.columns_)

fitted = te.fit(itemSetList)

te_ary = fitted.transform(itemSetList, sparse=True) # seemed to work good

df = pd.DataFrame.sparse.from_spmatrix(te_ary, columns=te.columns_) # seemed to work good
`
Now you can call mlxtend's fpgrowth() followed by association_rules().

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rasbt
Comment options

rasbt Jan 9, 2022
Maintainer

Answer selected by geoffreya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants