-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG] Normalize linear_model decision_function scores. #19142
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
NicolasHug
merged 6 commits into
scikit-learn:master
from
stootoon:linear_model_decision_function
Jan 13, 2021
Merged
[MRG] Normalize linear_model decision_function scores. #19142
NicolasHug
merged 6 commits into
scikit-learn:master
from
stootoon:linear_model_decision_function
Jan 13, 2021
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thanks @stootoon! Some lint errors need to be fixed.
|
Thanks for the PR @stootoon , but we can't change the output of |
agramfort
approved these changes
Jan 12, 2021
NicolasHug
approved these changes
Jan 13, 2021
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!
glemaitre
pushed a commit
to glemaitre/scikit-learn
that referenced
this pull request
Jan 18, 2021
jeremiedbb
pushed a commit
that referenced
this pull request
Jan 19, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Fixes #19139.
What does this implement/fix? Explain your changes.
According to the docs, the decision_function scores in LinearClassifierMixin are supposed to be the distances of samples to corresponding hyperplanes. (I assume) the hyperplanes are defined by the coefficients and intercepts arrays. The scores are computed as the scalar product of each sample with each of the coefficients, plus the intercepts. The problem is that without normalizing these scores by the norm of their corresponding coefficients, the scores won't actually be the signed distances to the corresponding hyperplanes. This is because the signed distance of a point p to a hyperplane defined by c'x + b = 0 is (c'p + b)/|c|, not the (c'p + b) currently computed.
I fix this problem by normalizing the scores by the norm of their corresponding coefficients.
Any other comments?
I ran pytest on linear_model and a few of the tests are failing, some because computed accuracies are being compared to hard-coded values. This may be expected if the hard-coded values reflect desired outputs using the previous, potentially incorrect, method of computing the scores.
Also, I haven't done any checking for division by zero which would occur if any of the coefficients are all zeros, because I wasn't sure what sklearn best practices are for doing so, and it will be easy enough for whoever does know to add this. Some tests are failing because NaNs are appearing, presumably due to such division by zero.