-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
FIX RuntimeWarning by dividing by zero in test_iforest_with_uniform_data #19622
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 by dividing by zero in test_iforest_with_uniform_data #19622
Conversation
@LSturtew Thanks for opening this PR. I’m very glad that you found an issue to work on. Does the RuntimeWarning stem from fit or predict? |
It stems from predict. |
I'd prefer to fix the cause of the runtime warning instead of removing the tests. |
@lorentzenchr I have updated the score calculations to fix the runtime warning. |
sklearn/ensemble/_iforest.py
Outdated
-np.divide(depths, denominator, np.ones_like(depths), | ||
where=denominator != 0) |
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.
-np.divide(depths, denominator, np.ones_like(depths), | |
where=denominator != 0) | |
# For a single training sample, denominator and depth are 0. | |
# Therefore, we set the score manually to 1. | |
-np.divide(depths, denominator, out=np.ones_like(depths), | |
where=denominator != 0) |
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.
Please use the keyword argument explicitly, i.e. out=np.ones_like(...)
.
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 @LSturtew !
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 too. @LSturtew Thank you.
Reference Issues/PRs
#19334
What does this implement/fix? Explain your changes.
The runtime error was in the test on a single row of data. The zero division error was due to the fact that the average path length between points was 0. It does not make sense to me to use the isolation forest algorithm on 1d data.
Any other comments?