MODELCATALOG

Evaluate & tune

Evaluate & tune

Evaluation

Separates model fitting from the evidence used to accept or reject a model.

Inputs

immutable model candidate + untouched test population

Outputs

evaluation.json + acceptance evidence

Core explanation

I treat evaluation as an explicit lifecycle gate rather than assuming a successful training job means a production-ready model.

01

Mental model

What this means before worrying about syntax.

Evaluate on validation or test data using metrics appropriate to the use case and persist those metrics for comparison and governance.

  • Evaluation is an explicit acceptance gate after training.
  • Aggregate metrics are not enough; inspect classes, slices and operating thresholds.
  • The test set should remain untouched until candidate selection is substantially complete.
Lifecycle position
trained model + held-out data -> metrics -> acceptance decision
02

Implementation anatomy

The sequence you would actually build or configure.

  1. 1

    Run predictions on held-out data.

  2. 2

    Calculate task-appropriate metrics.

  3. 3

    Review confusion matrix/per-class results.

  4. 4

    Evaluate business slices.

  5. 5

    Test thresholds and operational volume.

  6. 6

    Persist metrics and acceptance result.

Objects / terms worth remembering
accuracyprecisionrecallF1AUCbusiness thresholds
03

Concrete example

A real model-development or production flow.

1

Macro F1 highlights weak small categories

↓
2

Confusion matrix shows fraud vs card-payment confusion

↓
3

0.75 confidence threshold controls auto-route coverage

↓
4

Track coverage and error rate among auto-routed complaints

04

Implementation lab

Concrete code, data manipulation and configuration for this lifecycle step.

01

Per-class metrics + confusion matrix

python
from sklearn.metrics import (
    classification_report,
    confusion_matrix,
    f1_score,
)

pred = pipeline.predict(test_df["text"])

print("macro F1:", f1_score(
    test_df["label"], pred, average="macro"
))
print(classification_report(test_df["label"], pred))

cm = confusion_matrix(
    test_df["label"],
    pred,
    labels=pipeline.classes_,
)
print(cm)
02

Threshold sweep for operational trade-off

python

This turns a vague '0.75 confidence' rule into evidence: what volume is automated and what error rate remains?

import numpy as np
import pandas as pd

proba = pipeline.predict_proba(test_df["text"])
best_idx = proba.argmax(axis=1)
pred = pipeline.classes_[best_idx]
confidence = proba.max(axis=1)

rows = []
for threshold in np.arange(0.50, 0.96, 0.05):
    mask = confidence >= threshold
    coverage = mask.mean()
    accuracy = (
        (pred[mask] == test_df.loc[mask, "label"]).mean()
        if mask.any() else np.nan
    )
    rows.append({
        "threshold": round(float(threshold), 2),
        "coverage": coverage,
        "accepted_accuracy": accuracy,
    })

print(pd.DataFrame(rows))
03

Write machine-readable evaluation.json

python

A pipeline condition or approval process can consume this artifact instead of scraping notebook output.

import json
from pathlib import Path

metrics = {
    "macro_f1": float(macro_f1),
    "auto_route_threshold": 0.75,
    "auto_route_coverage": float(coverage),
    "auto_route_accuracy": float(accepted_accuracy),
}

Path("/opt/ml/processing/evaluation").mkdir(
    parents=True, exist_ok=True
)
Path("/opt/ml/processing/evaluation/evaluation.json").write_text(
    json.dumps(metrics, indent=2)
)

Design decisions that matter

  • Define acceptance metrics from business loss.
  • Set threshold before production.
  • Champion/challenger comparison.

Common failure modes

  • Repeated tuning on the test set turns it into validation data.
  • Aggregate accuracy can hide high-risk segment failures.
  • Offline results can be invalidated by serving skew.

Production readiness check

Items to close before treating this step as production-ready.

✓ held-out population✓ per-class metrics✓ slices✓ thresholds✓ calibration✓ acceptance rule✓ metric artifact