A bank has put a price on each kind of mistake. A missed fraud costs miss_cost. A false alarm, a good payment blocked by mistake, costs alarm_cost. Now the threshold can be chosen by money instead of by guesswork.
Task: write cheapest_threshold(y_true, chance, thresholds, miss_cost, alarm_cost).
y_true holds 1 for fraud and 0 otherwise. chance holds the model's chance of fraud for each row.t, a row is flagged when its chance is at or above t.thresholds, the total cost is misses × miss_cost + false alarms × alarm_cost.Return [threshold, total_cost, recall, precision] for the threshold you chose. Recall and precision are rounded to 3 decimal places, and precision is 0.0 if nothing is flagged. Both costs are whole numbers, so the total cost is a whole number too.