rasbt / mlxtend

A library of extension and helper modules for Python's data analysis and machine learning libraries.
https://rasbt.github.io/mlxtend/
Other
4.92k stars 873 forks source link

FPGrowth verbose mode TypeError when itemset elements are ints #559

Closed vishnureddy17 closed 5 years ago

vishnureddy17 commented 5 years ago

When using FPGrowth on itemsets with integer elements, a TypeError is raised when verbose mode is enabled:


TypeError Traceback (most recent call last)

in 3 df = pd.DataFrame(te_ary, columns=te.columns_) 4 ----> 5 frequent_sets = fpgrowth(df, min_support=15/len(itemsets), use_colnames = True, verbose = True) 6 frequent_sets = frequent_sets[frequent_sets['itemsets'].map(len) >= 2].sort_values('support', ascending=False) 7 len(frequent_sets['itemsets']) ~/.local/lib/python3.6/site-packages/mlxtend/frequent_patterns/fpgrowth.py in fpgrowth(df, min_support, use_colnames, max_len, verbose) 109 itemset_supports = [] 110 --> 111 for sup, iset in fpg_step(tree, minsup, colname_map, max_len, verbose): 112 frequent_itemsets.append(frozenset(iset)) 113 itemset_supports.append(sup/num_itemsets) ~/.local/lib/python3.6/site-packages/mlxtend/frequent_patterns/fpgrowth.py in fpg_step(tree, minsup, colnames, max_len, verbose) 169 cond_tree = tree.conditional_tree(item, minsup) 170 for sup, iset in fpg_step(cond_tree, minsup, --> 171 colnames, max_len, verbose): 172 yield sup, iset 173 ~/.local/lib/python3.6/site-packages/mlxtend/frequent_patterns/fpgrowth.py in fpg_step(tree, minsup, colnames, max_len, verbose) 160 if colnames: 161 cond_items = [colnames[i] for i in tree.cond_items] --> 162 cond_items = ", ".join(cond_items) 163 print('\r%d itemsets from tree conditioned on items (%s)' % 164 (count, cond_items), end="\n") TypeError: sequence item 0: expected str instance, int found
rasbt commented 5 years ago

Thanks, definitely looks like a bug. Will fix that some time next week and add a unit test for that.

harenbergsd commented 5 years ago

@rasbt I can fix this weekend if you don't get to it. Let me know

rasbt commented 5 years ago

@harenbergsd if you could fix that, that would also be nice :). I am currently traveling/attending a conference and things are a bit hectic

harenbergsd commented 5 years ago

Sure I got it. Just wouldn't be right to make you fix my bug feature :)

harenbergsd commented 5 years ago

Actually it looks like I already caught this when I added fpmax.

The issue in older version was: https://github.com/rasbt/mlxtend/blob/8dcb6e7251428d20878ae108c3c3247b0092befa/mlxtend/frequent_patterns/fpgrowth.py#L159-L164

Current code is casting to string: https://github.com/rasbt/mlxtend/blob/87cfbf95ba91b5629e546d741a1eaeece8daccc6/mlxtend/frequent_patterns/fpcommon.py#L155-L161

Should be good to go when @vishnureddy17 updates to latest dev version.

rasbt commented 5 years ago

Sure I got it. Just wouldn't be right to make you fix my bug feature :)

haha ok, fair enough. Thanks!

Actually it looks like I already caught this when I added fpmax. The issue in older version was:

Oh yeah, I just double-checked empirically, and both

run without issue. I guess we can close this then.

@vishnureddy17 : After updating to the latest dev version, please let us know in case the problem still persists.