Composite OEC Score per Variant, Normalized to Control

Quick Overview

Write a pandas function that gives each experiment variant a weighted composite score, with every metric normalized by the control group's value. It tests vectorized DataFrame work, deterministic summation, an exact output contract, and judgment about zero baselines and confidence intervals for the score.

Composite OEC Score per Variant, Normalized to Control

Role: Data Scientist

Category: Analytics & Experimentation

Difficulty: medium

Interview Round: Other

Implement `oec_composite_score(df, weights)` in `solution.py`. `df` has one row per variant: a `variant` column (object dtype, always including `'control'`) plus `float64` metric columns. `weights` maps a subset of the metric columns to float weights. For each variant $v$, the overall evaluation criterion (OEC) is $$ \text{OEC}_v = \sum_{m} w_m \cdot \frac{x_{v,m}}{x_{\text{control},m}} $$ where the sum runs over the metrics $m$ named in `weights`, $w_m$ is that metric's weight and $x_{v,m}$ is variant $v$'s value for it. Requirements: - Normalize each metric by the `'control'` row's value for that metric. - Use only the metrics named in `weights` and ignore every other column. - Iterate the metrics in sorted key order so the floating-point summation is deterministic. - Return a `pd.Series` indexed by variant (sorted ascending, index name `'variant'`), with `float64` values and name `'oec'`. Example: ```python df = pd.DataFrame({ 'variant': ['control', 'B'], 'metric_a': [100.0, 110.0], 'metric_b': [4.0, 3.0], }) weights = {'metric_a': 0.7, 'metric_b': 0.3} oec_composite_score(df, weights) # variant # B 0.995 # 0.7*(110/100) + 0.3*(3/4) = 0.77 + 0.225 # control 1.000 # equals sum(weights.values()) # Name: oec, dtype: float64 ``` ```hint Normalize whole columns Pull the control row out once as a Series keyed by metric name, then divide each weighted column by its baseline in one vectorized step. ``` ```hint Index alignment A boolean filter such as `df[df['variant'] == 'control']` keeps the original row label, and pandas aligns on labels when you divide. Make sure each baseline you divide by is a scalar. ``` ### Constraints & Assumptions - Exactly one row has `variant == 'control'`, and its value is non-zero for every metric in `weights`. - Each variant appears in exactly one row. - Every key in `weights` is a `float64` metric column of `df`. `df` may hold other metric columns, and they must not affect the score. ### What a Strong Answer Covers - Extracts the control baseline once and normalizes each weighted metric by its own control value with vectorized column arithmetic. - Sums only the metrics in `weights`, adding them in sorted key order. - Meets the output contract exactly: ascending index named `'variant'`, `float64` values, Series name `'oec'`. - Checks the result against an invariant, such as the control row scoring `sum(weights.values())`. - Names the failure cases (a zero baseline, a weight key missing from `df`, empty `weights`) and says how the function should behave in each. ### Follow-up Questions - How would you handle a `control_value` of zero for a weighted metric? - How would you attach confidence intervals to the OEC for each variant? - What goes wrong if you sum the weighted raw metric values without dividing by control?

Overview: Write a pandas function that gives each experiment variant a weighted composite score, with every metric normalized by the control group's value. It tests vectorized DataFrame work, deterministic summation, an exact output contract, and judgment about zero baselines and confidence intervals for the score.

General logo
General
Nov 25, 2026
mediumData ScientistOtherAnalytics & Experimentation
0
0

Implement oec_composite_score(df, weights) in solution.py. df has one row per variant: a variant column (object dtype, always including 'control') plus float64 metric columns. weights maps a subset of the metric columns to float weights. For each variant vv, the overall evaluation criterion (OEC) is

OECv=∑mwm⋅xv,mxcontrol,m\text{OEC}_v = \sum_{m} w_m \cdot \frac{x_{v,m}}{x_{\text{control},m}}

where the sum runs over the metrics mm named in weights, wmw_m is that metric's weight and xv,mx_{v,m} is variant vv's value for it.

Requirements:

  • Normalize each metric by the 'control' row's value for that metric.
  • Use only the metrics named in weights and ignore every other column.
  • Iterate the metrics in sorted key order so the floating-point summation is deterministic.
  • Return a pd.Series indexed by variant (sorted ascending, index name 'variant' ), with float64 values and name 'oec' .

Example:

df = pd.DataFrame({
    'variant':  ['control', 'B'],
    'metric_a': [100.0, 110.0],
    'metric_b': [4.0,   3.0],
})
weights = {'metric_a': 0.7, 'metric_b': 0.3}

oec_composite_score(df, weights)
# variant
# B          0.995   # 0.7*(110/100) + 0.3*(3/4) = 0.77 + 0.225
# control    1.000   # equals sum(weights.values())
# Name: oec, dtype: float64

Constraints & Assumptions

  • Exactly one row has variant == 'control' , and its value is non-zero for every metric in weights .
  • Each variant appears in exactly one row.
  • Every key in weights is a float64 metric column of df . df may hold other metric columns, and they must not affect the score.

What a Strong Answer Covers Guidance

  • Extracts the control baseline once and normalizes each weighted metric by its own control value with vectorized column arithmetic.
  • Sums only the metrics in weights , adding them in sorted key order.
  • Meets the output contract exactly: ascending index named 'variant' , float64 values, Series name 'oec' .
  • Checks the result against an invariant, such as the control row scoring sum(weights.values()) .
  • Names the failure cases (a zero baseline, a weight key missing from df , empty weights ) and says how the function should behave in each.

Follow-up Questions Guidance

  • How would you handle a control_value of zero for a weighted metric?
  • How would you attach confidence intervals to the OEC for each variant?
  • What goes wrong if you sum the weighted raw metric values without dividing by control?