-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
FIX RuntimeWarning division by zero in check_classifiers_one_label #19690
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
FIX RuntimeWarning division by zero in check_classifiers_one_label #19690
Conversation
….com/mbatoul/scikit-learn into fix_test_check_classifiers_one_label
With only 1 class, scikit-learn/sklearn/discriminant_analysis.py Line 479 in 302106b
Maybe we can do something like if self._max_components == 0:
self.explained_variance_ratio = np.empty((0,), dtype=S.dtype)
else:
self.explained_variance_ratio = ... |
Thank you for your help, @jeremiedbb! It makes total sense, I missed that I will work on it tonight. |
…n max components is zero
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. Thanks @mbatoul !
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. @mbatoul Thank you.
Reference Issues/PRs
See issue #19334.
What does this implement/fix? Explain your changes.
The warning stems from the LDA's fit method. There is a division by zero in the
LinearDiscriminantAnalysis#_solve_svd
method, when computing the explained variance ratio:self.explained_variance_ratio_ = (S**2 / np.sum(S**2))[:self._max_components]
. Here,S
is zero because it's the singular values vector of the zero matrixX
given byX = np.dot(((np.sqrt((n_samples * self.priors_) * fac)) * (self.means_ - self.xbar_).T).T, scalings)
. Here, we haveself.means_ == self.xbar_
because we are testing the LDA classifier with only one class (seey = np.ones(10)
).Any other comments?
I am still trying to figure out the right way to solve this problem.