Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-307

Synthetic Control Loss

Problem

Return the synthetic control pre-period loss: sum over periods of (target_t - sum_i weights_i*donors_i_t)^2. Return 0.0 for empty input, a length mismatch between donors and weights, or donor series of the wrong length.

Hint

The weights should make the donor average track the target.

Test cases

case 1
in: [[1,2,3],[[1,2,3],[0,0,0]],[0.5,0.5]]
expected: 3.5
case 2
in: [[1,2],[[1,2]],[1]]
expected: 0
case 3
in: [[1,2],[[3,4]],[1]]
expected: 8
case 4
in: [[],[],[]]
expected: 0
case 5
in: [[1,2],[[1,2],[3,4]],[0.5]]
expected: 0
Starter codePython
def synthetic_control_loss(target, donors, weights):
    # Your code here
    pass

5 test cases · run your code against them in the editor