Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

RFC Make non_negative_factorization call NMF instead of the opposite #19607

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

Merged
merged 18 commits into from
Mar 12, 2021

Conversation

cmarmo
Copy link
Contributor

@cmarmo cmarmo commented Mar 3, 2021

Reference Issues/PRs

Working on the MiniBatch implementation of the Non-negative Matrix Factorization class (#16948), it has been suggested that a reformat of both standard NMF and the in progress MiniBatch implementation would improve the maintainability of the code. This pull request applies this reformatting using #14985 and #18975 as models.

What does this implement/fix? Explain your changes.

Make non_negative_factorization call NMF instead of the opposite.

Any other comments?

I had to add a tag to the NMF class to avoid the n_features_in common test: but I'm not sure this was the right way to make the test pass.
ping @TomDLT and @jeremiedbb : thanks!

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

I made a first quick pass

sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
@cmarmo
Copy link
Contributor Author

cmarmo commented Mar 11, 2021

Hello everyone I need some help about n_features_in_
I have a number of tests failing with the error

E           AttributeError: 'NMF' object has no attribute 'n_components_'

from the lines
https://github.com/cmarmo/scikit-learn/blob/d4eeb7861947cb352080f13993dcbfb5a5ca1ef7/sklearn/decomposition/_nmf.py#L1394-L1396

I put here a snippet having the same problem

import numpy as np
from sklearn.decomposition import non_negative_factorization

rng = np.random.RandomState(0)
X = rng.random_sample((20, 15))
H = rng.random_sample((15, 15))
W = rng.random_sample((20, 15))

non_negative_factorization(X, H=H, update_H=False)

Apparently the check_is_fitted(self) function thinks the estimator is fitted because attrs contains 'n_features_in_', see


(I have temporarily added a print(attrs) to check). Is that an expected behavior? Thanks!

@jeremiedbb
Copy link
Member

Hello everyone I need some help about n_features_in_

Let's forget the idea of being able to call transform without fit. It makes the code too complicated. That way this PR is completely transparent to the user and doesn't change the API at all. I directly pushed this.

sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

thanks @cmarmo. I just have one last remark

sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
Copy link
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, just a small suggestion and a question/confirmation:

sklearn/decomposition/tests/test_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
sklearn/decomposition/_nmf.py Outdated Show resolved Hide resolved
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @cmarmo !

@TomDLT TomDLT changed the title [WIP] Make non_negative_factorization call NMF instead of the opposite. RFC Make non_negative_factorization call NMF instead of the opposite Mar 12, 2021
@TomDLT TomDLT merged commit 15fd026 into scikit-learn:main Mar 12, 2021
@TomDLT
Copy link
Member

TomDLT commented Mar 12, 2021

Thanks @cmarmo !

@cmarmo cmarmo deleted the nmf-reformat branch March 15, 2021 07:59
@glemaitre glemaitre mentioned this pull request Apr 22, 2021
12 tasks
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.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.