Performance metric tracking in MLOps - Commands & Configuration
pip install mlflowmlflow ui
If you remember nothing else from this pattern, remember: saving metrics during training lets you track and improve your models over time.
import mlflow import random with mlflow.start_run(): accuracy = random.uniform(0.7, 0.9) mlflow.log_metric("accuracy", accuracy) print(f"Logged accuracy: {accuracy:.3f}")
Practice
What is the main purpose of performance metric tracking in MLOps?
Solution
Step 1: Understand the role of performance metrics
Performance metrics are used to evaluate the quality and effectiveness of a machine learning model.Step 2: Identify the main goal of tracking these metrics
Tracking helps to see how well the model works over time and in different conditions.Final Answer:
To measure how well a machine learning model performs -> Option CQuick Check:
Performance metric tracking = measure model quality [OK]
- Confusing metrics with data storage
- Thinking metrics create models
- Mixing metrics with user management
Which of the following is the correct way to log a metric named accuracy with value 0.95 using a typical MLOps tracking tool?
Solution
Step 1: Identify required parameters for logging
Logging a metric usually requires a name and a numeric value.Step 2: Check syntax correctness
log_metric(name="accuracy", value=0.95) uses named parameters with correct types: name as string and value as number.Final Answer:
log_metric(name="accuracy", value=0.95) -> Option AQuick Check:
Correct syntax needs name and numeric value [OK]
- Passing metric name as a keyword argument
- Using string instead of numeric value
- Omitting the metric name
Given the following code snippet for metric logging, what will be the output or effect?
metrics = {}
# Log accuracy at step 1
metrics[1] = 0.85
# Log accuracy at step 2
metrics[2] = 0.90
print(metrics[2])Solution
Step 1: Understand the dictionary assignments
metrics[1] is set to 0.85, metrics[2] is set to 0.90.Step 2: Identify the printed value
print(metrics[2]) outputs the value stored at key 2, which is 0.90.Final Answer:
0.90 -> Option BQuick Check:
metrics[2] = 0.90 so print outputs 0.90 [OK]
- Confusing keys 1 and 2
- Expecting error due to missing key
- Assuming default None output
Identify the error in this metric logging code snippet:
def log_metric(name, value):
print(f"Metric {name}: {value}")
log_metric("loss")Solution
Step 1: Check function parameters and call
The function requires two arguments: name and value.Step 2: Identify the call mistake
The call provides only one argument ("loss"), missing the value argument.Final Answer:
Missing value argument when callinglog_metric-> Option DQuick Check:
Function call missing required argument [OK]
- Ignoring missing arguments
- Thinking print must be replaced
- Assuming metric name can be number
You want to track multiple metrics (accuracy, loss) over training steps and compare models. Which approach best supports this in an MLOps system?
- Log each metric with its name, value, and step number.
- Store metrics in a structured format like a table or database.
- Use the stored metrics to generate comparison reports.
Which option describes the best practice?
Solution
Step 1: Understand metric logging needs
Logging with name, value, and step allows tracking progress over time.Step 2: Importance of structured storage and reporting
Structured storage enables easy querying and comparison; reports help analyze results.Final Answer:
Log metrics with name, value, and step; store structured; generate reports -> Option AQuick Check:
Complete tracking needs structured logging and reporting [OK]
- Ignoring step numbers in logs
- Storing metrics unstructured
- Logging only final values
Ready to prove it?
Pass the test and this pattern moves unknown
