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.
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
Scoring isn't training
ReadBatch 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.
Which mean scales the new rows?
PredictPredict first
A model standardizes income during training. Tonight's batch comes from a wealthier region. Which mean is subtracted from tonight's incomes?
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.
The signature check
ReadBefore 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.
| Finding | Severity | What the model does |
|---|---|---|
| A feature's column is missing | Stops the run | Nothing: it can't score |
| Text in a numeric feature | Stops the run | Nothing |
| The table has no rows | Stops the run | Nothing |
| A category it never saw | Warning | Scores it with every indicator at zero |
| Numbers outside the training range | Warning | Scores them anyway |
| Far more missing values than in training | Warning | Handles them with its fitted rule |
| The target column is absent | Note | Nothing to fix: new rows don't have one |
Off the edge of the data
ExploreA 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?
Data
Model
k for neighbors, depth for trees, γ × 2 for the kernel, hidden units for the network.
Commit your prediction above to see the result
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.
Run the check
In the appIn 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.
Engine or SQL?
ReadThe 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.
Scores are data
ReflectEach 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?
Check your understanding
CheckpointCheck 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.
Do it on your own data
In the appScore 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.
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())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.
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