Sure of Itself, and Wrong

Machine Learning in CodeEasy+10 XP+10

Sure of Itself, and Wrong

A photo classifier reports how confident it is in each answer. A healthy model is very sure when it is right and less sure when it is wrong. The dangerous mistakes are the ones it made while still very sure.

Task: write confidence_check(y_true, y_pred, confidence, cutoff).

  • y_true and y_pred are the real and predicted labels. confidence is the model's confidence in each prediction, between 0 and 1.
  • Return a list of three values:
    1. the mean confidence on rows it got right, rounded to 3 decimal places,
    2. the mean confidence on rows it got wrong, rounded to 3 decimal places,
    3. how many wrong rows had a confidence strictly above cutoff, as a whole number.

Every test has at least one right row and one wrong row.

Examples

y_true = [3, 1, 4, 1, 5, 9]
y_pred = [3, 1, 4, 7, 5, 4]
confidence = [0.99, 0.95, 0.9, 0.6, 0.98, 0.93]
cutoff = 0.9
returns [0.955, 0.765, 1]
y_true = ['cat', 'dog', 'dog', 'fox']
y_pred = ['cat', 'cat', 'dog', 'dog']
confidence = [0.8, 0.55, 0.9, 0.7]
cutoff = 0.6
returns [0.85, 0.625, 1]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run