Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 142/ 160
08. MLOps & Model Deployment

Experiment Tracking with MLflow

Log params, metrics, and artifacts so experiments are comparable and recoverable.

IntermediateRuns · Metrics · Artifacts3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Experiment tracking is a logbook for your models: every time you train one, you write down the settings, the scores and the files, so you can find and rerun the best one later.

Think of it like…

A lab notebook with an index. Every experiment records the recipe (parameters), the measurements (metrics), the samples (artifacts) and the date and equipment (code version, data version, environment), so anyone can repeat or compare them without guessing.

Where you’ve seen it

A churn model search runs 30 random-search configurations, each logged as an MLflow run with parameters (learning_rate, max_depth, n_estimators, subsample), validation metrics (val_auc, val_pr_auc), tags (git_sha, data_version=v3, dvc_md5) and artifacts (the feature importance plot, the model). The table shows a baseline logistic regression at AUC 0.842 and a best gradient-boosted run at 0.871, but five seeds of the same configuration give 0.868 with a standard deviation of 0.004, so differences below about 0.008 are noise. Selection bias is real: the expected maximum of 30 independent standard normal draws is about 2.04 standard deviations, so choosing the best of 30 runs with per-run noise of 0.004 inflates the reported score by roughly 2.04 × 0.004 ≈ 0.008 AUC; the team therefore picks the winner on validation and reports a fresh test-set score once, never selecting on test. Cross-validation folds are logged as nested runs under a parent run so the mean and spread are one click away. Artifacts are 50 MB per run (the model plus plots), 30 runs ≈ 1.5 GB in the S3 artifact store, which a retention policy trims for non-promoted runs. Each run records requirements.txt and the conda environment through the model's logged dependencies, so the model can be reloaded months later with the right library versions. The tracking server uses PostgreSQL for metadata and S3 for artifacts, with authentication in front. The best run is registered in the model registry (see the later lesson), carrying its run ID, so deployment can trace back to the exact parameters and data version. A short convention keeps things tidy: one experiment per problem, run names like xgb-depth6-seed1, a stage tag (dev, candidate, final) and metric names that never change.

Words you’ll hear

Run
One execution of training code with its logged parameters, metrics and artifacts.
Experiment
A named group of runs for one problem.
Artifact
A file produced by a run, such as a model, plot or dataset sample.
Tracking server
A service with a metadata database and artifact store behind the MLflow UI and API.

Visual diagram

Loading interactive diagram

Theory & deep dive

What to log and how MLflow organises it

Log everything needed to reproduce and compare: parameters (hyperparameters, feature set version, random seed, split definition), metrics (validation and cross-validation scores, training loss per step, latency and model size), tags (git commit, data version or DVC hash, run purpose, owner) and artifacts (the model, preprocessing pipeline, plots, a sample of predictions, conda.yaml). In code: with mlflow.start_run(run_name="xgb-depth6-seed1"): mlflow.log_params(params); mlflow.log_metric("val_auc", auc); mlflow.sklearn.log_model(pipe, "model", signature=signature). Autologging (mlflow.autolog()) records many of these for scikit-learn, XGBoost, PyTorch and others, and you add custom tags and metrics on top. Use nested runs for cross-validation folds or hyperparameter trials under a parent run.

The architecture has three parts: a client (your code), a tracking server with a backend store (a SQL database for runs, params and metrics) and an artifact store (S3, GCS or Azure Blob). Run it locally with a file store for solo work and with a shared server for teams. Keep naming conventions: one experiment per problem, stable metric names (val_auc, never AUC_v2), meaningful run names and tags such as stage. Log the environment (the logged model carries its pip requirements) so the model can be loaded with the right versions, and log data lineage (a dataset hash or DVC revision), because identical parameters on different data are not the same experiment.

A logged run

params: learning_rate 0.05, max_depth 6, n_estimators 400, subsample 0.8, seed 1. metrics: val_auc 0.869, val_pr_auc 0.612, fit_seconds 41. tags: git_sha 9be3c1, data_version v3, stage candidate. artifacts: model/, feature_importance.png, confusion_matrix.png.

Key takeaway: Log parameters, metrics, tags and artifacts, including data and environment versions, under stable names.

Comparing runs honestly

