You are setting up monitoring for deployed ML systems. Different system types require different metrics. Accuracy alone does not capture the full picture.
Given a system type and ground truth / prediction arrays, compute the appropriate set of monitoring metrics.
classification (binary, y_true and y_pred are 0 or 1):
accuracy=nTP+TN precision=TP+FPTPrecall=TP+FNTP f1=precision+recall2⋅precision⋅recallregression (y_true and y_pred are floats):
mae=n1i∑∣yi−y^i∣rmse=n1i∑(yi−y^i)2ranking (y_true is binary relevance, y_pred is predicted scores):
precision_at_3=3relevant items in top 3recall_at_3=total relevantrelevant items in top 3Return a sorted list of (metric_name, value) tuples, sorted alphabetically by name. Handle division by zero by returning 0.0.
Input:
system_type = "classification" y_true = [1, 0, 1, 1, 0, 1, 0, 0] y_pred = [1, 0, 0, 1, 0, 1, 1, 0]
Output:
[("accuracy", 0.75), ("f1", 0.75), ("precision", 0.75), ("recall", 0.75)]
TP=3, FP=1, FN=1, TN=3. All four classification metrics are computed and returned sorted by name.
Input:
system_type = "regression" y_true = [3.0, 5.0, 2.5, 7.0] y_pred = [2.5, 5.5, 2.0, 8.0]
Output:
[("mae", 0.625), ("rmse", 0.6614)]
Errors are [0.5, 0.5, 0.5, 1.0]. MAE = 0.625, RMSE is approximately 0.6614. Regression uses different metrics than classification.
Use if/elif to branch on system_type and compute only the relevant metrics for each.
For ranking, pair up predictions with labels using zip(), then sort by predicted score descending before slicing the top k.
Sign in to take notes on this problem
Accepts: string
Accepts: array
Accepts: array
You are setting up monitoring for deployed ML systems. Different system types require different metrics. Accuracy alone does not capture the full picture.
Given a system type and ground truth / prediction arrays, compute the appropriate set of monitoring metrics.
classification (binary, y_true and y_pred are 0 or 1):
accuracy=nTP+TN precision=TP+FPTPrecall=TP+FNTP f1=precision+recall2⋅precision⋅recallregression (y_true and y_pred are floats):
mae=n1i∑∣yi−y^i∣rmse=n1i∑(yi−y^i)2ranking (y_true is binary relevance, y_pred is predicted scores):
precision_at_3=3relevant items in top 3recall_at_3=total relevantrelevant items in top 3Return a sorted list of (metric_name, value) tuples, sorted alphabetically by name. Handle division by zero by returning 0.0.
Input:
system_type = "classification" y_true = [1, 0, 1, 1, 0, 1, 0, 0] y_pred = [1, 0, 0, 1, 0, 1, 1, 0]
Output:
[("accuracy", 0.75), ("f1", 0.75), ("precision", 0.75), ("recall", 0.75)]
TP=3, FP=1, FN=1, TN=3. All four classification metrics are computed and returned sorted by name.
Input:
system_type = "regression" y_true = [3.0, 5.0, 2.5, 7.0] y_pred = [2.5, 5.5, 2.0, 8.0]
Output:
[("mae", 0.625), ("rmse", 0.6614)]
Errors are [0.5, 0.5, 0.5, 1.0]. MAE = 0.625, RMSE is approximately 0.6614. Regression uses different metrics than classification.
Use if/elif to branch on system_type and compute only the relevant metrics for each.
For ranking, pair up predictions with labels using zip(), then sort by predicted score descending before slicing the top k.
Sign in to take notes on this problem
Accepts: string
Accepts: array
Accepts: array