Classification Metrics
~12 mincode completion
Write score_model(y_true, y_pred) that returns [accuracy, precision, recall], in that order, for binary labels of 0 and 1.
Examples
A perfect classifier scores 1.0 on all three
- Input
- score_model([0, 1, 0, 1], [0, 1, 0, 1])
- Output
- [1, 1, 1]
One false positive lowers precision but not recall
- Input
- score_model([0, 1, 0, 1], [1, 1, 0, 1])
- Output
- [0.75, 0.66667, 1]
One missed positive lowers recall but not precision
- Input
- score_model([0, 1, 1, 1], [0, 1, 0, 1])
- Output
- [0.75, 1, 0.66667]
Hints
Hint 1
Work directly with the arguments y_true, y_pred and return the result rather than printing it.
Hint 2
Double check the order of precision and recall.
Requirements
y_true: 1-D array of true labels (0 or 1)y_pred: 1-D array of predicted labels (0 or 1)Return a list [accuracy, precision, recall].
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~12 min
••••••••••••••
7 employers weight this skill
2 health and bio companies, 2 quant funds, 2 enterprise vendors, 1 AI product company. Top match scores 50.
Python
import numpy as np
from sklearn.metrics import accuracy_score, precision_score, recall_score
def score_model(y_true, y_pred):
"""
Report the three headline classification metrics.
Args:
y_true: 1-D array of true labels (0 or 1)
y_pred: 1-D array of predicted labels (0 or 1)
Returns:
A list [accuracy, precision, recall].
"""
# YOUR CODE HERE
pass