Chevron left
Guides

Build a Constrained ML Deployment from a Measurable Baseline

Follow a worked ticket-routing baseline through approved data, leakage-aware evaluation, packaging, deployment and operating recovery.
by

Reviewed and updated October 8, 2026. Prepared and maintained by ALLTIPLY.

Build the simplest measurable machine-learning system that can support the task, then add complexity only when evidence justifies it. Constraints include data rights, review capacity, latency and maintenance as well as compute. Open-source software or inexpensive infrastructure does not remove those obligations.

This guide uses an illustrative ticket-routing baseline. It proposes a category for a human reviewer; it does not close a ticket, contact a customer or make an employment or eligibility decision. No real customer dataset or measured performance result is supplied.

1. Define the task and baseline

Write the categories, ambiguous-case rule and completed outcome. Compare with the current manual route and a simple keyword rule. Record the consequence of a missed or incorrect route. Google's Rules of Machine Learning supports starting with a simple model and a working pipeline rather than treating model complexity as the goal.

2. Prepare an approved dataset

Use records whose processing and retention are permitted. For this example, a CSV has ticket_id, customer_group, text and label. Review labels with task owners, inspect disagreements and remove unnecessary sensitive fields. Keep a provenance record and a version of the dataset; a pseudonymous group identifier is not a guarantee of anonymity.

Check repeated and near-duplicate tickets. The illustrative split below separates customer groups because closely related tickets can otherwise appear on both sides. If the use predicts later periods, add time-aware evaluation. Group splitting alone does not reproduce future conditions or guarantee balanced categories.

3. Fit preprocessing only on training data

The baseline was functionally smoke-tested on synthetic data with Python 3.14.6, pandas 2.3.3, scikit-learn 1.8.0, NumPy 2.4.2 and SciPy 1.17.0. This checks execution, not representative accuracy or production fitness. These are the tested environment versions, not a claim that they are the latest releases. One way to prepare an isolated environment is:

python3.14 -m venv .venv
.venv/bin/python -m pip install pandas==2.3.3 scikit-learn==1.8.0 numpy==2.4.2 scipy==1.17.0
.venv/bin/python baseline.py

Save the code below as baseline.py and place approved_tickets.csv beside it. The CSV requires nonempty text, unique ticket identifiers, nonmissing group and label fields, and multiple labels in training. The group identifier controls the split and is not a model input. This tiny synthetic sample shows the shape only; it is insufficient for a meaningful performance estimate:

ticket_id,customer_group,text,label
ticket-a-1,group-a,Invoice amount disputed,billing
ticket-a-2,group-a,Shipment tracking missing,delivery
ticket-b-1,group-b,Payment invoice question,billing
ticket-b-2,group-b,Parcel delivery delayed,delivery

Use a representative approved dataset for evaluation. Review class coverage, duplicates, languages and the split assumptions before interpreting the report. The scaffold is not a production service.

import pandas as pd
from sklearn.model_selection import GroupShuffleSplit
from sklearn.pipeline import make_pipeline
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report

# Approved, labeled records only. One row per ticket.
df = pd.read_csv("approved_tickets.csv")
required = ["ticket_id", "customer_group", "text", "label"]
assert df[required].notna().all().all()
assert df["ticket_id"].is_unique
assert df["text"].str.strip().ne("").all()
split = GroupShuffleSplit(n_splits=1, test_size=0.25, random_state=7)
train, test = next(split.split(df, groups=df["customer_group"]))
assert set(df.iloc[train]["customer_group"]).isdisjoint(
    set(df.iloc[test]["customer_group"]))
assert df.iloc[train]["label"].nunique() > 1
assert set(df.iloc[test]["label"]) <= set(df.iloc[train]["label"])
# Review duplicates and near-duplicates before accepting this split.
model = make_pipeline(TfidfVectorizer(), LogisticRegression(max_iter=1000))
model.fit(df.iloc[train]["text"], df.iloc[train]["label"])
predicted = model.predict(df.iloc[test]["text"])
print(classification_report(df.iloc[test]["label"], predicted,
                            zero_division=0))

scikit-learn's common-pitfalls guidance warns against fitting preprocessing on evaluation data. The pipeline fits its vocabulary on the training partition. Keep a separate final test for later model selection, and do not repeatedly tune against the report shown here.

4. Review errors before choosing a model

Inspect each category's missed and incorrect routes, relevant languages and unusual inputs. Check the distribution of test cases and category coverage. Compare with the rule baseline and manual process on the same work. A high aggregate score can conceal a consequential failure.

Use review rather than unsupported automatic action. Define an ambiguous or unsupported-input path and test it separately; the scaffold above does not implement abstention. Treat confidence values as scores needing task-specific evaluation, not as verified certainty.

5. Package and deploy the whole workflow

Record dependency versions, code revision, dataset version, label definitions and evaluation evidence. Package the approved model with input validation, access controls and a narrow interface. Keep source data and credentials out of the application artifact unless explicitly required and protected.

Compare batch processing with a service using actual workload, peaks, latency and operating costs. Managed or serverless infrastructure is not always cheaper. Evaluate startup behavior, service limits, dependency availability and support responsibilities before selecting it.

Build a workload-to-cost envelope

For an illustrative planning envelope, evaluate 2,000 and 10,000 tickets per month, including expected peaks. These are scenario inputs, not buyer thresholds or a claimed workload. Compare a scheduled batch, if the task permits delayed routing, with an always-available service. Measure runtime and memory on representative records rather than extrapolate from the tiny sample.

  • Compute or managed usage: execution hours × contracted compute rate, or billable operations × the applicable contracted unit rate. Use the charging model of the chosen option rather than count the same capacity twice.
  • Storage and transfer: retained dataset/model/log GB-month × the relevant rate, plus measured transfer and any fixed service charges.
  • Human review: cases reviewed × minutes per case ÷ 60 × an approved loaded labor rate. Include declined cases, corrections and reconciliation.
  • Operation: support and evaluation hours × their approved rates, plus monitoring, backup and other recurring charges.
  • Monthly cost: compute/usage + storage/transfer + human review + operation. Lifecycle cost: initial build and integration + the sum of monthly costs over the stated period.

Record the source of each rate and vary volume, review time and support effort. A no-change or rule-based path needs its own comparable cost. Do not call modeled labor-equivalent capacity a realized cash saving. Select an option only after checking quality, workload and ownership alongside this envelope.

6. Monitor and restore

Track failures, input changes, reviewed outcomes, latency, recurring cost and exception load. Assign an owner who can pause predictions and restore manual routing or a previous approved version. Reproduce the release and test restoration before operating it.

Do not retrain simply because a calendar date arrives. Investigate whether a changed source, label definition or workflow caused degradation, then evaluate any replacement. Keep a release record that explains what changed and why.

The delivery record

A useful handoff contains the approved task boundary, data handling, baseline, split rationale, error review, artifact versions, deployment configuration, operating owner and fallback. Explanations and anonymization techniques can support review; neither establishes blanket legal compliance. The result should be a maintainable task capability with visible limits, not an inexpensive prototype described as enterprise-ready.

Bring the decision into a project review

Bring the prediction task, permitted dataset and operating constraints. A review can define a baseline and deployment that your team can maintain. Explore ALLTIPLY AI development, or book a call to discuss the workflow, systems and constraints you need to assess.

Continue Reading