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

Fix fpmax for sparse matrices #1000

Merged
merged 2 commits into from
Dec 3, 2022
Merged

Fix fpmax for sparse matrices #1000

merged 2 commits into from
Dec 3, 2022

Conversation

tkellogg
Copy link
Contributor

@tkellogg tkellogg commented Dec 1, 2022

Description

While the current functionality supports sparse matrices on an API level, it calls pd.DataFrame.values in order to get the number of rows in the DataFrame. Unfortunately, .values forces the entire DataFrame to be converted into a non-sparse 2D numpy array. So using sparse matrices to fix an OOM doesn't actually make the OOM go away.

This fix is semantically identical, in Pandas terms, except that it doesn't materialize a dense array just to find it's length.

Related issues or pull requests

N/A

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 PYTHONPATH='.' pytest ./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., PYTHONPATH='.' pytest ./mlxtend/classifier/tests/test_stacking_cv_classifier.py -sv)
    • NOTE: 5 tests don't pass, but that's consistent with the state prior to this change.
  • Checked for style issues by running flake8 ./mlxtend

While this function technically supports sparse matrices, it calls
`pd.DataFrame.values` in order to get the number of rows in the
DataFrame. Unfortunately, `.values` forces the entire DataFrame to be
converted into a non-sparse 2D numpy array, which obliviates the whole
purpose behind using a sparse matrix in the first place. It's a simple
fix though.
@tkellogg tkellogg changed the title Fix fpgrowth for sparse matrices Fix fpmax for sparse matrices Dec 1, 2022
@rasbt
Copy link
Owner

rasbt commented Dec 3, 2022

Unfortunately, .values forces the entire DataFrame to be converted into a non-sparse 2D numpy array

Wow, good catch! Thanks for the PR

@codecov
Copy link

codecov bot commented Dec 3, 2022

Codecov Report

Base: 77.45% // Head: 77.46% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (29c97c0) compared to base (f248eb6).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1000      +/-   ##
==========================================
+ Coverage   77.45%   77.46%   +0.01%     
==========================================
  Files         198      198              
  Lines       11171    11171              
  Branches     1406     1406              
==========================================
+ Hits         8652     8654       +2     
+ Misses       2305     2304       -1     
+ Partials      214      213       -1     
Impacted Files Coverage Δ
mlxtend/frequent_patterns/fpmax.py 91.20% <100.00%> (ø)
mlxtend/evaluate/counterfactual.py 100.00% <0.00%> (+6.89%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rasbt rasbt merged commit 0a4013e into rasbt:master Dec 3, 2022
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

2 participants