Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-238

Cost Matrix Prediction

Problem

Predict the class with the lowest expected cost. cost_matrix[true][pred]; for probability p of class 1, compare p*C[1][0] + (1-p)*C[0][0] against p*C[1][1] + (1-p)*C[0][1].

Return 1 when predicting 1 is no more costly, else 0; empty input returns [].

Hint

Asymmetric misclassification costs shift the effective decision threshold away from 0.5.

Test cases

case 1
in: [[0.2,0.5,0.8],[[0,1],[1,0]]]
expected: [0,1,1]
case 2
in: [[0.2,0.8,0.9],[[0,5],[1,0]]]
expected: [0,0,1]
case 3
in: [[0.5],[[0,2],[4,0]]]
expected: [1]
case 4
in: [[],[[0,1],[1,0]]]
expected: []
Starter codePython
def cost_matrix_predict(probs, cost_matrix):
    # Your code here
    pass

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