How to log F1 score and confusion matrix in Vertex AI?
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 exam tests the distinction between logging scalar metrics and classification artifacts, where the trap is assuming the classification-specific function handles all metric types.
When logging metrics in Vertex AI, use the generic aiplatform.log_metrics function for scalar values like the F1 score, and the specialized aiplatform.log_classification_metrics function for structured artifacts like the confusion matrix.
Common mistake: Selecting Option B because it assumes 'log_classification_metrics' handles all classification data, failing to recognize that F1 is a scalar metric that requires the generic 'log_metrics' function.
Expert Analysis
Why the Answer Is Correct
Option D is the correct choice because the Vertex AI Python SDK distinguishes between simple scalar metrics and complex classification artifacts. The aiplatform.log_metrics function is designed for logging single numeric values, such as the F1 score, accuracy, or precision. Conversely, aiplatform.log_classification_metrics is specifically built to accept structured data objects like confusion matrices and ROC curves, which allows Vertex AI to render them visually in the console.
Why the Other Options Are Wrong
Option A is incorrect because the confusion matrix cannot be effectively logged or visualized using the generic log_metrics function, which expects scalar values. Option B is incorrect because while log_classification_metrics sounds comprehensive, it is strictly intended for visualizable artifacts (ROC/Confusion Matrix) and does not accept scalar F1 scores directly. Option C is incorrect because although you can log numbers with log_metrics, it lacks the necessary schema to generate the confusion matrix visualization required for comparison.
Community Comment Notes
The community consensus strongly supports Option D, with top-rated comments citing official documentation that explicitly links log_classification_metrics to confusion matrices and ROC curves. Users noted that since F1 scores are not mentioned in the context of that specific function, they must be logged as general metrics. Some users argued for Option B based on the semantic meaning of 'classification metrics', but the technical implementation of the SDK requires the separation found in Option D.
Official Reference
- https://cloud.google.com/vertex-ai/docs/experiments/log-data#classification-metrics
- https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform#google_cloud_aiplatform_log_classification_metrics
These links open the official vendor documentation in a new tab.
Exam Strategy
Differentiate between scalar metrics (like accuracy or F1) which use log_metrics, and visual artifacts (like confusion matrices or ROC curves) which require log_classification_metrics or similar specialized functions.
Community Votes
67% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 11 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 11
-
b1a8fae 👍 6 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)
-
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
-
Omi_04040 👍 3 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
-
fitri001 👍 3 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.
-
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
Show 6 more comments
-
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
-
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.
-
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
-
YangG 👍 2 Answered Dd
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 →