sense_drift: surface threshold_method (n_permutations re-thresholds, not just add a p-value)#1
Merged
Conversation
…not just add a p-value)
Passing n_permutations switches the flag threshold from the in-sample
control chart to a null-calibrated percentile, which can flag a different
set of periods and therefore change change_type/drift_terms — previously
this was silent. Add SenseDriftResult.threshold_method ('control_chart' |
'permutation_null'), document the behavior on sense_drift and the result
class, and add regression tests. No change to the detection math; the
switch is deterministic (not RNG non-determinism).
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
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.
What
Adds
SenseDriftResult.threshold_method("control_chart"|"permutation_null") so the result records which thresholding regime produced the flags.Why
Passing
n_permutations > 0does more than attach a p-value: it switches the flag threshold from the in-sample control chart (μ + kσ) to a null-calibrated percentile of the label-shuffle distribution. Those two thresholds differ, so the same data can yield a different set of flagged periods — and therefore a differentchange_type/drift_terms. Previously this regime switch was silent; a caller comparing a canonical run to a permutation run had no programmatic way to see that the thresholding method itself had changed.Changes
SenseDriftResult.threshold_method: str— new field recording the regime.sense_driftandSenseDriftResultnow state thatn_permutationsswitches the thresholding method, not just the p-value.test_threshold_method_is_surfaced— the label is set correctly in each regime.test_permutation_switches_threshold_not_just_pvalue— the two regimes use different thresholds.test_permutation_mode_is_deterministic— both regimes reproduce run-to-run under a fixedrandom_state.Not changed
No change to the detection math. The regime switch is deterministic (not RNG non-determinism). Backward compatible — additive field only.
pytest tests/unit/test_semantic_drift.py→ 24 passed.