Monitoring Metrics Selection
Monitoring Metrics Selection
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.
Metric Sets
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.
Examples
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.
Hint 1
Use if/elif to branch on system_type and compute only the relevant metrics for each.
Hint 2
For ranking, pair up predictions with labels using zip(), then sort by predicted score descending before slicing the top k.
Requirements
- Route to the correct metric set based on the system_type argument
- Compute all metrics for that system type
- Return 0.0 for any metric that would involve division by zero
- Return a list of (name, value) tuples sorted alphabetically by name
Constraints
- system_type is one of "classification", "regression", "ranking"
- len(y_true) == len(y_pred), and len >= 3
- For classification: y_true and y_pred contain only 0 and 1
- For ranking: y_true is binary (0/1), y_pred contains distinct float scores
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: string
Accepts: array
Accepts: array
Monitoring Metrics Selection
Monitoring Metrics Selection
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.
Metric Sets
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.
Examples
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.
Hint 1
Use if/elif to branch on system_type and compute only the relevant metrics for each.
Hint 2
For ranking, pair up predictions with labels using zip(), then sort by predicted score descending before slicing the top k.
Requirements
- Route to the correct metric set based on the system_type argument
- Compute all metrics for that system type
- Return 0.0 for any metric that would involve division by zero
- Return a list of (name, value) tuples sorted alphabetically by name
Constraints
- system_type is one of "classification", "regression", "ranking"
- len(y_true) == len(y_pred), and len >= 3
- For classification: y_true and y_pred contain only 0 and 1
- For ranking: y_true is binary (0/1), y_pred contains distinct float scores
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: string
Accepts: array
Accepts: array