All problems
Minimum Expected Cost
Problem
Compute the minimum total expected cost over a list of probability predictions. For each p, the expected cost of predicting 0 is p*C[1][0] + (1-p)*C[0][0] and of predicting 1 is p*C[1][1] + (1-p)*C[0][1]; sum the smaller of the two. Empty input returns 0.0.
Hint
The optimal policy picks whichever label minimizes expected cost for each sample independently.
Test cases
case 1
in: [[0.2,0.5,0.8],[[0,1],[1,0]]]
expected: 0.8999999999999999
case 2
in: [[0.2,0.8],[[0,5],[1,0]]]
expected: 1
case 3
in: [[],[[0,1],[1,0]]]
expected: 0
case 4
in: [[0.5],[[1,0],[0,1]]]
expected: 0.5
Starter codePython
def minimum_expected_cost(probs, cost_matrix):
# Your code here
pass4 test cases · run your code against them in the editor