How to Deploy Scikit-Learn Models on Vertex AI with Minimal Code?

You have recently trained a scikit-learn model that you plan to deploy on Vertex AI. This model will support both online and batch prediction. You need to preprocess input data for model inference. You want to package the model for deployment while minimizing additional code. What should you do?

  1. 1. Upload your model to the Vertex AI Model Registry by using a prebuilt scikit-ieam prediction container.
  2. 1. Wrap your model in a custom prediction routine (CPR). and build a container image from the CPR local model. Source Reference Answer
  3. 1. Create a custom container for your scikit learn model.
  4. 1. Create a custom container for your scikit learn model.

Community Votes

B
100%

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

Community Insight

This question tests understanding of Vertex AI serving frameworks, where candidates often mistakenly prioritize prebuilt containers over CPR, overlooking that CPR natively supports custom inference logic with significantly reduced boilerplate.

Deploying machine learning models on Vertex AI requires selecting the right serving abstraction to balance customization and development overhead. Community consensus confirms that Custom Prediction Routines (CPR) provide the most efficient path for handling pre- and post-processing without writing a full HTTP server.

Candidates frequently select Option A, assuming prebuilt containers minimize effort, but they fail to recognize that prebuilt images cannot accommodate the required custom data preprocessing steps.

Community Discussion (7 comments)

shadz10 👍 5 Selected: B
B - Creating a custom container without CPR adds additional complexity. i.e. write model server write dockerfile and also build and upload image. Where as using a CPR only requires writing a predictor and using vertex SDK to build image. https://cloud.google.com/vertex-ai/docs/predictions/custom-prediction-routines
desertlotus1211 👍 1 Selected: A
you want to minimize code... all other you need code...
bobjr 👍 1 Selected: B
https://cloud.google.com/vertex-ai/docs/predictions/custom-prediction-routines
gscharly 👍 1 Selected: B
agree with shadz10
guilhermebutzke 👍 1 Selected: C
My choose: C Option C ensures that the scikit-learn model is properly packaged, deployed, and integrated with Vertex AI services while minimizing the need for additional code beyond what is necessary for customizing the serving function. Option B is not considered correct because it suggests wrapping the scikit-learn model in a custom prediction routine (CPR), which might not be the most suitable approach for deploying scikit-learn models on Vertex AI. Options A and D using InstanceConfig, that is limited for preprocessing. Uploading the container without a serving function won't work.
pikachu007 👍 1 Selected: D
Considering the goal of minimizing additional code and complexity, option D - "Create a custom container for your scikit-learn model, upload your model and custom container to Vertex AI Model Registry, deploy your model to Vertex AI Endpoints, and create a Vertex AI batch prediction job that uses the instanceConfig.instanceType setting to transform your input data" seems to be a more straightforward and efficient approach. It involves customizing the container for the scikit-learn model, leveraging the Vertex AI Model Registry, and utilizing the specified instance type for batch prediction without introducing unnecessary complexity like custom prediction routines.
b1a8fae 👍 4 Selected: B
I go with B: “Custom prediction routines (CPR) lets you build custom containers with pre/post processing code easily, without dealing with the details of setting up an HTTP server or building a container from scratch.” (https://cloud.google.com/vertex-ai/docs/predictions/custom-prediction-routines). This alone makes B preferable to C and D, provided lack of complex model architecture. Regarding A, pre-built containers only allow serving predictions, but not preprocessing of data (https://cloud.google.com/vertex-ai/docs/predictions/pre-built-containers#use_a_prebuilt_container). B thus remains the most likely option.

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

Custom Prediction Routines (CPR) are explicitly designed to simplify model serving by allowing developers to define custom Predictor classes that handle input parsing, preprocessing, model invocation, and output serialization. By leveraging the Vertex AI SDK, you can automatically generate the underlying container image, which eliminates the need to manually write Dockerfiles or configure HTTP servers. This approach directly satisfies the requirement to preprocess data while minimizing additional code.

Why the Other Options Are Wrong

Option A relies on prebuilt containers, which offer zero flexibility for custom preprocessing or postprocessing logic. Options C and D involve building entirely custom containers from scratch, requiring manual setup of web servers, dependency management, and Docker configuration. These methods introduce significant boilerplate and maintenance overhead, contradicting the exam constraint to minimize additional code.

Community Comment Notes

Multiple high-voted comments validate Option B, emphasizing that CPR abstracts away complex serving infrastructure while still supporting custom Python code [1][2]. Users note that while prebuilt containers seem simpler initially, they become impractical when preprocessing is mandatory [3]. The provided documentation links consistently point to Vertex AI official guidance, confirming CPR as the standard for lightweight custom serving [4].

Official Reference

Exam Strategy

When Vertex AI questions mention preprocessing, postprocessing, or lightweight custom inference logic, immediately consider Custom Prediction Routines (CPR). Always weigh the minimize code constraint against the flexibility needed; if you do not need a completely new framework, CPR is almost always the exam preferred answer.

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