(benchmark_dir: Path, predictions_path: Path)
| 160 | |
| 161 | |
| 162 | def evaluate(benchmark_dir: Path, predictions_path: Path) -> dict[str, Any]: |
| 163 | labels = load_labels(benchmark_dir) |
| 164 | predictions = load_predictions(predictions_path) |
| 165 | |
| 166 | episode_metrics = [] |
| 167 | missing_predictions = 0 |
| 168 | for episode_id, label_rows in labels.items(): |
| 169 | predicted_ids = predictions.get(episode_id) |
| 170 | if predicted_ids is None: |
| 171 | missing_predictions += 1 |
| 172 | predicted_ids = [] |
| 173 | episode_metrics.append(evaluate_episode(label_rows, predicted_ids)) |
| 174 | |
| 175 | summary = { |
| 176 | "episodes": len(labels), |
| 177 | "predicted_episodes": len(predictions), |
| 178 | "missing_predictions": missing_predictions, |
| 179 | } |
| 180 | for metric in [ |
| 181 | "gNDCG@20", |
| 182 | "Useful@5", |
| 183 | "Useful@20", |
| 184 | "SelectedNDCG@20", |
| 185 | "StrictR@20+", |
| 186 | "MRR@20", |
| 187 | "Lift@20", |
| 188 | ]: |
| 189 | summary[metric] = mean_defined([row.get(metric) for row in episode_metrics]) |
| 190 | summary["RecommendationScore"] = recommendation_score(summary) |
| 191 | return summary |
| 192 | |
| 193 | |
| 194 | def parse_args() -> argparse.Namespace: |
no test coverage detected