-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
DOC Clarify how initial conditions are chosen for NMF. #17369
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
Conversation
When update_H is False, any given initial value of W is silently ignored, as are all of the initialization procedures. This commit fixes that by clarifying this in the non_negative_factorization function docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR @bsmith89 !
sklearn/decomposition/_nmf.py
Outdated
- 'custom': use custom matrices W and H | ||
|
||
Ignored if update_H is False, in which case the initial value of W | ||
is set automatically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be disp 8000 layed to describe this comment to others. Learn more.
This may be clearer:
- 'custom': use custom matrices W and H if `update_H=True`. If `update_H=False`, then
only custom matrix H is used.
The init=='custom'
and update_H=False
will down the following code path:
scikit-learn/sklearn/decomposition/_nmf.py
Lines 1040 to 1050 in f27adc5
elif not update_H: | |
_check_init(H, (n_components, n_features), "NMF (input H)") | |
if H.dtype != X.dtype: | |
raise TypeError("H should have the same dtype as X. Got H.dtype = " | |
"{}.".format(H.dtype)) | |
# 'mu' solver should not be initialized by zeros | |
if solver == 'mu': | |
avg = np.sqrt(X.mean() / n_components) | |
W = np.full((n_samples, n_components), avg, dtype=X.dtype) | |
else: | |
W = np.zeros((n_samples, n_components), dtype=X.dtype) |
Revised as suggested by @thomasjpfan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @bsmith89
Reference Issues/PRs
None yet. I can submit an issue if that's important.
What does this implement/fix? Explain your changes.
For
sklearn.decomposition.non_negative_factorization
, when update_H is False, any given initial value of W is silently ignored, as are all of the initialization procedures.See: sklearn/decomposition/_nmf.py#L1032-L1053
This commit fixes that by clarifying this in the non_negative_factorization function docstring.
Any other comments?
Nope. Simple problem, simple fix.