Uncertainty and online experiments
Uncertainty tempers the estimate; randomization tests the cause; guardrails protect the product.
An ETA model improves RMSE while increasing missed-delivery cost.
This chapter moves from name the unit of variation to read effect and harm together. We will make the idea concrete in a small code example before placing it back inside a production system with a declared latency, cost, and operator-capacity budget.
Report the treatment difference with uncertainty and confirm every safety metric before ramping traffic.
Verify the behavior illustrated in experiment_interval.py, then measure decision utility, slice reliability, and system latency.
ROC-AUC alone on 0.1% prevalence hides unusable precision and an impossible review queue. An unsafe release must degrade to a named baseline or the last known-good version.
Build the idea one layer at a time.
A measured improvement is an estimate, not a fact carved into the dashboard. Decisions need both its plausible range and evidence that deployment caused it.
Offline uncertainty reveals how sensitive a result is to sampled rows, time periods, and training seeds. Confidence intervals do not guarantee truth, but they prevent a noisy tenth of a point from being presented with the certainty of a ten-point gain.
A randomized online experiment estimates causal product impact under live behavior. It still needs guardrails: a treatment that raises conversion while sharply increasing latency or complaints is not an automatic win.
- PR curves
- calibration
- experiment guardrails
Follow the reasoning before touching the code.
- 01
Name the unit of variation
Resample or randomize at the independent unit—often user, merchant, or time block—not at correlated event rows.
- 02
Predeclare the experiment
Fix eligibility, randomization unit, primary metric, duration, minimum effect, guardrails, and stop rules before reading results.
- 03
Read effect and harm together
Report the treatment difference with uncertainty and confirm every safety metric before ramping traffic.
from math import sqrt
from statistics import mean, variance
control = [0, 1, 0, 1, 0, 0, 1, 0]
treatment = [1, 1, 0, 1, 0, 1, 1, 0]
effect = mean(treatment) - mean(control)
se = sqrt(variance(control) / len(control) + variance(treatment) / len(treatment))
interval = (effect - 1.96 * se, effect + 1.96 * se)
latency_control_ms = 82
latency_treatment_ms = 109
guardrail_ok = latency_treatment_ms <= latency_control_ms + 15
print("effect", round(effect, 3), "95% interval", tuple(round(x, 3) for x in interval))
print("latency guardrail", guardrail_ok)Compute a simple difference-in-means interval and a latency guardrail.
What to notice
- The tiny sample produces a wide interval, so the positive point estimate alone is weak launch evidence.
- The latency increase violates the declared 15 ms guardrail even before statistical significance is debated.
YOUR TURN Pause and predict before revealing the answer.
Why would randomizing individual page views be unsafe if the treatment changes a user’s learned behavior?
Need a hint?
One user would carry treatment effects between nominally separate observations.
Check your reasoning
Page views are not independent and the same user can be contaminated across variants; randomize persistently by user instead.
Lessons 1, 2, 3, 4 in this course.
Connect the chapter to the course’s quantitative spine.
Uncertainty tempers the estimate; randomization tests the cause; guardrails protect the product. The cost-aware threshold selection below is the shared course-level lens that helps quantify the surrounding system. Name each symbol, check its units or shape, and use only values that were available at the production cutoff.
Cost-aware threshold selection
| Symbol | Meaning / shape / unit |
|---|---|
t | decision threshold |
FN, FP | error counts at t |
c_FN, c_FP | business cost per error |
Open derivation and numerical substitution
Start from the production quantity being optimized, substitute the observed values with their declared units, then isolate the model-controlled term. Preserve shape annotations at each step so broadcasting or aggregation cannot silently change the result.
- Write the named inputs: t, FN, FP, c_FN, c_FP.
- Substitute one small, hand-checkable batch before vectorizing.
- Calculate an independent reference value and compare within a declared tolerance.
# equation → code contract
inputs = validate_shapes_and_units(batch)
value = compute_c02(inputs)
assert is_finite(value)Change one assumption and make the tradeoff visible.
Use the worked chapter as your prediction, then change one input in the lab and explain why the output moves. The lab runs predefined TypeScript and never executes learner code, so the focus stays on the concept rather than setup.
Cost-aware threshold
Move the cutoff over a fixed set of scored transactions.
Assumption: Fixed 12-event dataset; false positive costs 2 units and false negative costs 12.
Open nonvisual data table
| Item | Computed state | Interpretation |
|---|---|---|
| 0.92 | fraud | review |
| 0.84 | fraud | review |
| 0.76 | legit | review |
| 0.68 | fraud | review |
| 0.59 | legit | review |
| 0.51 | fraud | review |
| 0.43 | legit | pass |
| 0.37 | legit | pass |
| 0.31 | fraud | pass |
| 0.22 | legit | pass |
| 0.14 | legit | pass |
| 0.08 | legit | pass |
Trace the complete operating path.
Carry the chapter’s central idea into the system: Uncertainty tempers the estimate; randomization tests the cause; guardrails protect the product. The path below shows where that reasoning needs an artifact, a test, an owner, or a fallback.
- 01
Turn “Name the unit of variation” into a written invariant and a failing test.
- 02
Promote experiment_interval.py from illustration to a versioned implementation with representative fixtures.
- 03
Use “Read effect and harm together” as the release checkpoint: Report the treatment difference with uncertainty and confirm every safety metric before ramping traffic.
- 04
Serve or materialize behind explicit a declared latency, cost, and operator-capacity budget.
- 05
Join telemetry to mature outcomes and retain a rollback path.
Observability
Join service health, input quality, prediction distributions, slice behavior, and mature outcomes by exact version.
Cost
Measure storage, preprocessing, compute, queueing, and human review under a representative arrival pattern.
Failure modes
ROC-AUC alone on 0.1% prevalence hides unusable precision and an impossible review queue. Add a detector, owner, mitigation, and stop condition for this class of failure.
Alternatives
Compare a rule, a simpler statistical baseline, and a different system boundary before adding model complexity.
Explain the contract, not just the vocabulary.
Late-delivery evaluation contract
Specify a cutoff-safe target, validation design, cost/capacity threshold, calibration report, uncertainty, and controlled experiment.
- Decision and metric contract
- Leakage-safe split tests
- Threshold and calibration analysis
- A/B guardrails and rollback
Read primary material with a purpose.
Return to the opening failure.
Store the decision contract, cutoff, split logic, threshold policy, uncertainty, and experiment design beside the model.
For this lesson, the release evidence is the worked code example, a hand-checked formal result, deterministic simulation output, a ≥80% checkpoint, the production rubric, and a named fallback. The course resolves when the system can produce a metric contract, leakage-safe validation, calibration analysis, and experiment plan.