skills/tabular/weighted-recall-multi-objective-metric/SKILL.md
Evaluate recommendation quality with recall@K per action type, combined via business-importance weights
npx skillsauth add wenmin-wu/ds-skills tabular-weighted-recall-multi-objective-metricInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
For multi-objective recommendation (predict clicks, carts, and orders), evaluate recall@K separately per action type, then combine with weights reflecting business importance. Orders matter most (0.60), carts next (0.30), clicks least (0.10). This single metric aligns optimization with business value while tracking per-type performance.
import numpy as np
def weighted_recall(predictions, ground_truth, k=20,
weights={'clicks': 0.10, 'carts': 0.30, 'orders': 0.60}):
"""Compute weighted recall across action types.
Args:
predictions: dict {action_type: {session_id: [predicted_aids]}}
ground_truth: dict {action_type: {session_id: [true_aids]}}
k: max predictions per session
weights: importance weight per action type
"""
recalls = {}
for action_type, w in weights.items():
hits, total = 0, 0
preds = predictions.get(action_type, {})
truth = ground_truth.get(action_type, {})
for sid, true_aids in truth.items():
pred_aids = set(preds.get(sid, [])[:k])
true_set = set(true_aids)
hits += len(pred_aids & true_set)
total += min(len(true_set), k)
recalls[action_type] = hits / max(total, 1)
score = sum(recalls[t] * w for t, w in weights.items())
return score, recalls
min(len(true_set), k) avoids penalizing when ground truth exceeds Kdata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF