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?
Community Votes
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)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
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. Theaiplatform.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 genericlog_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 linkslog_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 →