Book a free call

Machine Learning Pitfalls: What Goes Wrong and How to Avoid It

Machine learning pitfalls are the quiet errors that make a model look good in testing and fail in production. Learn the eight most common and how to catch them.

Hertiv engineering teamReviewed by a senior engineer
6 min read
Machine Learning Pitfalls: What Goes Wrong and How to Avoid It
On this page

Short answer

Machine learning pitfalls are the quiet errors in how data is chosen, how a model is tested, and how success is measured. They make a model look good in testing and fail in production, because the test did not match real life. The most common are data leakage, a test set that does not match real users, and optimising the wrong metric.

What are machine learning pitfalls?

Machine learning pitfalls are errors that make a model look good in testing and fail in production. They are not coding bugs. They are mistakes in how the data is chosen, how the model is tested, and how success is measured, and they usually show up only after the model is live.

The pattern is the same every time: the test score is high, the team ships, and real users get worse answers than the test promised. The gap between the test and real life is where every pitfall lives.

The eight pitfalls teams hit most often are:

Pitfall What goes wrong How to spot it
Data leakage The answer hides in the training data Scores too good to believe
Test set mismatch The test looks nothing like real users Live results fall far below the test
Wrong metric The model solves the wrong problem High score, no business value
No baseline Nobody knows if the model helps Nothing to compare the score with
Dirty labels Wrong answers teach the model Errors cluster in one category
Overfitting the benchmark The model memorises the test Score drops on fresh data
Ignoring drift Behaviour changes, the model does not Slow decline over weeks
Skipping monitoring Failures go unnoticed for months No alerts, no owner, no checks

This guide walks through the three most common pitfalls in detail, then shows how to catch them before launch. The fixes are simple; the hard part is remembering to apply them before the model ships.

Data leakage: when the model sees the answer

Data leakage happens when information from the answer sneaks into the training data, so the model learns to read the answer instead of solving the problem. It is the most common pitfall, and the hardest to notice, because the test score looks excellent.

Three examples show the shape of it. A churn model trained on cancellation dates learns that a filled-in cancellation date means the customer left. A fraud model that sees the investigator's note learns to copy the investigator's verdict. A medical model that sees the treatment code learns which treatment was chosen, not which patient needed it. In each case the answer was in the input all along.

The fix is to check every input field and ask one question: would this be known at the moment the model has to decide? If the answer is no, the field must go. A second check is to split the data by time, not at random, so the test set looks like the future rather than a shuffled past. A leaked field usually reveals itself the moment the split is done by time.

A test set that does not match real life

A test set that looks like the training data but not like real users will flatter any model. Random splits are the usual cause: they mix easy and hard cases together, so the test hides the hard ones and the score looks better than it is.

Real life is messier. Users type with typos, send photos in bad light, and ask questions the training data never covered. A model tested only on clean data meets none of that until it is live, and the first week in production is when the gap shows up.

Build the test set from real cases, in the order they arrived. Hold out the most recent month, and include the awkward cases: the short messages, the rare categories, the customers who behave oddly. If the model survives that test, it has a chance in production. Model validation in machine learning covers the checks that turn a test set into a real trial.

Optimising the wrong metric

A model that scores well on the wrong metric is a model that solves the wrong problem. Accuracy is the usual trap: a model that predicts no fraud for every transaction is 99% accurate when fraud is 1% of transactions, and completely useless.

Pick the metric from the cost of being wrong. If missing a real case is expensive, measure recall, which is the share of real cases the model finds. If false alarms are expensive, measure precision, which is the share of flagged cases that are real. If both matter, measure both and look at the trade-off instead of a single number.

Write the metric down before training starts, and do not change it after seeing the results. Changing the target to fit the result is how a bad model gets shipped with a good score. Evaluating machine learning models explains which metric fits which kind of problem.

Example (hypothetical): a churn model that looked perfect

Example (hypothetical): a subscription business trains a churn model to spot customers who will leave. On the test set it scores 97%, getting 970 of 1,000 cases right, and the team ships it with confidence.

