🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #241

Experiment Tracking

Experiment tracking automatically logs every training run's parameters, metrics and artifacts — replacing "which of my 40 notebook runs actually produced the good result?" with a searchable, comparable record.

What Gets Logged, Every Run

CategoryExamples
Hyperparametersn_estimators, learning_rate, max_depth
MetricsAccuracy, F1, RMSE — on train, validation, and test sets
ArtifactsThe trained model file, plots, confusion matrices
MetadataGit commit hash, data version, timestamp, who ran it

Python Implementation — MLflow

import mlflow
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, f1_score

mlflow.set_experiment("loan_approval_model")

for n_estimators in [100, 200, 300]:
    with mlflow.start_run(run_name=f"rf_n{n_estimators}"):
        model = RandomForestClassifier(n_estimators=n_estimators, random_state=42)
        model.fit(X_train, y_train)
        predictions = model.predict(X_test)

        mlflow.log_param("n_estimators", n_estimators)
        mlflow.log_metric("accuracy", accuracy_score(y_test, predictions))
        mlflow.log_metric("f1_score", f1_score(y_test, predictions))
        mlflow.sklearn.log_model(model, "model")

# Launch the UI to browse and compare every run visually:
# mlflow ui

Every run in this loop gets its own tracked record — no manual notes needed to remember which n_estimators value produced which score; the MLflow UI lets you sort, filter and compare runs directly.

Comparing Runs Programmatically

experiment = mlflow.get_experiment_by_name("loan_approval_model")
runs = mlflow.search_runs(experiment_ids=[experiment.experiment_id])

best_run = runs.sort_values("metrics.f1_score", ascending=False).iloc[0]
print(f"Best run: {best_run['run_id']}, F1: {best_run['metrics.f1_score']:.3f}")
print(f"Params: n_estimators={best_run['params.n_estimators']}")

Why This Matters Beyond Convenience

Without tracking, comparing hyperparameter choices means manually scrolling through notebook cell outputs or, worse, relying on memory. With tracking, "which configuration actually performed best, and why" becomes a query, not an archaeology project — and it directly feeds the model registry, since the best-tracked run is exactly what gets promoted to production.

Practical Use Cases

  • Any project running more than a handful of training experiments — manual tracking stops scaling almost immediately
  • Team environments, where multiple people need to see and compare each other's experiment results

Common Mistakes

  • Relying on notebook cell outputs or personal notes instead of a proper tracking tool, losing the ability to systematically compare runs later.
  • Logging metrics but not hyperparameters (or vice versa) — both are needed to understand why one run outperformed another.

Interview Relevance

Q: "How would you keep track of 50 different hyperparameter combinations tried during model development?" Use an experiment tracking tool like MLflow to automatically log every run's parameters, metrics and artifacts — this makes comparing, sorting, and retrieving the best run a direct query instead of manually reviewing scattered notebook outputs.

Practice Question

Modify the MLflow example above to also log a confusion matrix plot as an artifact for each run.

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Experiment Tracking – FAQs

Quick answers about learning Experiment Tracking in Machine Learning.

This free note from CodingNow 2.0 explains Experiment Tracking in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including Experiment Tracking, is 100% free with no signup required.
With focused practice, most students grasp Experiment Tracking in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now