Thanks to visit codestin.com
Credit goes to github.com

Skip to content

API Add data_transposed argument and warning to make_sparse_coded_signal - #21425

Merged
glemaitre merged 34 commits into
scikit-learn:mainfrom
g4brielvs:warn-make_sparse_coded_signal
Mar 22, 2022
Merged

API Add data_transposed argument and warning to make_sparse_coded_signal#21425
glemaitre merged 34 commits into
scikit-learn:mainfrom
g4brielvs:warn-make_sparse_coded_signal

Conversation

@g4brielvs

@g4brielvs g4brielvs commented Oct 23, 2021

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #19894.

What does this implement/fix? Explain your changes.

  • Add data_transposed argument (default=True) to datasets.make_sparse_coded_signal to avoid confusion.
  • Implement the logic when data_transposed=True.
  • Add data_transposed argument description to docstring.
  • Add FutureWarning to inform future change of the default from True to False.
  • Add test to check future warning message.
  • Add test to check shapes.

Any other comments?

Thanks #Data Umbrella sprint. Thanks so much for reviewing this PR!

@g4brielvs

g4brielvs commented Oct 23, 2021

Copy link
Copy Markdown
Contributor Author

@amueller Thank you so much for your kind help! If any changes are necessary, I'd be happy to continue working on this issue. Please let me know we should also change the example on Orthogonal Matching Pursuit.

@g4brielvs

g4brielvs commented Oct 23, 2021

Copy link
Copy Markdown
Contributor Author

Looking into the check failure on Check Changelog. The future warning should be included to the CHANGELOG.

@amueller

Copy link
Copy Markdown
Member

Yes please add an entry to the changelog :)

Comment thread sklearn/datasets/_samples_generator.py Outdated
@g4brielvs g4brielvs changed the title Add data_tranposed argument and warning to make_sparse_coded_signal Add data_transposed argument and warning to make_sparse_coded_signal Oct 23, 2021
Comment thread sklearn/datasets/_samples_generator.py Outdated
Co-authored-by: Andreas Mueller <[email protected]>
@amueller

Copy link
Copy Markdown
Member

You will also need to add an entry to the changelog, then you're all set!

@g4brielvs
g4brielvs marked this pull request as draft October 23, 2021 18:08
@g4brielvs
g4brielvs marked this pull request as ready for review October 23, 2021 18:12

@jeremiedbb jeremiedbb left a comment

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.

Thanks @g4brielvs !

I think that to be coherent we should also transpose the code and the dictionary. Actually, instead of transposing them at the end, we should change the code to directly create them with the right shape. For instance, D = generator.randn(n_features, n_components) becomes D = generator.randn(n_components, n_features).

Then you can add a test to check that the shapes of all 3 returned arrays are the expected shapes

Comment thread sklearn/datasets/_samples_generator.py Outdated
Comment thread sklearn/datasets/_samples_generator.py Outdated
@g4brielvs
g4brielvs marked this pull request as draft October 26, 2021 23:34
@g4brielvs
g4brielvs marked this pull request as ready for review October 27, 2021 00:11
@g4brielvs
g4brielvs requested a review from jeremiedbb October 27, 2021 00:11
Comment thread doc/whats_new/v1.1.rst Outdated
Comment thread sklearn/datasets/tests/test_samples_generator.py Outdated
Comment thread sklearn/datasets/tests/test_samples_generator.py Outdated
Comment thread sklearn/datasets/_samples_generator.py Outdated
@reshamas

reshamas commented Nov 5, 2021

Copy link
Copy Markdown
Member

Hello @g4brielvs, How is this PR going?

@g4brielvs

Copy link
Copy Markdown
Contributor Author

@reshamas I'm sorry for the delay. I'll submit the changes before the end of the week. I'd really appreciate the opportunity, if possible.

@g4brielvs
g4brielvs requested a review from jeremiedbb February 15, 2022 22:27
@g4brielvs

g4brielvs commented Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

@thomasjpfan Thank you so much and my apologies! I am aware of the contributing guide, but unfortunately I had black unpinned on the environment. I updated to black==22.1.0 and I'll wait to see if the tests are passing.

