10000 ENH Sets assume_finite in _non_negative_factorization by thomasjpfan · Pull Request #18581 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

ENH Sets assume_finite in _non_negative_factorization #18581

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 6 commits into from
Nov 30, 2020

Conversation

thomasjpfan
Copy link
Member

Reference Issues/PRs

Continues #18557

CC @ogrisel @NicolasHug

Copy link
Member
@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

I think I'd be +0 to introduce this parameter. IMHO a cleaner way would be for the function to call the estimator, not the other way around.

Some related discussion in #14897

@NicolasHug
Copy link
Member

(As a side note, the notion of "private parameters" has been in the back of my mind for a while. Basically a parameter that we use internally but that we don't expose to users. I'm not sure what it should look like, but I feel like this could be very useful to us. )

@thomasjpfan
Copy link
Member Author

I have been thinking of doing stuff like:

def non_negative_factorization(_check_input=False)

where we use the underscore as a convention. The other option would be to have a private method:

def non_negative_factorization(...):
	X = check_array(X, ...)
	_non_negative_factorization(X, ...)

class NMF:
	def fit_transform(self, ...):
		X = self._valdiate_data(X, ...)
		... = _non_negative_factorization(X, ...)

where _non_negative_factorization does not check the input.

IMHO a cleaner way would be for the function to call the estimator, not the other way around.

In this case NMF.fit_transform() calls _beta_divergence, which would add more computation to the non_negative_factorization function call.

@NicolasHug
Copy link
Member

Hm OK, I feel like having a private _non_negative_factorization is safer than introducing a new parameter. We can have _non_negative_factorization do no validation, or introduce the new parameter there.

I have been thinking of doing stuff like def non_negative_factorization(_check_input=False)

Yeah, leading underscore + some sphinx magic so that these parameters docs aren't rendered might be a way. Pretty unconventional though :p

@TomDLT
Copy link
10000 Member
TomDLT commented Oct 15, 2020

I understand the reluctance to introduce new parameters for internal stuff, but check_input is already used here and there, and seems like a simpler option to me.

@thomasjpfan thomasjpfan changed the title ENH Adds check_input to non_negative_factorization ENH Adds private method _non_negative_factorization to above checking input Oct 15, 2020
@amueller
Copy link
Member

I like the decorator approach used in #18727. That only concerns the finiteness check, though, and I wonder if any of the other checks are expensive. If so, we could add another global config or rename this one?

@TomDLT
Copy link
Member
TomDLT commented Nov 20, 2020

I like it too !
It might be sufficient. The finiteness check is the longest since it goes through all the data (O(n)), while all the rest is O(1) if there is no change of type/dtype/copy.

@amueller
Copy link
Member

That was my feeling as well, though checking is always good ;)

@thomasjpfan
Copy link
Member Author

Updated to use a context manager.

Co-authored-by: Tom Dupré la Tour <tom.dupre-la-tour@m4x.org>
thomasjpfan changed the title ENH Adds private method _non_negative_factorization to above checking input ENH Sets assume_finite in _non_negative_factorization Nov 30, 2020
@ogrisel
Copy link
Member
ogrisel commented Nov 30, 2020

Two CI jobs failed when doing the git checkout. I triggered them again.

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 as well. Let's wait for the CI to be green.

@ogrisel ogrisel merged commit fa5f1d5 into scikit-learn:master Nov 30, 2020
@ogrisel
Copy link
Member
ogrisel commented Nov 30, 2020

Merged!

cmarmo added a commit to cmarmo/scikit-learn that referenced this pull request Dec 29, 2020
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
0