All problems
CUPED Variance Reduction
Problem
Apply CUPED variance reduction. With theta = cov(x, y) / var(x), adjust y_i to y_i - theta * (x_i - mean_x).
Return [adjusted_mean, variance_reduction] where variance_reduction = 1 - var(adjusted)/var(y). If var(x) or var(y) is 0, return [mean_y, 0.0].
Hint
A pre-experiment covariate correlated with the metric lets you explain away variance.
Test cases
case 1
in: [[1,2,3,4],[1,2,3,4]]
expected: [2.5,1]
case 2
in: [[1,2,3,4],[0,0,0,0]]
expected: [2.5,0]
case 3
in: [[2,4,6,8],[1,3,5,7]]
expected: [5,1]
case 4
in: [[1,3,2,4],[2,1,4,3]]
expected: [2.5,0]
Starter codePython
def cuped_variance_reduction(y, x):
# Returns [adjusted_mean, variance_reduction]
# Your code here
pass4 test cases · run your code against them in the editor