# A Threshold Is a Decision
# Core implementation example — ackleywill.com

import numpy as np

# Illustrative scores: use validation data to choose a threshold.
y = np.array([1, 0, 1, 0, 1, 0])
scores = np.array([0.90, 0.80, 0.65, 0.45, 0.30, 0.10])
threshold = 0.50
pred = scores >= threshold

tp = np.sum(pred & (y == 1))
fp = np.sum(pred & (y == 0))
fn = np.sum(~pred & (y == 1))
tn = np.sum(~pred & (y == 0))
cost_fp, cost_fn = 1, 5
print({"TP": tp, "FP": fp, "FN": fn, "TN": tn})
print("Error cost:", cost_fp * fp + cost_fn * fn)
