-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG before #12069] KernelPCA: raise Errors and Warnings according to eigenvalue decomposition numerical/conditioning issues #12145
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
[MRG before #12069] KernelPCA: raise Errors and Warnings according to eigenvalue decomposition numerical/conditioning issues #12145
Conversation
- Added a few comments to clarify `_fit_transform`, `fit_transform` and `transform`. - Uniformized the numpy coding style for `fit` and `fit_transform`.
…rnel conditioning. Fixes scikit-learn#12140
Needs review: the only failing check is coverage. To improve it we would need to produce tests where the kernel matrix has artificial defects. Would it be ok ? How to check that warnings are properly raised ? |
… It is used in `KernelPCA`. Added corresponding test `test_errors_and_warnings` for KernelPCA.
While waiting for the review I proposed a way to fix the coverage and improve maintainability: the method to check the kernel eigenvalues ( In addition I created a test for kPCA to check that warnings and errors are raised correctly in case of bad conditioning. |
…ange failure in Travis.
…ed ('randomized' is not available in this branch !)
…o always check the inner check_kernel_eigenvalues method before the kPCA fit.
…aced during call to fit() - we now execute the test directly on `_fit_transform` instead, so that the matrix is untouched.
… this time :) ).
…e still errors of this kind.
…s where there is no zero division, to avoid numpy warnings.
…o zero division numpy warning.
…ture to perform fine-grain warning assertion
# Conflicts: # sklearn/decomposition/tests/test_kernel_pca.py
I had some afterthoughts on one of the warnings: indeed it is normal to find quasi-zero eigenvalues when the number of samples is high enough (my intuition would be, in the case of a gaussian kernel, that it is when this number is larger than the underlying distribution's manifold dimensionality, but maybe in this paper there are better explanations). For this reason I will push a new commit where there is no warning by default about zero eigenvalues. |
…all: this is most probably a common case especially when the number of samples gets high. Removing the warning by default.
…more, this is normal behaviour as the number of samples increases.
All set ! Ready to merge once #12143 will have been. |
@adrinjalali are you ok with:
We are clearly over engineering this PR by trying too hard to future-proof it. Let's keep things simple. |
…g` is now `False` by default
a precision concerning your last sentences @NicolasHug "one parameter to control all the warnings" and "I would be ok to remove all the warnings": please have a look at my previous comments, there is a huge difference between the warning for significant negative values (which could even be transformed into a |
I'm happy with a significant negative value to be a |
Also, @smarie I really appreciate your persistence and you following the suggestions so promptly. I'm sorry it's being dragged for longer than we all would prefer :) |
Perfect. I make the changes right now and push what should finally be the final proposal. Almost there :) ! |
* Renamed `small_nonzeros_warning` into `enable_warnings`. * now consistent warnings are raised for all three cases (imaginary parts, negative, small non zero), and the parameter disables all of them. * improved string formatting using `%g` instead of `%f` or other things
Ready for a last round. That "simple" last change was actually quite impactant but I think that the result is now straightforward and consistent. I updated the docstring, please have a look. In details:
|
…th the others. Now adopting the same message everywhere.
…ot copied back. Added it.
…y parts are all zeros, to convert to float dtype
…messages explicitly state what is happening (setting to zero the imag/negative/small value).
All seems ok now, stopping edits and waiting for final review @adrinjalali @NicolasHug . |
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 @smarie, only nitpicks from me but LGTM
Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>
Thanks very much for the review. @adrinjalali you're up next (if you have a few minutes to devote to this) :) |
ping @adrinjalali |
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 a lot @smarie and @NicolasHug
Merged! |
Yay!!
|
So cool ! I will now be able to finalize #12069 |
…r faster partial decompositions, like in PCA (#12069) Co-authored-by: Sylvain MARIE <sylvain.marie@se.com> Co-authored-by: Thomas J Fan <thomasjpfan@gmail.com> Co-authored-by: Nicolas Hug <contact@nicolas-hug.com> Co-authored-by: Joel Nothman <joel.nothman@gmail.com> Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org> Co-authored-by: Olivier Grisel <olivier.grisel@gmail.com> Co-authored-by: Tom Dupré la Tour <tom.dupre-la-tour@m4x.org>
This PR fixes #12140 by performing some numerical and conditioning checks on the eigenvalues found from kernel decomposition.
This PR is dependent on #12143, that solves an issue happening in
transform
when zero eigenvalues are present in the kernel.