All problems
Optimal Ensemble Weight
Problem
Compute the minimum-variance ensemble weight for model A: w = (var_b - cov) / (var_a + var_b - 2 * cov) using population statistics, clamped to [0, 1]. Return 0.5 when there are fewer than two paired errors, lengths differ, or the denominator is 0.
Hint
The variance-minimizing weight leans on the more stable model and on whichever error is less correlated.
Test cases
case 1
in: [[0,0,0,0],[1,2,3,4]]
expected: 1
case 2
in: [[1,2,3,4],[2,3,4,5]]
expected: 0.5
case 3
in: [[3,1,4,1,5,9],[2,7,1,8,2,8]]
expected: 0.5520661157024793
case 4
in: [[1],[2]]
expected: 0.5
case 5
in: [[],[]]
expected: 0.5
Starter codePython
def optimal_ensemble_weight(errors_a, errors_b):
# Your code here
pass5 test cases · run your code against them in the editor