In production the model watches 1,000 customers, of whom 100 really leave. It flags 100 customers as likely to leave, but only 30 of them actually leave, and 70 of the real leavers were never flagged.

Its precision is 30 out of 100, or 30%, and its recall is 30 out of 100, or 30%. The 97% test score was a lie: the training data included the cancellation date, so the model had seen the answer.

After removing the leaked field and re-testing on the most recent month, the score falls to 82%, but the flagged list is honest, and the team can act on it. A lower honest score beats a higher false one, because only the honest one tells the team what will happen next.

How to catch pitfalls before launch

Catching pitfalls is a checklist, not a talent. Run it before the model ships, and most of the eight pitfalls show up while there is still time to fix them.

  1. List every input field and check it would be known at decision time. Any field that comes from after the event is a leak, and it must go.
  2. Split the test set by time, not at random. Hold out the most recent month, so the test looks like the future.
  3. Build a simple baseline first. A rule of thumb the model must beat clearly, so the team knows the model adds anything at all.
  4. Test on the awkward cases, not just the average ones. Short messages, rare categories and odd customers are where models fail first.
  5. Write the success metric down before training, and check it on real traffic for two weeks after launch. MLOps consulting covers the monitoring and rollout practices that keep this check running after launch.

Run the checklist on every model, even the small ones. The cost is an afternoon. The cost of skipping it is a model that fails in front of users, and a team that stops trusting its own tests.

What are the common mistakes?

The most common mistakes are skipping the baseline, testing on shuffled data, and changing the metric after seeing the results.

  • Skipping the baseline and trusting the first score. Without a simple rule to beat, any score looks good.
  • Testing on shuffled data instead of recent data. Shuffled tests hide the hard cases and the changes over time.
  • Changing the metric after seeing the results. The target should be fixed before training, not fitted to the outcome.
  • Shipping without a plan to watch the model live. Drift and failures are silent unless someone is watching for them.
  • Treating a vendor demo as proof the model works on your data. A demo runs on the vendor's data, not yours.

Each of these is easy to avoid with a checklist and a baseline. Teams that skip them usually blame the model, when the problem was the test. What machine learning is and how it works is the place to start for teams that want the basics before they build.

Key takeaways

  • Pitfalls live in the gap between the test and real life, not in the code.
  • Data leakage is the most common pitfall: check every field would be known at decision time.
  • Split the test set by time, not at random, so it looks like the future.
  • Pick the metric from the cost of being wrong, and fix it before training.
  • A lower honest score beats a higher false one.

Frequently asked questions

What is the most common machine learning pitfall?

Data leakage, where information from the answer sneaks into the training data. The model learns to read the answer instead of solving the problem, so the test score looks excellent and the live result fails. Check every input field against what would be known at decision time.

Why does a model score well in testing and fail in production?

Because the test did not match real life. Random splits mix easy and hard cases, clean test data hides the messy cases real users bring, and leaked fields inflate the score. Test on the most recent month, including the awkward cases.

What is the wrong metric problem?

It is optimising a number that does not match the business cost of being wrong. Accuracy is the usual trap: a model that predicts no fraud for every transaction is 99% accurate when fraud is 1% of transactions, and completely useless.

How do I build a good test set?

Hold out the most recent month of real cases, in the order they arrived, and include the awkward ones: short messages, rare categories and odd customers. Split by time, not at random, so the test looks like the future.

What is a baseline, and why does it matter?

A baseline is a simple rule of thumb the model must beat clearly, such as always predicting the most common outcome. Without one, the team cannot tell whether the model adds anything at all, and any score looks good.

How often should a live model be checked?

At least every quarter, and weekly in the first month after launch. Customer behaviour changes, and a model trained on last year's data slowly goes stale. A short review with the same data and the same test shows whether it still earns its keep.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building a machine learning model and want the test to match real life? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Machine Learning Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call