Workspace/Coding labs
Loading progress

Standardize a comparison across case mix

Intermediate50 min

Implement standardized_comparison(baseline,candidate,weights). Baseline and candidate map each stratum to (successes,total). Require the same nonempty keys in all mappings, integer counts excluding booleans, total>0, and 0<=successes<=total. Weights must be finite nonnegative numbers excluding booleans and sum to 1 within 1e-9. Return baseline_observed, candidate_observed, baseline_standardized, candidate_standardized, and standardized_delta. Even zero-weight strata must have valid observations so coverage is explicit.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Inputbaseline={"easy":(90,100),"hard":(2,10)}, candidate={"easy":(19,20),"hard":(30,100)}, weights={"easy":0.5,"hard":0.5}

Outputbaseline_standardized=0.55, candidate_standardized=0.625, standardized_delta=0.075

A common target mix separates within-stratum rates from the observed mix.
solution.pyPython 3.12