All problems
Covariate Shift Weights
Problem
Compute covariate shift importance weights for training samples: (n_train/n_test) * p / (1 - p), where p is the adversarial probability of belonging to the test set, clipping p to [1e-12, 1 - 1e-12].
Return zeros if n_test is 0; empty input returns [].
Hint
Samples that look like the test set get larger training weight.
Test cases
case 1
in: [[0.5,0.8],100,50]
expected: [2,8.000000000000002]
case 2
in: [[0.2],200,100]
expected: [0.5]
case 3
in: [[0.5],10,5]
expected: [2]
case 4
in: [[],10,5]
expected: []
Starter codePython
def covariate_shift_weights(probs, n_train, n_test):
# Your code here
pass4 test cases · run your code against them in the editor