A table of runs invites over-reading. Seed noise matters: five seeds of one configuration giving AUC 0.868 with a standard deviation of 0.004 means two models 0.003 apart are indistinguishable, so compare means over seeds or use repeated cross-validation and a paired test or confidence interval. Selection bias (the winner's curse): the expected maximum of n independent normal draws grows with n; for 30 runs it is about 2.04 standard deviations above the mean, so choosing the best of 30 runs with noise 0.004 inflates the reported AUC by about 0.008. Defences: select on a validation set or inner cross-validation, then report a single fresh test-set estimate; use nested cross-validation for small data; and prefer simple models unless the gain exceeds the noise.

Operational habits: set a baseline run first (logistic regression, a prior-rate predictor), log failed or poor runs too (they are evidence about what doesn't work), tag runs that are candidates for promotion and apply retention to artifacts (30 runs × 50 MB ≈ 1.5 GB; keep final and promoted runs, prune the rest). Don't log secrets or raw personal data as parameters or artifacts. When a run is promoted, register the model so deployment references the run ID; that link is what lets you answer "which data and parameters produced the model serving production today?" in seconds.

Winner's curse

30 runs, per-run noise sd = 0.004 AUC. E[max of 30 standard normals] ≈ 2.04 → expected inflation ≈ 2.04 × 0.004 = 0.0082. A reported best of 0.871 on validation likely corresponds to a true value near 0.863; the baseline 0.842 gap is still real, a 0.003 gap between top runs is not.

Key takeaway: Judge differences against seed noise, expect the best of many runs to be optimistic and report one untouched test estimate.

How it works, step by step

Step 1 of 4
Data scientist

1. Set up tracking

Point to a tracking server, create an experiment per problem and agree on metric and tag names.

PostgreSQL metadata + S3 artifacts
Key numbers at this step
Convention
val_auc, stage tag

When to use it & trade-offs

What it is

Experiment tracking records what you tried and what happened so results are comparable and recoverable. MLflow Tracking organises this as experiments containing runs; each run stores parameters (log_param), metrics (log_metric, optionally per step for learning curves), tags (git commit, data version, owner), and artifacts (plots, the fitted model, a confusion matrix, the environment file). A tracking server keeps run metadata in a backend database and artifacts in object storage, and a UI lets you filter, sort and compare runs. mlflow.autolog() captures much of this automatically for common libraries, and mlflow.<flavour>.log_model saves a model with a signature and dependencies so it can be loaded and served later.

Why it matters: Without tracking, the best model of last Tuesday lives in someone's terminal history. Teams can't say which parameters produced a number, which data it used or whether the "improvement" is real. Tracking turns modelling into an auditable process: results can be reproduced, compared fairly and handed to deployment with their lineage. It also exposes a statistical trap: picking the best of many noisy runs inflates the reported score unless you account for it.

When to reach for it

  • Hyperparameter searches and model comparisons
  • Recording lineage for models that will be deployed
  • Team dashboards of experiments and baselines

When to avoid or be careful

  • Selecting models using the test set
  • Logging results without the data version
  • Over-reading differences smaller than seed noise

Tracking approaches

MLflow Tracking
Best for: Open, framework-agnostic tracking and registry

Strengths: UI, API, autologging, model registry.

Watch out: You host and secure the server.

Hosted trackers (Weights & Biases, Neptune)
Best for: Rich dashboards and collaboration

Strengths: Managed; strong visualisation.

Watch out: Cost and data-governance review.

Spreadsheets and filenames
Best for: Very small solo experiments

Strengths: Zero setup.

Watch out: No lineage; error-prone; hard to share.

Interview signals & numbers to know

When this topic comes up

  • “How do you keep track of experiments?”
  • What you log in a run
  • Seed variance and comparing models
  • Why the best of many runs is optimistic
  • Linking a registered model to its run

Benchmarks & rules of thumb

2.04 σ -
expected maximum of 30 standard normal draws
≈ 0.008 AUC -
inflation from picking the best of 30 runs with 0.004 noise
0.868 ± 0.004 -
five-seed mean ± sd in the example

Common mistakes & follow-ups

Common interview mistakes

  • Reporting the best validation score as the expected production score.
  • Using different metric names across runs.
  • Never pruning artifacts and filling the store.

Likely interviewer follow-ups

  • How would you compare two models within the noise level?
  • How do you ensure a registered model can be reproduced?
  • What would you log for a deep learning run?
Interview tip: Mention the winner's curse with the 2.04σ figure; it shows you understand why validation scores flatter the best run.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Experiment Tracking with MLflow with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Project Structuring & Cookiecutter Data Science
Next topic
Data & Model Versioning with DVC