Skip to content

TST Extend tests for scipy.sparse.*array in test_nmf.py#27100

Merged
adrinjalali merged 5 commits intoscikit-learn:mainfrom
ivirshup:sparse-array-nmf
Aug 18, 2023
Merged

TST Extend tests for scipy.sparse.*array in test_nmf.py#27100
adrinjalali merged 5 commits intoscikit-learn:mainfrom
ivirshup:sparse-array-nmf

Conversation

@ivirshup
Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Towards #27090

What does this implement/fix? Explain your changes.

This modifies the NMF transformer to accept scipy.sparse.sparray classes.

Any other comments?

Still needs tests to check that the NMF returns the correct type. I am not 100% sure it's going to be obvious what the desired return type is.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 18, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 7530b65. Link to the linter CI: here

@ivirshup
Copy link
Copy Markdown
Contributor Author

I think the only place that it's expected this could return a sparse type is inverse_transform. I was expecting this because of the docs:

image

However, I'm now thinking that inverse_transform only ever returns numpy arrays since I believe .components_ is always a dense array and inverse_transform is Xt @ self.components_

Maybe the docs should be updated?

@ivirshup ivirshup marked this pull request as ready for review August 18, 2023 13:17
@ivirshup
Copy link
Copy Markdown
Contributor Author

I convinced myself .components_ is always a np.ndarray by adding some assert isinstance(self.components_, np.ndarray) into fit_transform and running the test suite. So I've fixed those docs.

Returns
-------
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
X : ndarray of shape (n_samples, n_features)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indeed, this is in line with the docstring of _fit_transform that should always return H as numpy arrays for both solvers (coordinate descent and multiplicative update).

Copy link
Copy Markdown
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

LGTM (assuming CI will turn out green).

@adrinjalali adrinjalali enabled auto-merge (squash) August 18, 2023 17:45
@adrinjalali adrinjalali merged commit 6d50c2e into scikit-learn:main Aug 18, 2023
@ivirshup ivirshup deleted the sparse-array-nmf branch August 18, 2023 19:02
TamaraAtanasoska pushed a commit to TamaraAtanasoska/scikit-learn that referenced this pull request Aug 21, 2023
…earn#27100)

Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
akaashpatelmns pushed a commit to akaashp2000/scikit-learn that referenced this pull request Aug 25, 2023
…earn#27100)

Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
…earn#27100)

Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants