Skip to content
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

[ML] Fix data drift calculating inaccurate p value when range is not of uniform distribution #168757

Merged
merged 10 commits into from
Oct 17, 2023

Conversation

qn895
Copy link
Member

@qn895 qn895 commented Oct 12, 2023

Summary

Addresses #168090

KS-Test p-value for pdays on the bank-marketing dataset is very small, although reference and comparison distributions are identical. I guess we have a numerical issue here we need to investigate.

This is actually an edge case. This we because we currently assume uniform distribution - that in every range we will have 5% of the overall data. If this is true, then performing the ks_test aggregation, we don’t need to specify the fractions parameter, since all fractions should be 0.05 by design and this is the default value (uniform distribution).
Now, in the case with pdays an overwhelming amount of values (70% or so) have the value -1. It’s probably a default value for missing data or something like this. Now when we run the percentile aggregation, we get a bunch of [-1,-1] intervals, since aggregation is not able to split the values into distinct 5% intervals. And this breaks our assumption of uniform distributed fractions in the ks_test.

So, to fix this in the general case, we need to run an additional ranges agg to get the doc count for the ranges that we get from the percentiles aggregation. Having the doc counts we can compute fractions explicitly and then pass the values as a list to the ks_test.

This PR adds that additional ranges agg, use the doc_count to compute the fractions, and pass that to the ks_test agg.

After

Screen Shot 2023-10-17 at 12 53 56

image

NOTE: Logging is temporarily added to have more visibility to the ES queries.

In addition, this PR also fixes:

  • Clicking on the comparison chart will no longer generate any additional brushes
  • If either data set is empty, no need to make KS agg tests, default to Drift detected = yes

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@qn895 qn895 added the ci:cloud-deploy Create or update a Cloud deployment label Oct 12, 2023
@qn895 qn895 self-assigned this Oct 13, 2023
@qn895 qn895 requested review from valeriy42 and removed request for valeriy42 October 13, 2023 16:15
@qn895 qn895 marked this pull request as ready for review October 17, 2023 17:27
@qn895 qn895 requested a review from a team as a code owner October 17, 2023 17:27
@@ -359,7 +359,7 @@ export const DataDriftPage: FC<Props> = ({ initialSettings }) => {
label={comparisonIndexPatternLabel}
randomSampler={randomSamplerProd}
reload={forceRefresh}
brushSelectionUpdateHandler={brushSelectionUpdate}
brushSelectionUpdateHandler={undefined}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just omit 'brushSelectionUpdateHandler' completely

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM ⚡

@qn895 qn895 added bug Fixes for quality problems that affect the customer experience :ml release_note:skip Skip the PR/issue when compiling release notes v8.11.0 labels Oct 17, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@kibana-ci
Copy link
Collaborator

kibana-ci commented Oct 17, 2023

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #10 / lens app - group 3 lens inline editing tests should reset changes made to the previous state

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
dataVisualizer 613.8KB 614.3KB +466.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @qn895

@qn895 qn895 enabled auto-merge (squash) October 17, 2023 18:59
@qn895 qn895 merged commit 6d06dc3 into elastic:main Oct 17, 2023
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 17, 2023
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.11

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Oct 17, 2023
…is not of uniform distribution (#168757) (#169168)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[ML] Fix data drift calculating inaccurate p value when range is not
of uniform distribution
(#168757)](#168757)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Quynh Nguyen
(Quinn)","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-10-17T19:34:12Z","message":"[ML]
Fix data drift calculating inaccurate p value when range is not of
uniform distribution
(#168757)","sha":"6d06dc3d2d2fd9440ce474c9f8fdfc45b720fc59","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug",":ml","release_note:skip","ci:cloud-deploy","v8.11.0","v8.12.0"],"number":168757,"url":"https://github.com/elastic/kibana/pull/168757","mergeCommit":{"message":"[ML]
Fix data drift calculating inaccurate p value when range is not of
uniform distribution
(#168757)","sha":"6d06dc3d2d2fd9440ce474c9f8fdfc45b720fc59"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/168757","number":168757,"mergeCommit":{"message":"[ML]
Fix data drift calculating inaccurate p value when range is not of
uniform distribution
(#168757)","sha":"6d06dc3d2d2fd9440ce474c9f8fdfc45b720fc59"}}]}]
BACKPORT-->

Co-authored-by: Quynh Nguyen (Quinn) <[email protected]>
hop-dev pushed a commit to hop-dev/kibana that referenced this pull request Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience ci:cloud-deploy Create or update a Cloud deployment :ml release_note:skip Skip the PR/issue when compiling release notes v8.11.0 v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants