Skip to content

Batch scoring: the training recipe on new rows

Scoring reuses the preprocessing fitted during training and checks new rows against the version's signature first. Learn what stops a run, what only warns, and when SQL can do the scoring.

Applied ~11 min10 steps

You will be able to

  • Explain why scoring reuses fitted preprocessing instead of fitting it again
  • Sort signature findings into those that stop a run and those you must read
  • Choose between the engine and SQL scorers

Read first

01

Scoring isn't training

Read

Batch scoringBatch scoringRunning a model over a whole table of new rows and saving the predictions with the version that made them. runs a saved model over a table of new rows and writes the predictions to a new dataset.

Most decisions can wait for a batch: tonight's churn list, this month's forecast of renewals. It's simpler than a live service, and every prediction is kept with the version that made it.

The one rule that matters: new rows get the preprocessing fitted during training, saved in design.json. Nothing is fitted again.

02

Which mean scales the new rows?

Predict

Predict first

A model standardizes income during training. Tonight's batch comes from a wealthier region. Which mean is subtracted from tonight's incomes?

The new batch's own meanThe training rows' meanAn average of the two
Reveal

The training mean. The model learned its coefficients on that scale. If you rescaled each batch by its own mean, a wealthier region would look average, and the model would score it as if nothing had changed. A batch's scores would also change depending on which other rows happened to be in it.

03

The signature check

Read

Before scoring, the app compares your table with the version's input signatureInput signatureThe features a version expects, with each one's kind, training range or levels, and share of missing values.: the features it expects, with kinds, ranges and levels.

FindingSeverityWhat the model does
A feature's column is missingStops the runNothing: it can't score
Text in a numeric featureStops the runNothing
The table has no rowsStops the runNothing
A category it never sawWarningScores it with every indicator at zero
Numbers outside the training rangeWarningScores them anyway
Far more missing values than in trainingWarningHandles them with its fitted rule
The target column is absentNoteNothing to fix: new rows don't have one
04

Off the edge of the data

Explore

A warning isn't a refusal, so a model will give an answer for rows unlike anything it saw.

DExplorable · Decision boundary zoo

What shapes of boundary can each kind of model draw?

Which model will score highest on new data from this shape?

How sure?

Data

Model

5

k for neighbors, depth for trees, γ × 2 for the kernel, hidden units for the network.

0.20
150
Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Pick a data shape, and look at the corners of the plot, where there are no training rows. Every model still colors them in. Switch between models and watch those regions change, with no row there to say which one is right.

That's what an out-of-range warning is telling you. The number you get back looks the same, but no data supports it.

05

Run the check

In the app

In Models, open a version's Score data tab and choose a dataset ({{dataset}} in the walkthrough). Press Check the data first, and read each finding.

Then choose where the predictions go, A new dataset or A new version of this one, and press Score.

The result names the new columns and adds a drift summary. Next to the predictions, a version with a predictive SD or a saved conformal calibration adds <name>_pred_sd, <name>_pred_lower and <name>_pred_upper, or <name>_pred_set, where <name> is the prediction column. The next lessons explain how to read the drift summary.

06

Engine or SQL?

Read

The Scorer menu offers two routes:

  • The training engine, Python or R, handles any model.
  • DuckDB SQL handles linear models and single trees. The preprocessing is written into the query, so it needs no Python or R, and it can run wherever DuckDB can.

The app's tests check that SQL scores match the engines' scores, so your choice is about speed and portability.

07

Scores are data

Reflect

Each batch appears on the Scoring history tab: when it ran, which data went in, where the scores went, which scorer ran, how many rows, and whether drift was found.

Imagine a customer asks, six months from now, why they got a given score. What would you need to answer them? Which of those things does the history keep, and which would you have to keep yourself?

08

Check your understanding

Checkpoint

Check yourself

A new table is missing one feature's column, and another feature has a category the model never saw. What happens?

Show the answer

Answer: a

Without a column there's nothing to score from. An unseen category can still be scored, as all-zero indicators, so you get a warning and a decision to make.

Check yourself

Your scoring table has no target column. Is that a problem?

Show the answer

Answer: b

Scoring only needs the features. When outcomes arrive later, a monitor can use them to measure performance.

Check yourself

Which model can be scored with DuckDB SQL here?

Show the answer

Answer: a

SQL scoring covers linear models and single trees. Ensembles use the training engine.

09

Do it on your own data

In the app

Score a table that has real differences from the training data, and read what the check reports. To score outside the app, open the Export tab and export a Python scoring script or R scoring script. Each comes with the model files and a README, reads input.parquet, and writes scores.parquet.

Python
import subprocess
import sys

import pandas as pd

# In the exported folder, with your new rows saved as input.parquet.
pd.read_csv("new_rows.csv").to_parquet("input.parquet")
subprocess.run([sys.executable, "score.py"], check=True)
print(pd.read_parquet("scores.parquet").head())
R
library(nanoparquet)

# In the exported folder, with your new rows saved as input.parquet.
write_parquet(read.csv("new_rows.csv"), "input.parquet")
system2("Rscript", "score.R")
head(read_parquet("scores.parquet"))

The Python script needs the codesplash helper and the model's packages, and the R script needs codesplashr. The README lists them.

10

Recap

Recap
  • New rows get the preprocessing fitted in training, never a new fit.
  • A missing column or non-numeric text stops the run. Unseen categories and out-of-range numbers warn, and the model answers anyway.
  • SQL scoring covers linear models and single trees; the engine handles everything.
  • Scores are saved with the version that made them, so you can answer questions later.

Concepts in this lesson