Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(signals): shrink the current anomaly rate toward the smoothed baseline (#123192)

posthog[bot]175f47540c08
diff --git a/products/signals/backend/anomaly_scores/read.py b/products/signals/backend/anomaly_scores/read.py
index 108add2041ce..3e87ea1fed94 100644
--- a/products/signals/backend/anomaly_scores/read.py
+++ b/products/signals/backend/anomaly_scores/read.py
@@ -425,12 +425,14 @@ def prior_rate(series: Sequence[SeriesSummary]) -> float:
def rate_lift(summary: SeriesSummary, prior: float) -> float:
- """The smoothed rate in the range less the smoothed baseline rate. Only a ranking uses it."""
- baseline = summary.baseline_rate if summary.baseline_rate is not None else prior
- rate = (summary.flagged_buckets + PRIOR_BUCKETS * baseline) / (summary.scored_buckets + PRIOR_BUCKETS)
+ """The smoothed rate in the range less the smoothed baseline rate. Only a ranking uses it.
+
+ Both rates shrink toward the same smoothed baseline, so a series with no scored bucket gets a lift of 0.
+ """
smoothed_baseline = (summary.baseline_flagged_buckets + PRIOR_BUCKETS * prior) / (
summary.baseline_scored_buckets + PRIOR_BUCKETS
)
+ rate = (summary.flagged_buckets + PRIOR_BUCKETS * smoothed_baseline) / (summary.scored_buckets + PRIOR_BUCKETS)
return rate - smoothed_baseline
diff --git a/products/signals/backend/test/test_anomaly_search.py b/products/signals/backend/test/test_anomaly_search.py
index 42e688442ccf..f5212872b82f 100644
--- a/products/signals/backend/test/test_anomaly_search.py
+++ b/products/signals/backend/test/test_anomaly_search.py
@@ -60,6 +60,11 @@ class TestAnomalyRanking(SimpleTestCase):
_summary("quiet_before", scored=10, flagged=3, baseline_scored=30, baseline_flagged=0),
_summary("noisy_before", scored=10, flagged=3, baseline_scored=30, baseline_flagged=10),
),
+ (
+ "real_jump_beats_unchanged_noisy",
+ _summary("jumped", scored=10, flagged=3, baseline_scored=30, baseline_flagged=0),
+ _summary("unchanged", scored=10, flagged=5, baseline_scored=10, baseline_flagged=5),
+ ),
]
)
def test_ranks_series_by_comparable_rates(