MODELCATALOG

Evaluate & tune

Evaluate & tune

Tuning & experiments

Makes model iteration traceable and comparable.

Inputs

search space + objective metric + repeatable training job

Outputs

ranked candidate runs + selected configuration

Core explanation

The goal is reproducibility and model selection, not tuning for its own sake.

01

Mental model

What this means before worrying about syntax.

Track configurations and metrics across runs; tune hyperparameters where the expected gain justifies the compute.

  • Experiments make data/code/config/metrics comparable across runs.
  • Tuning is repeated training over a bounded search space.
  • Reproducibility requires more than hyperparameters.
Lifecycle position
candidate configs -> training runs -> metrics -> selected candidate
02

Implementation anatomy

The sequence you would actually build or configure.

  1. 1

    Choose meaningful parameters.

  2. 2

    Define objective metric/direction.

  3. 3

    Bound search ranges.

  4. 4

    Track image/code/data versions.

  5. 5

    Select candidate on validation.

  6. 6

    Confirm on independent test data.

Objects / terms worth remembering
Experimentshyperparameterstuning jobs
03

Concrete example

A real model-development or production flow.

1

TF-IDF min_df {2,5,10}

↓
2

ngram_range {(1,1),(1,2)}

↓
3

LogisticRegression C on log scale

↓
4

class_weight None vs balanced

↓
5

objective = validation macro F1

04

Implementation lab

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

01

Simple reproducible search before managed tuning

python

The search-space design matters more than the tuner API. Know what each hyperparameter changes.

from sklearn.model_selection import ParameterGrid
from sklearn.metrics import f1_score

grid = ParameterGrid({
    "tfidf__min_df": [2, 5, 10],
    "tfidf__ngram_range": [(1, 1), (1, 2)],
    "clf__C": [0.1, 1.0, 10.0],
})

results = []
for params in grid:
    pipeline.set_params(**params)
    pipeline.fit(train_df["text"], train_df["label"])
    pred = pipeline.predict(val_df["text"])
    results.append({
        **params,
        "macro_f1": f1_score(
            val_df["label"], pred, average="macro"
        )
    })

best = max(results, key=lambda x: x["macro_f1"])
print(best)
02

Hyperparameters as ModelTrainer inputs

python
trainer = ModelTrainer(
    training_image=SKLEARN_TRAINING_IMAGE_URI,
    source_code=source_code,
    role=SAGEMAKER_ROLE_ARN,
    hyperparameters={
        "C": 1.0,
        "min_df": 5,
        "ngram_max": 2,
        "class_weight": "balanced",
    },
)

Design decisions that matter

  • Tuning budget vs likely value.
  • Early stopping for expensive models.
  • One metric vs multi-constraint selection.

Common failure modes

  • Tiny validation differences can be noise.
  • A run is not reproducible if its data snapshot/image is unknown.
  • Hyperparameter search cannot repair target leakage.

Production readiness check

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

✓ objective✓ search space✓ budget✓ seed✓ data version✓ image version✓ winning-run evidence