From demo to production with a predictive model

Picked by

· written by AI, fact-checked ·

How do you take a predictive model from a demo into production, meaning real day-to-day use? A predictive model is a program that learns from past data to forecast what will happen. The steps below draw on machine-learning documentation from Google, Feast and scikit-learn, and a research paper on how predictions can change outcomes. Every example is about late deliveries, and every case is made up rather than taken from a real deployment.

A model can score well on old records and still be hard to use at work. Its inputs may arrive too late, or it may predict a different outcome from the one the business cares about. Staff may also get its warning too late to act. Putting it into production involves checking for these problems and building a system that handles them.

The short version

  • A late-delivery system must warn someone early enough to act. Then it must wait to find out what happened.
  • Decide which promised date counts, how much delay counts as late, and when the prediction is made.
  • Train and test only on facts the system really had at prediction time. Using later facts gives the model clues in testing that it will not have in real use.
  • Judge the model only on orders whose outcome is known. Record what staff did after each warning, because their action can change the outcome.
  • Send only as many warnings as the team can act on, early enough to help. Check inputs straight away and results later, and have a fallback if scoring fails.

What counts as late?

An order can have several promised dates. There is the original promise to the customer, the supplier’s promise, a revised delivery date and an internal service deadline. Choose which promise the model should predict a failure to meet. Each choice answers a different question.

Suppose a planner moves the promised date after a delay becomes clear. The order may then count as on time against the new date. Yet it still missed the original promise. So training against the revised date can hide the very delays you wanted to predict.

That does not always mean the model learns whether someone changed a date. It depends on the model’s inputs and how you build the target, the outcome the model learns to predict.

Also decide how much delay counts, and when the system will make its prediction. Predicting any missed deadline is different from predicting a delay beyond an agreed margin. Predicting when the order is placed is different from predicting just before delivery, when more is known.

Write these choices down with the people who run the delivery process. Keep the date used to judge the outcome apart from later changes to the order. The one exception is when the stated goal is to predict how orders do against a revised promise.

Use only inputs that were known at the time

The inputs a model uses are called features. For a delivery model, they might be the carrier, the shipment’s current status, an estimated arrival date and the supplier’s past delivery record.

A copy of past records can hold facts that were added after the model would have made its prediction. An order table might hold the final delivery status. It might hold an arrival estimate that was fixed after a problem became obvious. A supplier’s on-time rate for a whole month can include deliveries that had not yet happened when an earlier order was scored (given a prediction).

Using those facts is called data leakage. In its test, the model gets clues it will not have when someone really needs a warning. Holding some rows back from training for testing does not fix this if those rows hold the same future facts.

Build each past example from the values known at its prediction time. This is called point-in-time correctness. History tables, records of changes and event logs (time-stamped lists of what happened) can help rebuild those values.

A feature store, a shared system that stores and serves model inputs, can also help. But it only helps if its timestamps and rules for fetching values show when each value became known.

For example, suppose a carrier scans a parcel in the morning. The scan reaches your system only after the model makes its prediction. The past example must leave the scan out, even though the scan had already happened. The time of an event and the time your system got the news are different.

Check how your tool handles data that arrives late or gets corrected. Feast’s documentation gives one example. It explains how Feast’s default point-in-time join works. The join matches each example with input values from the right moment. It limits values by their event timestamp, the time the event happened. But it can still return values that were corrected later.

For stores that support it, Feast offers an extra filter on a “created” timestamp. This works only if that timestamp records when the value became known.

If you cannot rebuild an input reliably, leave it out of the test on past data. Or start recording it from now on. Compare the features used in live predictions with those your training pipeline (the steps that prepare training data) produces.

If the system will predict future orders, also test it on later orders. Do not rely only on a random split, where test rows are picked at random from all the data.

Wait until the outcome is known

A label is the recorded outcome used to train or check the model. Here, it says whether the order missed the chosen deadline.

An open order with no “late” flag is not always an on-time delivery. Before its deadline, the result may still be unknown. Once the deadline passes with no delivery, it may already count as late, even though the shipment is still open.

When the label can be known depends on how the target is defined and how fast records arrive. Keep unsettled cases apart from confirmed outcomes. Decide how to handle cancellations, missing delivery records and orders still open after the reporting window.

If you skip this, the newest data can look unusually good. That is only because many failures have not been recorded yet.

Some targets judge each order over a fixed time window. For these, group predictions by the date they were made. These groups are often called cohorts. Only check groups whose outcome window and extra time for reporting have both passed. This stops older, finished orders being mixed with recent ones that are still unsettled.

Sometimes the target is the time until delivery. Then an order still not delivered when tracking ends is a censored record. You know it has not arrived yet, but not how long delivery will take in the end.

Survival methods, statistical tools built for “how long until something happens” data, can handle that unfinished record. Treating it as a finished, on-time case cannot.

