All problems
Counterfactual Prediction Residual
Problem
Compute the residual between the observed outcome and the counterfactual prediction under the observed treatment: y_obs - (y1_pred if treatment == 1 else y0_pred).
Hint
Only the potential outcome matching the treatment actually received is observed.
Test cases
case 1
in: [5,3,6,1]
expected: -1
case 2
in: [2,3,6,0]
expected: -1
case 3
in: [4,4,7,1]
expected: -3
case 4
in: [0,0,0,0]
expected: 0
Starter codePython
def counterfactual_residual(y_obs, y0_pred, y1_pred, treatment):
# Your code here
pass4 test cases · run your code against them in the editor