Vertex AI SDK Logging: Metrics vs Classification Metrics
Short answer
D Use the aiplatform.log_metrics function to log the F1 score, and use the aiplatform.log_classification_metrics function to log the confusion matrix.
Question
Key Takeaways
The trap is assuming one function handles all metrics;
log_classification_metricsis strictly for structured classification outputs (confusion matrices, ROC), whilelog_metricsis for scalar values.
Learn how to properly log evaluation metrics in Vertex AI using the Python SDK. Correctly separate scalar metrics like F1 scores from structured data like confusion matrices using the appropriate logging functions.
Common mistake: Selecting Option B (using `log_classification_metrics` for both) is the most common mistake. Candidates often assume the 'classification' logger is a catch-all for any classification-related metric, failing to recognize its limitation to structured matrix/curve data rather than scalar scores.
Expert Analysis
Distinction Between General and Classification-Specific Logging
The core of this question tests knowledge of the Vertex AI Python SDK's logging functions, specifically aiplatform.log_metrics versus aiplatform.log_classification_metrics. The scenario involves comparing a scikit-learn model to a TensorFlow model using F1 scores and confusion matrices. To correctly log these, one must understand what data structures each function accepts.
Analysis of aiplatform.log_classification_metrics
According to Google Cloud documentation, aiplatform.log_classification_metrics is specialized for classification tasks. It explicitly supports logging complex structures like confusion matrices (as a dictionary with 'rows' and 'labels') and ROC curves. However, it does not natively accept simple scalar metrics like the F1 score as direct arguments in the same way general metrics are logged. Its primary purpose is to handle the structural integrity of multi-class or binary classification outputs that require label alignment.
Analysis of aiplatform.log_metrics
The aiplatform.log_metrics function is designed for generic, scalar metric logging. It takes a dictionary of key-value pairs where values are numeric. This makes it ideal for logging single-point evaluation results like the F1 score, accuracy, or precision derived from sklearn.metrics. Using log_metrics for a confusion matrix would be inappropriate because a confusion matrix is a 2D array/table, which exceeds the scope of simple scalar logging and lacks the semantic context provided by the classification-specific logger.
Why Other Options Fail
Option B suggests logging both using log_classification_metrics. While this function handles confusion matrices well, it is not designed to ingest a pre-calculated scalar F1 score directly without additional processing or specific formatting that isn't standard for this function's signature. Option A reverses the logic, attempting to use the general logger for structured data and the specific logger for scalars, which contradicts their design purposes. Option D correctly separates them: use the general logger (log_metrics) for the scalar F1 score and the specialized logger (log_classification_metrics) for the structured confusion matrix. This aligns with the SDK's best practices for maintaining clear, parseable experiment data in Vertex AI Experiments.
Official Reference
This link opens the official vendor documentation in a new tab.
Exam Strategy
When answering questions about Vertex AI SDK logging, always check the data type of the metric. If it is a simple number (scalar), use log_metrics. If it is a structure requiring labels (like a confusion matrix or ROC curve), use log_classification_metrics. Do not force structured data into the general logger, nor scalar data into the specialized classifier logger.
Frequently Asked Questions
Can I log a confusion matrix using aiplatform.log_metrics?
log_metrics is designed for scalar numeric values. A confusion matrix is a 2D structure that requires the semantic understanding of log_classification_metrics to be properly visualized and tracked in Vertex AI Experiments.Does log_classification_metrics support F1 scores?
log_metrics.Community Votes
50% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 23 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 23
-
b1a8fae 👍 8 Answered DI go with D. log_classification_metrics currently support confusion matrix and ROC curve. https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform#google_cloud_aiplatform_log_classification_metrics Because it is not explicitly mentioned in the docs of log_classification_metrics, I assume F1 Score must be logged with log_metrics. https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform#google_cloud_aiplatform_log_metrics (if accuracy and recall are logged in the example, probably F1 is done the same way)
-
fitri001 👍 7 Answered Baiplatform.log_classification_metrics is specifically designed for logging classification metrics, which includes F1 score and confusion matrix. aiplatform.log_metrics is a more generic function for logging any kind of metric, but it wouldn't capture the rich structure of a confusion matrix. Therefore, using aiplatform.log_classification_metrics allows you to log both F1 score and confusion matrix in a single call, simplifying your code and ensuring proper handling of these classification-specific metrics.
-
Omi_04040 👍 4 Answered DD. Utilize the aiplatform.log_metrics function to log the F1 score, and employ the aiplatform.log_classification_metrics function to log the confusion matrix. Utilize the aiplatform.log_metrics function to log the F1 score, and employ the aiplatform.log_classification_metrics function to log the confusion matrix. This is the correct approach. aiplatform.log_metrics is appropriate for logging general metrics such as the F1 score, and aiplatform.log_classification_metrics is ideal for logging classification-specific metrics like the confusion matrix. Reference: https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform#google_cloud_aiplatform_log_classification_metrics
-
b1a8fae 👍 4Option B also suggests sing aiplatform.log_classification_metrics for the confusion matrix. Which is supported, btw. https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform#google_cloud_aiplatform_log_classification_metrics
-
bobjr 👍 4 Answered Dhttps://cloud.google.com/vertex-ai/docs/experiments/log-data#classification-metrics log_classification_metrics -> only the confusion matrix, not the F1scores log_metrics -> any number you want -> you can use it to store a F1 scores
Show 18 more comments
-
qaz09 👍 3 Answered BIn this example linked below you can see that they use log_classification_metrics and the output contains both F1 score and confusion matrix. Hence I am voting for B. https://colab.research.google.com/github/whylabs/whylogs/blob/mainline/python/examples/integrations/writers/Writing_Classification_Performance_Metrics_to_WhyLabs.ipynb
-
gscharly 👍 3 Answered DAccording to docs, log_classification_metrics supports confusion matrix and ROC curve. Not sure if it means that it only supports those... Assuming those are the only ones supported, I would got with D
-
fitri001 👍 2While aiplatform.log_metrics can handle numeric values like F1 score, it wouldn't capture the complexity of a confusion matrix. Confusion matrix is a two-dimensional table and requires specific handling for proper logging.expand_more aiplatform.log_classification_metrics is designed for classification tasks and understands the structure of both F1 score and confusion matrix, allowing them to be logged efficiently in a single function call.
-
tardigradum 👍 2Hi fitri001. You are usually right but, I this particular case, I think D is the right answer. As you can see here in the link I provide you below, it "Currently support confusion matrix and ROC curve." Link: https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform#google_cloud_aiplatform_log_classification_metrics
-
Mohamed_Tareq 👍 2 Answered Df1 = f1_score(y_true, y_pred) aiplatform.log_metrics({ "f1_score_manual": f1 }) ========================================= with aiplatform.start_run("sklearn-model-eval"): aiplatform.log_classification_metrics( labels=["0", "1"], confusion_matrix={ "rows": cm.tolist() }, )
-
fitri001 👍 2Therefore, using separate functions like log_metrics for F1 score and log_classification_metrics for confusion matrix would be inefficient and might not capture the matrix structure accurately.
-
gscharly 👍 2forgot to add the link: https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform#google_cloud_aiplatform_log_classification_metrics
-
daidai75 👍 2 Answered BActually, the F1 score is calculated by the Precision and recall metrics. The the log_classification_metrics is OK for both confusion matrix and F1 score
-
pinimichele01 👍 2https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform#google_cloud_aiplatform_log_classification_metrics
-
YangG 👍 2 Answered Dd
-
Yan_X 👍 1 Answered BThe aiplatform.log_classification_metrics function is designed to log classification metrics, including the F1 score and the confusion matrix. It takes the following arguments: predictions: The predicted labels. labels: The true labels. weight: The weight of each sample. logger: The logger to use. ---------------------------- The aiplatform.log_metrics function is designed to log general metrics, such as accuracy, loss, and precision. It takes the following arguments: metric: The metric to log. value: The value of the metric. step: The step at which the metric was logged. logger: The logger to use.
-
pikachu007 👍 1 Answered BOption A: It's incorrect because aiplatform.log_metrics is a more general function that doesn't provide the same specialized structure for classification metrics. Option C: While technically possible to log both metrics using aiplatform.log_metrics, it's less optimal as it requires manual formatting and might not be as easily interpreted by Vertex AI's visualization tools. Option D: This is incorrect as it suggests using aiplatform.log_classification_metrics for the confusion matrix, but that function doesn't support logging confusion matrices directly.
-
joao_01 👍 1 Answered BGuys, Its b. Pls look at this link: https://www.youtube.com/watch?v=a_YXZ5UltkU In the minute 7:20 you'll see the result of the log_classification_metrics() and there (pay attention) its the F1. After, its shows the confusion matrix. You're welcome
-
pinimichele01 👍 1link?? i find only: https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform#google_cloud_aiplatform_log_classification_metrics so D NOT B
-
364db8d 👍 1 Answered DD is correct, F1 can be captured with log_metrics, but not with log_classification_metrics. You have to use 2 methods in this case.
-
omermahgoub 👍 1 Answered Baiplatform.log_classification_metrics to log metrics relevant to classification tasks, including F1 score and confusion matrix.
-
rajshiv 👍 1 Answered BI think we can log both metrics together. D is a close second but B seems to be a better answer
-
OpenKnowledge 👍 1 Answered DF1 score is not a classification matrix. So use aiplatform.log_metrics for logging F1 score
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All PMLE Questions
Access 65 questions with complete answers and detailed explanations.
View Full PMLE Practice Test →