Quiz 2

MLflow & Experiment Tracking

421 words
2 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# MLflow & Experiment Tracking ## 🎯 Learning Objectives - Track ML experiments with MLflow - Compare runs, log parameters, metrics, and artifacts - Register and deploy models with MLflow Model Registry - Version data with DVC ## 📖 Core Content ### 6.1 Why Experiment Tracking? Without tracking: "I think the model w...

MLflow & Experiment Tracking

🎯 Learning Objectives

  • Track ML experiments with MLflow
  • Compare runs, log parameters, metrics, and artifacts
  • Register and deploy models with MLflow Model Registry
  • Version data with DVC

📖 Core Content

6.1 Why Experiment Tracking?

Without tracking: "I think the model with learning_rate=0.01 and batch_size=32 gave 92% accuracy... or was it learning_rate=0.001?" Experiment tracking solves this by recording every training run automatically.

6.2 MLflow Components

(Diagram)

6.3 MLflow Tracking Example

python
# runnable
# Note: Requires mlflow installation
# import mlflow
# import mlflow.sklearn
# from sklearn.ensemble import RandomForestClassifier
# from sklearn.datasets import load_iris
# from sklearn.model_selection import train_test_split
# from sklearn.metrics import accuracy_score
#
# with mlflow.start_run():
#     # Log parameters
#     mlflow.log_param("n_estimators", 100)
#     mlflow.log_param("max_depth", 5)
#
#     # Train model
#     iris = load_iris()
#     X_train, X_test, y_train, y_test = train_test_split(
#         iris.data, iris.target, test_size=0.3, random_state=42)
#
#     model = RandomForestClassifier(n_estimators=100, max_depth=5)
#     model.fit(X_train, y_train)
#
#     # Log metrics
#     acc = accuracy_score(y_test, model.predict(X_test))
#     mlflow.log_metric("accuracy", acc)
#
#     # Log model
#     mlflow.sklearn.log_model(model, "random_forest_model")
#
#     print(f"Run logged: accuracy={acc:.3f}")

6.4 DVC (Data Version Control)

DVC extends Git to handle large data files and ML pipelines.
bash
# DVC commands
dvc init
dvc add data/dataset.csv
git add data.dvc .gitignore
git commit -m "Add dataset"
git tag "v1.0-data"
dvc push  # Upload data to remote storage
git checkout v1.0-data
dvc checkout  # Restore data version

📝 Practice Questions

Q1: Why log experiments instead of just saving models?
Experiments capture the entire context: parameters, code version, data version, metrics, and artifacts. This enables: (1) comparing which hyperparameters worked best, (2) reproducing any past result, (3) understanding why a model degraded over time. A saved model file alone doesn't tell you how it was trained. Q2: What is the MLflow Model Registry?
A central repository for managing model versions. It tracks: which version is in staging vs production, model lineage (which run produced it), stage transitions (staging → production), and deployment metadata. Think of it as "Git for models" with staging/production workflows. Q3: How does DVC differ from Git LFS?
Git LFS replaces large files with pointers; DVC stores the pointers in Git and the actual data in remote storage (S3, GCS, etc.). DVC also versions data transformations (pipelines), not just files. DVC is designed specifically for ML workflows; Git LFS is a general-purpose large file solution. Join Discord PreviousAPIs & Web ScrapingNextCloud Computing
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.