Hello! Welcome back to our final module, Architecture for AI & Machine Learning.
In our last lesson, we took a high-level tour of MLOps, identifying its core components: experiment tracking, the model registry, and CI/CD pipelines. You learned that experiment tracking is the foundational practice that brings scientific rigor to the otherwise chaotic process of model development.
Today, we move from theory to practice. Our learning outcome is to use MLflow Tracking to log model parameters, metrics, and artifacts in a Databricks experiment. As an architect, knowing how these tools work at a practical level is crucial for designing and implementing effective MLOps systems. Since Databricks provides a fully managed and integrated MLflow environment, it's an excellent platform to learn these fundamentals.
1. The Building Blocks of MLflow Tracking
Before we write any code, let's quickly solidify the key concepts. As we discussed previously, MLflow is designed to manage the entire machine learning lifecycle. Today, we're focusing on the "Tracking" component.

MLflow Tracking is organized around a few simple concepts. This brief reading will formalize them.
Track model development using MLflow
This document from Microsoft Learn provides a concise definition of the core entities in MLflow Tracking: experiments and runs.
Please read the short section titled 'MLflow tracking with experiments, runs, and models'. It clearly defines the relationship between these key components.
To summarize, every time you run your training code, you create a Run within an Experiment. Inside that run, you log:
- Parameters: The inputs to your code, like hyperparameters (
n_estimators = 100). - Metrics: The outputs that measure performance, like model accuracy or error (
mse = 4150.2). - Artifacts: Any output files, such as plots, data files, and most importantly, the trained model itself.
Databricks automatically hosts the MLflow tracking server, so all your logged data is saved and viewable directly within your workspace.
2. Logging Your Experiments: Two Approaches
MLflow offers two primary ways to log your training runs in Python: autologging and explicit logging.
Approach 1: Autologging (The "Easy Button")
For many common ML libraries (like Scikit-learn, TensorFlow, and PyTorch), MLflow can automatically log everything for you with a single line of code: mlflow.autolog(). When enabled, it automatically captures parameters, metrics, and the model artifact at the end of a training call without any extra effort.
This is the fastest way to get started. Let's see it in action.
Explained how to use Databricks to train ML Models using MLFlow & Hyperopt
This video by Praveen Reddy Learnings provides a great walkthrough of MLflow in Databricks. We'll watch a short segment where autologging is enabled and a run is initiated.
Watch from 04:21 to 05:40. The video first shows the empty Experiments page, then enables autologging and starts a run with mlflow.start_run().
As you saw, mlflow.autolog() is powerful. However, you often need more fine-grained control over what gets logged. You might want to log custom metrics, intermediate results, or specific files and plots generated during the run. This is where explicit logging comes in.
Approach 2: Explicit Logging (The "Power User" Method)
Explicit logging gives you full control. You wrap your training logic in an mlflow.start_run() block and use specific API functions to log exactly what you need.
The main functions are:
mlflow.log_param(key, value): Logs a single parameter.mlflow.log_metric(key, value): Logs a single metric.mlflow.log_artifact(local_path): Logs a local file or directory.mlflow.log_figure(figure, artifact_file): A handy function for loggingmatplotlibplots.mlflow.<framework>.log_model(...): A framework-specific function (e.g.,mlflow.sklearn.log_model) to log a trained model in a standard format.
The following quickstart guide from Databricks provides a perfect example of this in practice.
MLflow Logging API Quickstart (Python)
This notebook is a self-contained example of using the MLflow Logging API. It trains a simple model and demonstrates how to log parameters, metrics, a model, and even a plot artifact.
Focus on the final code cell, which starts with with mlflow.start_run():. Read through the code and see how log_param, log_metric, log_model, and log_figure are used to capture the results of the training run.
This explicit approach is more verbose but gives you complete command over the information you capture, which is essential for complex experiments and production-grade workflows.
3. Viewing and Comparing Runs in the Experiments UI
The real power of MLflow Tracking comes alive when you view the results. The MLflow Experiments UI in Databricks provides a dashboard to see all your runs, sort and filter them, and compare their results.
Let's return to the video to see how the run we logged appears in the UI and how we can use it to compare experiments.
Explained how to use Databricks to train ML Models using MLFlow & Hyperopt
Now we'll see the payoff. This clip shows the logged run in the Experiments UI and demonstrates the core value of tracking: comparing different runs.
Watch from 06:09 to 09:20. The first part (to 07:43) shows the details of a single run, including parameters, metrics, and artifacts. The second part demonstrates what happens when you run the experiment again with a different parameter—MLflow tracks it as a new run, allowing for easy comparison.
As the video showed, every run is captured with its unique parameters and resulting metrics. The UI makes it trivial to see how changing a hyperparameter, like n_estimators, impacts the model's performance.

This ability to track, view, and compare experiments is the bedrock of reproducible machine learning.
Test your understanding!
You are training a Scikit-learn RandomForestRegressor model. The code looks like this:
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
import mlflow
# Model parameters
n_estimators = 150
max_depth = 10
# Assume X_train, y_train, X_test, y_test are defined
# Train the model
rf = RandomForestRegressor(n_estimators=n_estimators, max_depth=max_depth)
rf.fit(X_train, y_train)
# Evaluate the model
predictions = rf.predict(X_test)
mse = mean_squared_error(y_test, predictions)
# --- YOUR MLFLOW CODE GOES HERE ---
Add the necessary MLflow code to an mlflow.start_run() block to explicitly log the two parameters (n_estimators, max_depth), the mse metric, and the trained rf model.
Show answer
# --- YOUR MLFLOW CODE GOES HERE ---
with mlflow.start_run():
# Log parameters
mlflow.log_param("n_estimators", n_estimators)
mlflow.log_param("max_depth", max_depth)
# Log metric
mlflow.log_metric("mse", mse)
# Log the model
mlflow.sklearn.log_model(rf, "random-forest-model")
This code block creates a new MLflow run and logs the specified parameters, metric, and the Scikit-learn model as an artifact.
Conclusion
In this lesson, you've moved from the concept of experiment tracking to its practical application using MLflow in Databricks. This skill is fundamental to MLOps and a prerequisite for building reliable and scalable ML systems.
Key Takeaways:
- MLflow Tracking organizes your work into Experiments and Runs.
- Autologging (
mlflow.autolog()) is the quickest way to get started, automatically capturing key information for common frameworks. - Explicit Logging (
mlflow.log_param,mlflow.log_metric, etc.) provides fine-grained control for custom logging needs. - The Experiments UI in Databricks is a powerful tool for viewing, comparing, and analyzing the results of your training runs.
By systematically tracking your experiments, you create a reproducible and auditable history of your model development process. This not only improves your own productivity but is also the first step toward automating the entire ML lifecycle.
Preview of the next lesson:
Tracking experiments is the first step. What happens when you've identified a promising model from your runs? The next logical step is to formalize it as a candidate for deployment. In our next lesson, we will register a model and manage its versions using the MLflow Model Registry.