Choosing the most probable class is only optimal when every mistake costs the same. If wrongly clearing a fraudulent payment is far worse than wrongly flagging a good one, the best decision is the one with the smallest expected cost, which can differ from the most probable class.
Implement minimum_risk_class(posteriors, cost_matrix). For each possible prediction, compute its expected cost under the posterior, and return the prediction with the lowest cost.
posteriors is a one-dimensional array of class probabilities summing to 1.cost_matrix[i][j] is the cost of predicting class j when the true class is i; it is square.int. On ties, return the smallest class index.Open one at a time. Each gives away a little more than the last.
The expected cost of predicting j is sum_i posteriors[i] * cost_matrix[i][j].
That is a vector-matrix product: posteriors @ cost_matrix gives every prediction's risk at once.
No results yet
Run your code to check it against the examples, or submit to run every test.