05-shadow-deployment compares a candidate model's would-be outputs against the live model's, but never measures its effect on real USER OUTCOMES (does it actually convert more? engage more?). A/B testing is the step that does: split real traffic between the existing model (control) and the new one (treatment), measure a real outcome metric for each group, and use an actual statistical test, not gut feeling, to decide whether an observed difference is real or just noise, and whether to roll back.
Implement assign_variant (deterministic, weighted traffic splitting: generalizing 04-canary-deployment's single-percentage routing to several named variants), evaluate_ab_test (a genuine two-proportion z-test), and decide_rollback.
assign_variant(user_id, variant_names, weights) deterministically assigns the SAME user_id to the SAME variant every time, with the population split roughly proportional to weights.evaluate_ab_test(...) computes the standard two-proportion z-test comparing control vs. treatment conversion rates, returning (z_statistic, p_value): a POSITIVE z_statistic means control outperformed treatment.decide_rollback(z_statistic, p_value, alpha=0.05) returns True ONLY when the result is BOTH statistically significant (p_value < alpha) AND in the wrong direction (treatment underperforming, z_statistic > 0).Open one at a time. Each gives away a little more than the last.
assign_variant reuses 04-canary-deployment's hash-bucketing idea, just generalized: instead of one threshold (canary vs. not), walk through each variant's weight, accumulating a running total, and return the first variant whose cumulative weight exceeds the user's hashed position.
The two-sided p-value is computed directly with Python's math.erfc(abs(z_statistic) / math.sqrt(2.0)), avoiding cancellation error for extremely small p-values without requiring an external statistics library.
No results yet
Run your code to check it against the examples, or submit to run every test.