gistmax. Back to DiscoverStudio
Technology

Fix training and prediction using different feature scales

By Gistmax Tutorials · 2026-11-04

Machine learning: Fix training and prediction using different feature scales. Workflow: identify, diagnose, fix, verify.
Machine learning: Fix training and prediction using different feature scales. Workflow: identify, diagnose, fix, verify.

A trained model gives unreasonable predictions in the application even though the offline evaluation looked normal. The application sends raw values while training used scaled values.

Why this happens

A model expects the same transformation at prediction time that it saw during fitting. Fitting a fresh scaler on each request creates a different coordinate system.

Step-by-step solution

1. Trace one record through the training and serving paths. Compare feature order, units, missing-value handling and transformed values.

2. Package preprocessing and estimator in one pipeline. Persist the fitted pipeline rather than saving only the final estimator.

3. Call predict on raw records that match the documented schema. Never refit preprocessing on a single production request.

Worked example

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import Ridge
model = make_pipeline(StandardScaler(), Ridge())
model.fit([[1,10],[2,20],[3,30]], [2,4,6])
assert len(model.predict([[4,40]])) == 1

Verify the fix

The same fixture should produce matching predictions in the offline script and the deployed service within a defined tolerance. Check values before and after preprocessing when they differ.

Prevent a repeat

Version the complete inference contract and include a known-input smoke test with every model release.

Reference

Official documentation or standards guidance

An original Gistmax troubleshooting guide. Scenarios and sample values are illustrative; configuration depends on your software version and environment. Cover diagram: Gistmax Tutorials.

Join the conversation →