Get Your CertDatabricks Certified Machine Learning ProfessionalPlayCompete
‹ All Databricks Certified Machine Learning Professional questions

Databricks ML Professional Practice Question 11: Custom pyfunc Wrapper

Databricks Certified Machine Learning Professional · Test 2 · question 1 of 10

Advanced MLflowmedium

A scikit-learn regressor is served behind a real-time endpoint. Before scoring, raw requests need a currency conversion applied to two fields; after scoring, predictions must be clipped to a non-negative range and rounded to cents. Today the calling applications do both steps, and three teams have drifted out of sync on the conversion logic. The team wants one deployable artifact that carries the logic, with no change to the wire format clients already send.

What should they do?

Select one answer
Show answer and explanation

Answer:

  • C. Subclass mlflow.pyfunc.PythonModel, apply both steps inside predict(), and log it with mlflow.pyfunc.log_model

A custom PythonModel is the supported way to package logic that is not part of the estimator itself. Its predict() method receives the raw request, so the conversion runs before the wrapped regressor is called and the clipping and rounding run after, with the fitted model carried in load_context or as a logged artifact. The result is one versioned pyfunc model: serving, spark_udf batch scoring and local testing all invoke the identical code path, which is what removes the three-way drift. Clients keep sending what they send today, because the wrapper defines the schema they were already targeting.

Option A leaves the logic in prose. Documentation does not execute, so each team still implements the conversion itself and the drift persists.

Option B fixes only half the problem and only for batch. Post-processing downstream cannot apply the pre-processing the model needs before scoring, and a real-time caller receives the unclipped value directly from the endpoint.

Option D misuses a routing setting. traffic_config splits requests between served model versions; it has no capacity to transform payloads.

Reference: MLflow PythonModel (custom pyfunc models)

Practice Test 2 ›

Study guides for Databricks Certified Machine Learning Professional