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

Apriori use sets #393

merged 6 commits into from
Jun 15, 2018

Conversation

WLaney
Copy link
Contributor

@WLaney WLaney commented Jun 11, 2018

Description

Changes apriori to return itemsets as sets instead of lists.

Related issues or pull requests

Disscused in issue 344

Pull Request Checklist

  • Added a note about the modification or contribution to the ./docs/sources/CHANGELOG.md file (if applicable)
  • Added appropriate unit test functions in the ./mlxtend/*/tests directories (if applicable)
  • Modify documentation in the corresponding Jupyter Notebook under mlxtend/docs/sources/ (if applicable)
  • Ran nosetests ./mlxtend -sv and make sure that all unit tests pass (for small modifications, it might be sufficient to only run the specific test file, e.g., nosetests ./mlxtend/classifier/tests/test_stacking_cv_classifier.py -sv)
  • Checked for style issues by running flake8 ./mlxtend

@coveralls
Copy link

coveralls commented Jun 11, 2018

Coverage Status

Coverage increased (+0.01%) to 91.267% when pulling a7cdb41 on WLaney:apriori-use-sets into bcf3f44 on rasbt:master.

@rasbt
Copy link
Owner

rasbt commented Jun 12, 2018

Thanks for the PR!

I think for efficiency reasons, to avoid yet another for-loop, it would be better to do the transformation to sets some place earlier in the code. For example, replacing the line itemsets = pd.Series([set(i) for i in itemset_dict[k]] by

itemsets = pd.Series([set(i) for i in itemset_dict[k]]

and then the line for the use_colnames loop as well. I.e., res_df['itemsets'] = res_df['itemsets'].apply(lambda x: {mapping[i] for i in x}).

Would be great if you could also add a short unit test checking that the types of the itemsets is indeed "set" for use_colnames=True & False

Thanks!

@WLaney
Copy link
Contributor Author

WLaney commented Jun 14, 2018

Thank you for the advice!

I tried to do the transformation earlier in the code on my first go, but I couldn't quite figure out where to do it without messing up the panda data structure. I was able to get it this time with your help though!

For the unit test I'm just looping through the returned itemsets and checking the type of each element. I've never had to make unit tests before, but I that test seems to checks what we want. If you think it would be better to do something else though just let me know.



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

@rasbt
Copy link
Owner

rasbt commented Jun 14, 2018

That looks good, thanks! Could you maybe just do the little comment-fix that I mentioned above? Besides that, this looks good!

@WLaney
Copy link
Contributor Author

WLaney commented Jun 15, 2018

Thanks! And yeah, no problem. Sorry about the comments, that was just carelessness on my part.

@rasbt
Copy link
Owner

rasbt commented Jun 15, 2018

That's great, thanks for the fix & PR

@rasbt rasbt merged commit 84fde97 into rasbt:master Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants