CertLumen

Databricks Machine Learning Associate · Section 4 · 12% of the exam

Use pandas to perform batch inference

One of the objectives of the Databricks Certified Machine Learning Associate exam, in the section “Model Deployment”. Here is what it covers, the points to remember and a question to try.

What it covers

Compare the three ways to deliver predictions on Databricks (batch, streaming and real-time) and pick the right one from latency, throughput and cost requirements. Then run batch inference with pandas: load a registered model by alias, score a pandas DataFrame, and scale the same pandas code across a cluster with spark_udf and mapInPandas.

Points to remember

  • Batch: scheduled, highest throughput, lowest cost, minutes to hours of latency; the most common and usually most cost-effective pattern.
  • Streaming: continuous or micro-batch scoring of arriving data with seconds to minutes of latency; Structured Streaming or Lakeflow Spark Declarative Pipelines.
  • Real-time: per-request REST calls to a Model Serving endpoint with millisecond latency; the most expensive per prediction.
  • Low latency but predictable inputs: precompute in batch and publish to an online store for lookups.
  • Load by alias for batch jobs: mlflow.pyfunc.load_model('models:/catalog.schema.model@champion').

Try a question

The model ml_prod.churn.churn_model was registered with a signature that lists tenure_months, plan and monthly_spend as required inputs. A batch job loads it with mlflow.pyfunc.load_model and calls predict() on a pandas DataFrame that has no monthly_spend column. What happens?

  1. AMLflow fills monthly_spend with 0 and returns a prediction for every row
  2. BMLflow ignores the signature during batch inference and passes the DataFrame to the model unchanged
  3. CMLflow drops the rows that lack the column and returns predictions for the others
  4. DMLflow's schema enforcement raises an error, because a required input column is missing
Show the answer

D. When a model has a signature, PyFuncModel.predict checks the input against it before calling the model, and a missing required column raises an MlflowException. This catches broken inference inputs before they produce silent garbage. Build the scoring DataFrame from the expected names, for example model.metadata.get_input_schema().input_names().

Written for practice in the style of the exam: never a question from the real exam.

In the course

The lesson Batch, Streaming and Real-Time Inference; Batch Scoring with pandas teaches this objective (about 40 minutes), and 11 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.

More in this section

← Previous objective · All 48 objectives · Next objective →