How to Develop a Custom AI Model: From Data to Production
Follow a delivery-delay example from data preparation and model selection to training, testing, explainability, APIs, integration, and monitoring.
· TankDev Mühendislik
Developing a custom AI model means designing a system that learns from data for a specific business problem, evaluating it, and making it work inside a real process. The lifecycle covers data collection and preparation, model selection, training, validation and testing, explainability, an API, integration, and production monitoring. Its value emerges when that chain supports a better decision.
“Custom” does not necessarily mean training a large language model from scratch. A delivery-delay predictor trained on a company's orders is also a custom model. Some problems call for adapting an existing model; others can be solved by supplying relevant information to a model without training it at all.
We will follow an illustrative distributor that wants to identify orders at risk of arriving late. The goal is to help operations choose which orders to investigate. This is a worked scenario, not a client case study or a claim about measured results.
Figure 1. What happens in production becomes input to the next version.
1. Define the decision before choosing the model
“Predict delays” leaves several important questions unanswered. Will the prediction run when an order is placed or the day before dispatch? Is a delay measured against the original promised delivery date? Who will act on an alert, and what can they change?
For this scenario, let the prediction run when the order is confirmed. The target is delivery after the original promised date. Operations reviews flagged orders and checks stock availability and dispatch plans. That defines both the information available to the model and the purpose of its output.
Set the success criteria here: how many late orders can the team identify within its daily review capacity? What does a false alarm cost, and what does a missed delay cost? These answers will help determine the decision threshold later.
2. Collect and prepare data: What did we know at prediction time?
Orders, stock movements, warehouse workload, and delivery outcomes may live in different systems. Joining them requires more than a shared order identifier: preserve when each fact was valid.
Attaching today's stock level to an order placed six months ago misrepresents the past. Using a shipping complaint filed after the order gives the model information from the future. This is data leakage: the model appears successful in evaluation because it uses clues that will not be available when a real prediction is needed.
Make the preparation rules explicit:
- Source and meaning: Does “delivery date” mean the planned date or the actual arrival date?
- Labels: How will cancelled and undelivered orders be handled? An unknown outcome is not an on-time delivery.
- Quality: How will duplicates, missing fields, inconsistent units, and incorrect joins be resolved?
- Coverage: Are seasons, warehouses, and uncommon order types represented?
- Access: Which fields are necessary, who may access them, and how long should they be retained?
Split the data into training, validation, and test sets before fitting learned transformations such as scaling, imputation, or feature selection. Fit those transformations only on training data, then apply them to the other sets. This separation is a central recommendation in the scikit-learn guide to common pitfalls.
3. Select a model that meets the need
Start with a baseline, a simple reference solution. An existing rule might flag every order with a stock shortage. Without measuring whether machine learning improves on that rule, its additional complexity is difficult to justify.
For structured order data, logistic regression and tree-based models are reasonable candidates. Image and text tasks may benefit from adapting a pretrained model. Selection depends on data availability, latency, running cost, and maintenance capacity as well as predictive performance.
For language-model projects, distinguish two approaches. Retrieval-augmented generation (RAG) retrieves relevant documents and supplies them as context at answer time; it does not change model weights. Fine-tuning updates weights using examples. Answering questions from current company documents and learning a particular output format or task behaviour are different needs. Evaluate the options on examples of the actual task.
4. Train a reproducible experiment
Training allows the model to learn patterns between inputs and the target. The deliverable, however, includes more than a model file. Record the data version, preparation code, feature definitions, parameters, and execution environment.
For example, changing how warehouse workload is calculated can change predictions even if the model file stays the same. Version preprocessing together with the model. Experiment records should answer: “Which data and code produced this result?”
Select hyperparameters using validation data. If training performance improves while validation performance deteriorates, the model may be fitting the historical examples too closely. More training does not automatically produce better generalisation.
5. Validate and test against realistic future use
The training set supports learning; the validation set supports model and threshold selection; the test set provides an independent evaluation after those choices are complete. Repeatedly adjusting the model after looking at test results turns the test set into another tuning tool.
For delivery delays, a chronological split can be more realistic than a random split. Training labels must also have become available by the simulated evaluation date. Keep lines from the same order in one split. If the goal is performance on new customers, evaluate a customer-based split as well.
In a hypothetical dataset where only 5% of orders are late, predicting “on time” for every order achieves 95% accuracy while identifying no delays. Examine these measures together:
- Precision: Of the flagged orders, how many were actually late?
- Recall: Of all late orders, how many did the model identify?
- Review workload: How many orders per day does the selected threshold send to operations?
The scikit-learn precision-recall example illustrates the trade-off. Choose a threshold on validation data using business costs and review capacity rather than automatically using 0.5. Inspect results by warehouse, season, and order type: a good overall average can hide a weak segment.
6. Explainability: Make the basis of a prediction visible
Explainability helps investigate how inputs influence model output. Global analysis examines the model's broader behaviour; local analysis examines the factors contributing to an individual prediction.
Methods such as SHAP can help examine contributions from stock shortages or warehouse workload. A contribution to a prediction does not prove what caused a delay. “The model uses this information” and “changing this field will prevent the delay” are different claims. The SHAP discussion of causal interpretation explains this limitation.
Connect the explanation to a useful action: “Stock shortage and warehouse workload increase this score; check the dispatch plan.” Evaluate calibration before presenting a score as a probability. An output of 0.8 does not, by itself, establish that 80% of comparable orders will arrive late.
7. API: Turn the model into a defined service
If predictions are needed online, expose the model through an API. The request contract should define field names, types, units, required values, and invalid-input behaviour. Training and serving must use consistent preprocessing.
Return the prediction together with a model version, request identifier, and prediction timestamp. If missing data prevents a prediction, say so explicitly; returning “low risk” would mislead operations. Authentication, authorisation, request-size limits, timeouts, and logs that avoid sensitive data are part of the service.
Not every problem needs an immediate API call. If operations uses a list each morning, a batch prediction job may be sufficient. The timing of the decision should guide the architecture.
Figure 2. Prediction, decision policy, and human intervention have separate responsibilities.
8. Integrate the prediction into an existing workflow
Adding a risk field to an ERP is only the beginning. Decide who sees flagged orders, how review status is stored, and how work continues if the prediction API is unavailable.
Start in shadow mode if appropriate: generate predictions on real orders without changing the workflow. Once data access and response times have been verified, introduce the model to a limited group of users or warehouses. Keep a tested route back to the previous version.
If a prediction creates a work item, a repeated request must not create another copy. Separate the model output from the business rule: the model supplies a score, while operational policy determines which scores require review.
9. Monitor usefulness as well as service availability
Production monitoring must answer three questions: Is the service available? Has incoming data changed? Are predictions still useful? Errors and latency address the first; missing fields and distribution changes address the second; predictions compared with actual outcomes address the third.
A change in input distribution is called data drift. A change in the relationship between inputs and the target may be concept drift. A drift alert does not establish a performance drop on its own. Investigate whether the cause is a broken data pipeline or a change in business conditions.
Delay labels only become available once delivery outcomes are known. Join those outcomes back to stored predictions. Record interventions too: a delay prevented because operations acted on an alert can look like a false alarm in a naive evaluation. Assess predictive performance and the effect of intervention separately.
Monitoring, data validation, and controlled retraining are part of the production approach described in Google Cloud's MLOps guide. Instead of automatically publishing a new model whenever an alert fires, define the owner, investigation step, and conditions for reevaluation.
What makes the first version ready for production?
It should have been compared with a baseline, independently tested, exercised under failure conditions, and connected to observable outcomes. Users should understand its recommendation; maintainers should know which version is running and how to roll it back.
The most valuable result is a system whose supporting evidence is understood, whose mistakes can be detected, and whose behaviour can be improved—not merely a high test score.