Python exercise · about 5 minutes · free
Precision and Recall by Hand
Accuracy hides what matters. Did we catch the defaulters (recall)? Were our alarms right (precision)?
Count TP (predicted 1, really 1), FP (predicted 1, really 0), FN (predicted 0, really 1) and TN. Precision = TP / (TP + FP). Recall = TP / (TP + FN).
Your quest: Set
tp, fp, fn, tn, precision and recall.Try it now Runs in your browser. No sign-in needed. Ctrl+Enter to run.
Hint
pairs = list(zip(y_true, y_pred)); tp = pairs.count((1, 1)); fp = pairs.count((0, 1)); fn = pairs.count((1, 0)); tn = pairs.count((0, 0))Output appears here.