How to log F1 score and confusion matrix in Vertex AI?

You want to migrate a scikit-learn classifier model to TensorFlow. You plan to train the TensorFlow classifier model using the same training set that was used to train the scikit-learn model, and then compare the performances using a common test set. You want to use the Vertex AI Python SDK to manually log the evaluation metrics of each model and compare them based on their F1 scores and confusion matrices. How should you log the metrics?

  1. Use the aiplatform.log_classification_metrics function to log the F1 score, and use the aiplatform.log_metrics function to log the confusion matrix.
  2. Use the aiplatform.log_classification_metrics function to log the F1 score and the confusion matrix.
  3. Use the aiplatform.log_metrics function to log the F1 score and the confusion matrix.
  4. Use the aiplatform.log_metrics function to log the F1 score: and use the aiplatform.log_classification_metrics function to log the confusion matrix. Source Reference Answer

Community Votes

D
67%
B
33%

67% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

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.

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.

Community Discussion (11 comments)

b1a8fae 👍 6 Selected: D
I 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)
Omi_04040 👍 3 Selected: D
D. 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
rajshiv 👍 1 Selected: B
I think we can log both metrics together. D is a close second but B seems to be a better answer
YangG 👍 2 Selected: D
d
bobjr 👍 4 Selected: D
https://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
fitri001 👍 3 Selected: B
aiplatform.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 Selected: D
According 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
omermahgoub 👍 1 Selected: B
aiplatform.log_classification_metrics to log metrics relevant to classification tasks, including F1 score and confusion matrix.
Yan_X 👍 1 Selected: B
The 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.
daidai75 👍 2 Selected: B
Actually, 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
pikachu007 👍 1 Selected: B
Option 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.

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

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

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.

Related Analysis

Practice All PMLE Questions

Access 65 questions with complete answers and detailed explanations.

View Full PMLE Practice Test →

← Back to PMLE Study Guide