@g4brielvs
g4brielvs force-pushed the warn-make_sparse_coded_signal branch from 84b728d to 00b83c6 Compare February 15, 2022 22:40
@g4brielvs
g4brielvs force-pushed the warn-make_sparse_coded_signal branch from 00b83c6 to dd2841a Compare February 15, 2022 22:43

@thomasjpfan thomasjpfan left a comment

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.

Thanks for the update. I left a comment regarding the API.

Comment thread doc/whats_new/v1.1.rst Outdated
Comment thread sklearn/datasets/_samples_generator.py
@thomasjpfan

Copy link
Copy Markdown
Member

From the discussion in #21425 (comment), we can move forward with changing the order when data_transposed=False. Basically this behavior:

Y, D, X = make_sparse_coded_signal(..., data_transposed=True)
# Y = D @ X

Y, X, D = make_sparse_coded_signal(..., data_transposed=False)
# Y = X @ D

We would also need to update the documentation to describe the order change.

@jeremiedbb

Copy link
Copy Markdown
Member

@g4brielvs I synced with main and directly pushed the changes we discussed.

@thomasjpfan I think it's ready for a final review.

Comment thread sklearn/datasets/_samples_generator.py Outdated

@thomasjpfan thomasjpfan left a comment

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.

This looks good to me. I think it would be good to have one more opinion for changing the order based on a kwarg.

Comment thread sklearn/datasets/_samples_generator.py Outdated
Comment thread sklearn/datasets/_samples_generator.py Outdated
Comment thread sklearn/datasets/_samples_generator.py Outdated
Comment thread sklearn/datasets/tests/test_samples_generator.py Outdated
@thomasjpfan thomasjpfan changed the title Add data_transposed argument and warning to make_sparse_coded_signal API Add data_transposed argument and warning to make_sparse_coded_signal Mar 18, 2022
@jeremiedbb

Copy link
Copy Markdown
Member

I think it would be good to have one more opinion for changing the order based on a kwarg.

Note for future reviewer: this is temporary and will last until 1.3. After that there will be only 1 return statement as before.

ping @glemaitre, you assigned yourself to the issue, maybe you want to take a look here.

@glemaitre glemaitre left a comment

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.

I find the swap code-dictionary quite surprising

Comment thread sklearn/datasets/_samples_generator.py Outdated
Y = XD has shape (n_samples, n_features).

.. versionadded:: 1.1
.. deprecated:: 1.1

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.

Is it deprecated or versionchanged here

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.

Actually it's neither. It will be both in 1.3 when we do change the default and we deprecate this arg

Comment thread sklearn/datasets/_samples_generator.py Outdated
Comment thread sklearn/datasets/_samples_generator.py Outdated
Comment thread sklearn/datasets/_samples_generator.py Outdated
Comment thread sklearn/datasets/_samples_generator.py Outdated
Comment thread sklearn/decomposition/_dict_learning.py Outdated
n_features=n_samples,
n_nonzero_coefs=n_nonzero_coefs,
random_state=0,
data_transposed=True,

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.

Do we want to change the test to deal now with the change of shape?

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.

I think we can leave that to when we deprecate the param

n_features=n_samples,
n_nonzero_coefs=n_nonzero_coefs,
random_state=0,
data_transposed=True,

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.

Do we want to change the test to deal now with the change of shape?

@glemaitre
glemaitre merged commit ffa0898 into scikit-learn:main Mar 22, 2022

@glemaitre glemaitre left a comment

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.

LGTM

@reshamas

Copy link
Copy Markdown
Member

Congrats to @g4brielvs for completing this PR for the October sprint and everyone for reviewing it as well.
I will be updating our PR spreadsheet from the sprint. :)

@jeremiedbb

Copy link
Copy Markdown
Member

Thanks @g4brielvs !

glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Apr 6, 2022
…nal (scikit-learn#21425)

Co-authored-by: Andreas Mueller <[email protected]>
Co-authored-by: jeremie du boisberranger <[email protected]>
Co-authored-by: Jérémie du Boisberranger <[email protected]>
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.

make_sparse_coded_signal returns data transposed

7 participants