The same wait limits experiments. You need enough settled outcomes to judge a change. Input checks and other early measures can help you find problems sooner. But they do not show whether the new model prevents late deliveries.

Record what people do after a warning

Suppose the model flags an order, marking it as likely to be late, and a planner speeds it up. The order arrives on time. From the final delivery record alone, you cannot tell whether the warning was wrong or the planner prevented the delay.

This is a feedback effect: the prediction leads to an action that changes the outcome. Retraining means building a new version of the model on newer data. Retraining on these outcomes without recording the actions can change what the next model learns.

It may learn that orders like the ones that were sped up successfully usually arrive on time. It may then give them lower scores. This is a risk. It will not happen on every retraining run.

A related problem is called selective labels. It happens when a decision controls which outcomes you get to see at all. For example, a rejected application may never produce the repayment record that an approved one would.

Changing a delivery outcome you can see is one problem. Hiding an outcome from view is a different one. Both make it harder to check the model.

Record the score, whether staff saw it, the action they took and the rule or threshold in use. A threshold is the score above which an order gets flagged. If actions are assigned at random, also record the chance of each action at the time.

These records help tell apart how well the model works from the effect of the intervention policy, the rules for acting on warnings.

Where it is safe and acceptable, a randomised test can estimate whether model-assisted work improves delivery results. A control group might carry on with the existing process, while the other group gets model warnings.

The test must allow for other actions people take, and for effects that spill over between the groups. Holding back a warning does not always create a group that gets no help.

Comparing periods that used the same intervention policy can also make results easier to read. On its own, though, it does not show what would have happened with no intervention.

Logging the chance of each action can support methods that estimate outcomes under a different policy. Those methods still rely on assumptions. They also need enough cases of each action being compared.

Fit the prediction to the work

Start with the person who will get the warning and the action they can take. Say speeding up an order needs three days’ notice. Then a warning one day before delivery is too late for that. Another action, such as telling the customer, may still be possible.

Choose when the system scores an order to suit that workflow. Then work out which features are available at that point. A model that relies on facts from dispatch (when goods are sent out) cannot support a decision made when the order is placed.

The team also needs a queue it can manage. Picture a made-up operation that can review fifty orders a day. Five hundred warnings would force staff to choose which ones to ignore.

So judge the model at the volume the team can handle. Also weigh the cost of acting when there was no need, and the cost of missing real delays.

Precision measures how many of the flagged orders meet the target. Recall measures how many of all the late orders the model flags. Both matter. But neither one alone tells you whether staff can act on the warnings well.

AUC measures how well the model ranks positive cases above negative ones across thresholds. Here, positive cases are late orders. AUC also does not tell you which cut-off suits the team’s workload.

Check calibration if you treat the scores as probabilities. A calibrated score should match how often the outcome really happens among similar predictions. Ranking orders well does not by itself make the probabilities reliable. Read calibration results with the actions taken after scoring in mind.

Decide what gets a score: an order line, a shipment or a customer. If several lines travel in one shipment, decide how their scores become one decision. Put the warning in the queue or planning screen where someone can use it. Do not leave it on a separate dashboard.

Staff may need useful facts next to the score, such as a missed dispatch step. A model explanation can show which inputs swayed the prediction. It does not prove what caused the delay, or show which action will work.

Check inputs now and outcomes later

Some checks can run as soon as a prediction is made. Watch for inputs that are missing or out of date, and unexpected changes in the mix of shipments. Also watch for shifts in scores, unusual volumes, and slow or failed requests.

These checks can reveal a broken data feed or a change in the conditions the system works in. They can do so before delivery outcomes arrive.

Once outcomes are ready, measure precision, recall and calibration for the right cohorts of predictions. Break results down where useful, such as by carrier or route. Check that each group has enough cases. Compare matching seasons, so a change in peak season is not simply blamed on the model.

Save the prediction time, input values, model version, threshold and whether the warning reached staff. Use a stable ID, one that never changes, to link that record to the final outcome and any action taken.

Not every response should wait for outcomes to get measurably worse. If an input feed breaks, fix it or switch to a fallback at once. If the business changes its delivery process, review whether the target and scoring policy still fit.

Retraining is one possible answer once a problem has been found. Others are fixing the data, changing the policy, or rolling back to the earlier model.

Plan for things going wrong

Before release, the team should be able to:

  • Rebuild a model from its training data, code, settings and feature definitions.
  • Trace a prediction back to the inputs and model version that produced it.
  • Respond as fast as the workflow requires, and have a clear plan for missing or out-of-date data.
  • Fall back to an agreed rule, a manual process or the previous model when scoring fails.
  • Test a proposed replacement on suitable data with known outcomes before putting it live.
  • Name who looks into alerts, who approves changes and who restores service.

Test those paths as well as the prediction itself. A useful release test follows one order all the way through. It goes through scoring, the staff workflow, any action taken and the final outcome record. It should show that the team can use the warning and later check what happened.

Sources