Don't Round Before You Rank

Machine Learning in CodeEasy+10 XP+10

Don't Round Before You Rank

AUC measures how well a model ranks cases: the chance that a real positive gets a higher score than a real negative. To do that, it needs the model's scores, not its final yes-or-no answers.

Task: write two_aucs(y_true, chance) and return [auc_from_chances, auc_from_labels], each rounded to 3 decimal places.

  • y_true holds 1 for positive and 0 for negative. Both appear.
  • auc_from_chances is the ROC AUC computed from chance directly.
  • auc_from_labels is the ROC AUC computed from hard labels: 1 where the chance is at or above 0.5, and 0 otherwise.

The second number is what you get if you hand AUC the output of predict by mistake. Compare it with the first.

Examples

y_true = [1, 0, 1, 0, 0, 1, 0, 0]
chance = [0.9, 0.6, 0.4, 0.2, 0.1, 0.7, 0.3, 0.05]
returns [0.933, 0.733]
y_true = [0, 0, 1, 1, 0, 1]
chance = [0.1, 0.2, 0.3, 0.45, 0.05, 0.4]
returns [1.0, 0.5]

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