-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fixing KDE evaluate() to return correct ValueAndMagnitude object #128602
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
Open
Jason-Whitmore
wants to merge
3
commits into
elastic:main
Choose a base branch
from
Jason-Whitmore:issue_127517
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
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
…ct for bandwidth = 0 Prior to this change, the evaluate method would return a dummy object for an input with bandwidth = 0. This would occur if the dataset had zero variance (see KDE constructor). This would then cause ChangePointDetector to fail to detect a spike on a dataset containing all equal numbers except for one spike. This change removes the bandwidth = 0 condition for returning a dummy ValueAndMagnitude object. Statistical testing in ChangePointDetector now properly detects the spike in the example mentioned above. Unit tests are added to confirm the bug is fixed.
Pinging @elastic/ml-core (Team:ML) |
@elasticmachine test this please |
Thanks for your contribution @Jason-Whitmore and thanks for adding the tests, we will try to review this as soon as possible |
@elasticmachine test this please |
tveasey
reviewed
Oct 9, 2025
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.
I propose a small tweak.
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/changepoint/KDE.java
Show resolved
Hide resolved
This change enables an early return and avoids numerical issues.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
>bug
external-contributor
Pull request authored by a developer outside the Elasticsearch team
:ml
Machine learning
Team:ML
Meta label for the ML team
v9.3.0
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.
Issue #127517 describes
ChangePointDetector.getChangeType()
failing to detect a spike when all non spike values are constant (for example, the input [51,51,...,51,50001,51...,51]).Prior to this change, the
KDE.evaluate()
method would return a special object for an input withbandwidth == 0
. This would occur if the values excluding the spike had zero variance (seeKDE
constructor). This would then causeChangePointDetector.getChangeType()
andSpikeAndDipDetector.detect()
to use the wrong p-value and fail to detect the spike.This change removes the
bandwidth == 0
condition for returning a specialValueAndMagnitude
object. Statistical testing inChangePointDetector.getChangeType()
andSpikeAndDipDetector.detect()
now properly detect the spike in the example mentioned above.Unit tests are added to confirm the bug is fixed.
Closes #127517