Foundations

Twelve Beginner Mistakes in Machine Learning and How to Catch Them

Twelve common errors in data handling, evaluation and training, each with a symptom to watch for and a concrete test that exposes it.

Key takeaways

  • A score that looks too good is a reason to search for leakage before you celebrate.
  • Fit every preprocessing step on training data only, ideally by putting it in a pipeline with the model.
  • Compare against a trivial baseline, using a metric that reflects the costs of the real decision.
  • Split by time or by group when examples are related, and use the test set only for the final report.
  • Reading individual wrong predictions finds problems that summary metrics hide.

Most beginner errors in machine learning do not crash the program. The code runs, a score appears, and the score is wrong or useless. The way to catch them is to test your pipeline deliberately, with a few cheap checks, before you trust any number it prints.

The twelve mistakes below are grouped by where they happen: framing, data handling, evaluation and training. Each comes with a way to detect it.

Four places to look for mistakes
1 Framing Baseline, metric, target 2 Data handling Leaks, splits, duplicates 3 Evaluation Test reuse, uncertainty 4 Training and use Sanity checks, serving parity Framing Baseline, metric, target 1 Data handling Leaks, splits, duplicates 2 Evaluation Test reuse, uncertainty 3 Training and use Sanity checks, serving parity 4

Framing mistakes

1. Skipping the baseline

A model with 94% accuracy sounds strong until you learn that 95% of the examples belong to one class. Before training anything, score a predictor that always outputs the majority class, or the mean for regression, plus a simple rule a domain expert would use. If your model barely beats these, you have learned something important. See why every project needs a simple baseline.

How to catch it: put the baseline in the same results table as every model.

2. Optimizing the wrong metric

Accuracy treats all errors as equal. Missing a failing machine and raising a false alarm rarely cost the same. For imbalanced classes, look at precision (the share of flagged cases that are real) and recall (the share of real cases that are flagged).

How to catch it: write down what happens after each type of error, then print the confusion matrix and check that your metric moves in the direction you care about.

3. Predicting a target that is only a proxy

You want to know who needs help, but you train on who received help in the past. The model then learns past decisions, including their gaps.

How to catch it: describe in one sentence how each label was produced, and ask who could be missing from it.

Data handling mistakes

4. Fitting preprocessing on all the data

If you compute means for scaling, fill missing values or select features before splitting, information from the test rows reaches training. Feature selection done this way can produce convincing scores on pure noise.

This script shows it. X has 100 rows and 5,000 columns of random numbers, and y is random too, so honest accuracy should hover around 0.5.

import numpy as np
from sklearn.feature_selection import SelectKBest, f_classif
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score
from sklearn.pipeline import make_pipeline

rng = np.random.default_rng(0)
X = rng.normal(size=(100, 5000))
y = rng.integers(0, 2, size=100)

X_bad = SelectKBest(f_classif, k=20).fit_transform(X, y)  # leak
bad = cross_val_score(LogisticRegression(), X_bad, y, cv=5)

pipe = make_pipeline(SelectKBest(f_classif, k=20), LogisticRegression())
good = cross_val_score(pipe, X, y, cv=5)
print(bad.mean(), good.mean())

The first number comes out far above chance. The second reflects the truth: there is nothing to learn. Pipelines in scikit-learn refit each step inside each fold for you.

How to catch it: replace the labels with shuffled labels and rerun the whole workflow. A score well above chance means something leaks.

5. Using features you will not have at prediction time

A column such as "account closure reason" predicts cancellation almost perfectly because it is filled in after the customer cancels. This is target leakage.

How to catch it: for each feature, ask when its value becomes known. Inspect any feature that dominates the model.

Several scans from one patient, or many sessions from one user, are not independent. A random split puts near-copies on both sides, and the model gets credit for recognizing the individual. With time series, random splitting lets the model learn from the future.

How to catch it: count how many group identifiers appear in both training and test sets. For forecasting, confirm that every training timestamp comes before every test timestamp.

