The default 0.5 threshold assumes a false positive costs the same as a false negative. In fraud detection, missing fraud might cost 5.
Implement:
expected_cost(probs, labels, threshold, cost_fp, cost_fn): predict positive when prob >= threshold, and return FP * cost_fp + FN * cost_fnbest_threshold(probs, labels, cost_fp, cost_fn): try every distinct probability as a threshold, plus 1.0 + 1e-9 (predict nothing positive). Return (threshold, cost) with the lowest cost (ties: the smallest threshold).bayes_threshold(cost_fp, cost_fn): the optimal threshold for calibrated probabilities, cost_fp / (cost_fp + cost_fn)