Batch: Preparing a Scoring Script

Batch: Preparing a Scoring Script

Batch deployment runs the model against a complete input file or partition and writes predictions for later consumption. It's useful when a low-latency response is unnecessary and a scheduled job can process the available data together.

Separate the scoring steps

Turn the scoring notebook into a script with clear stages:

  • read the input data.
  • prepare the same features used during training.
  • load a specific model run or registered version.
  • calculate predictions.
  • write the output with the run identifier and model version.

The batch deployment checklist

The feature transformation used for scoring must match training. Reuse the serialized dictionary vectorizer or the complete model pipeline instead of rebuilding it with slightly different settings.

Load the model and write results

The sample code loads a model artifact from the configured object store path. The scoring function adds identifiers and timestamps. When actual durations are available, it also records the actual duration, predicted duration, and model version in the result frame.

Loading the model before applying it to a batch

Expose the input and output paths as parameters, then pass the year and month with the run ID as additional parameters.

Use the same script for a scheduled month or a historical backfill:

python score.py \
  --year 2023 \
  --month 3 \
  --run-id <mlflow-run-id>

The scoring script's output fields

Optional analytics

Optional analytics are off unless you allow them. Your choice does not affect access to DataTalks.Club, Slack, events, or courses.

Current choice: not chosen.

Privacy Policy

If you allow analytics, self-hosted Umami counts anonymous public pageviews without analytics cookies. Private account and learning pages are excluded. Read the Privacy Policy for the complete data boundary.