Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apriori use sets #393

Merged
merged 6 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/sources/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The CHANGELOG for the current development version is available at

##### Changes

- -
- Itemsets generated with `apriori` are now sets ([#344](https://github.com/rasbt/mlxtend/issues/344) by [William Laney](https://github.com/WLaney))


##### Bug Fixes
Expand Down
6 changes: 3 additions & 3 deletions mlxtend/frequent_patterns/apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def apriori(df, min_support=0.5, use_colnames=False, max_len=None):
all_res = []
for k in sorted(itemset_dict):
support = pd.Series(support_dict[k])
itemsets = pd.Series([i for i in itemset_dict[k]])
itemsets = pd.Series([set(i) for i in itemset_dict[k]])

res = pd.concat((support, itemsets), axis=1)
all_res.append(res)
Expand All @@ -139,8 +139,8 @@ def apriori(df, min_support=0.5, use_colnames=False, max_len=None):
res_df.columns = ['support', 'itemsets']
if use_colnames:
mapping = {idx: item for idx, item in enumerate(df.columns)}
res_df['itemsets'] = res_df['itemsets'].apply(lambda x: [mapping[i]
for i in x])
res_df['itemsets'] = res_df['itemsets'].apply(lambda x: set([mapping[i]
for i in x]))
res_df = res_df.reset_index(drop=True)

return res_df
10 changes: 10 additions & 0 deletions mlxtend/frequent_patterns/tests/test_apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ def test_max_len():

res_df2 = apriori(df, max_len=2)
assert len(res_df2.iloc[-1, -1]) == 2


def test_itemsets_type():
res_colindice = apriori(df, use_colnames=False) # This is defualt behavior
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change "defualt" to "default" ? :)

for i in res_colindice['itemsets']:
assert isinstance(i, set) is True

res_colnames = apriori(df, use_colnames=True) # This is defualt behavior
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shouldn't be default behavior then, because the line above with "use_colnames=False" is indicated with default behavior

for i in res_colnames['itemsets']:
assert isinstance(i, set) is True