Skip to content
DeepForgeby svx
All problems
HardStatisticsst-316

DML Residual Estimate

Problem

Return the partially linear double machine learning estimate sum(v_i*(y_i - l_i))/sum(v_i^2), where v_i = d_i - m_i are treatment residuals and l_i are outcome-model predictions. Return 0.0 for empty or mismatched input or when all treatment residuals are zero.

Hint

Residualize both the treatment and the outcome before regressing.

Test cases

case 1
in: [[3.1,1,3,0.9],[1,0,1,0],[1,1,1,1],[0.5,0.5,0.5,0.5]]
expected: 2.0999999999999996
case 2
in: [[5,1,5,1],[1,0,1,0],[3,1,3,1],[0.5,0.5,0.5,0.5]]
expected: 2
case 3
in: [[1,2],[1,0],[1,2],[1,0]]
expected: 0
case 4
in: [[],[],[],[]]
expected: 0
case 5
in: [[1,2],[1,0],[1],[1,0]]
expected: 0
Starter codePython
def dml_residual_estimate(outcome, treatment, outcome_model, treatment_model):
    # Your code here
    pass

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