7. Ignoring duplicates and labeling errors

Exact or near duplicates inflate scores when they cross the split. Wrong labels set a ceiling on measured performance and confuse training.

How to catch it: hash normalized rows to find repeats. Sort examples by loss and read the top 50; mislabeled items tend to collect there.

Evaluation mistakes

8. Tuning on the test set

Each time you look at the test score and change something, the test set becomes part of training. After many rounds, the score describes your search as much as your model.

The validation set (or cross-validation) is for choosing. The test set is for reporting.

How to catch it: keep a log of every test evaluation. If it has more than a few entries, treat the number as optimistic and, if you can, collect fresh data.

9. Trusting a single number without its uncertainty

On 200 test examples, an accuracy of 0.80 has a standard error of about √(0.8 × 0.2/200) ≈ 0.028. A competitor at 0.82 on the same sample size is well within the noise, although a paired comparison on identical examples can be more sensitive.

How to catch it: bootstrap the test set or repeat training with several seeds, and report the range.

10. Looking only at the average

A model can score well overall and fail badly for a rare product category, a particular camera or a smaller group of people.

How to catch it: compute the metric on slices that matter, with the count in each slice. Then do error analysis by hand on the mistakes. If the system affects people, such as in lending or hiring, a classroom model is not a validated one, and legal duties vary by place.

Training and deployment mistakes

11. Tuning before checking that training works

Beginners often start a large hyperparameter search while a bug sits in the data loader, such as labels misaligned with inputs.

How to catch it: train on ten examples and confirm the model can fit them almost perfectly. Print a few inputs with their labels right before they enter the model. Check that the initial loss is plausible: for a k-class classifier with roughly uniform outputs, natural-log cross-entropy should start near ln k, about 2.30 when k = 10.

12. Preprocessing differently in production

Training used one tokenizer, image resize method or unit of measure, and the serving code uses another. The model receives inputs it never saw.

How to catch it: send the same raw records through both code paths and compare the feature vectors value by value. After release, log input statistics and watch for changes.

How one suspicious score gets traced

Say you are predicting which loan applications in a practice data set will default, and your first gradient boosting model reports an AUC of 0.99. AUC is the chance that a randomly chosen positive example scores above a randomly chosen negative one, so 0.99 means almost perfect ordering. Few real outcomes are that predictable.

Start with feature importance. Suppose one column, the number of collection calls, dwarfs the rest. Importance only describes what the model uses, but it tells you where to look. Collection calls happen after a borrower misses payments, so the column encodes the answer.

Remove it and retrain. If the score drops to a believable level, you have found one leak. Then repeat the timing question for the next few strongest features, because leaks often travel in families: several columns filled in by the same downstream process.

Finally, check the split. If the same borrower appears in both parts, or if later applications train a model that is scored on earlier ones, fix that too. Each repair will usually lower the number. The lower number is the one you can build on.

A short audit to run every time

Before sharing a result, work through this list.

Check Passing result
Shuffled-label run Score falls to chance level
Ten-example overfit Training loss gets close to its minimum
Group and time overlap No shared groups; no future rows in training
Baseline comparison Clear margin beyond the noise
Feature timing Every input known at prediction time
Slice report No unexplained collapse in an important group

None of these takes long on a small project. Turn the ones you can into automated tests, so that a later change to the data code cannot silently reintroduce a problem.

Common questions

Which mistake is the most damaging?

Leakage, in many projects, because it makes every other decision rest on a false score. A weak but honest model can be improved. A leaked one often fails only after release.

Do these apply to deep learning and language models?

Yes. The forms change: test questions may appear in pretraining data, prompts may be tuned against the evaluation set, and image augmentations may be applied before duplicates are removed. The habit of asking where information could have traveled still works.

How do I know a score is too good?

Compare it with what a domain expert could achieve from the same inputs, and with earlier simple models. A sudden jump after adding one column or one data source deserves an investigation.

Written for 4MachineLearning with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 42 articles in Foundations →

Latest news on this topic