Tensorflow
Machine Learning
Model Evaluation
Overfitting
Prediction Accuracy

Tensorflow accuracy at .99 but predictions awful

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

When TensorFlow reports 0.99 accuracy but real predictions are poor, the model is usually optimizing the wrong thing for your problem setup. Accuracy alone can hide major failure modes.

Why this happens

1. Class imbalance

If 99% of samples are class A, a model that always predicts class A gets 99% accuracy while being useless for class B.

2. Data leakage

If training features include future information or label-derived signals, validation accuracy can look excellent but collapse in production.

3. Overfitting

The model memorizes training patterns and does not generalize to unseen examples.

4. Train/serve mismatch

Different preprocessing in training vs inference (normalization, tokenization, label encoding, image resize) causes bad live predictions.

5. Wrong threshold

For probabilistic classifiers, a default threshold of 0.5 may be suboptimal. Accuracy can look high while precision/recall for the target class is poor.

What to check first

  1. Inspect class distribution in train, validation, and test splits.
  2. Plot a confusion matrix, not just a single scalar metric.
  3. Report precision, recall, F1, and PR-AUC/ROC-AUC.
  4. Verify preprocessing parity between training and inference pipelines.
  5. Evaluate on a truly held-out dataset from the same production distribution.

Metric formulas (plain text)

  • Precision = TP / (TP + FP)
  • Recall = TP / (TP + FN)
  • F1 = 2 * (Precision * Recall) / (Precision + Recall)

TensorFlow-focused fixes

  • Use class weights: model.fit(..., class_weight=...)
  • Use stratified splits when possible.
  • Add regularization (dropout, weight decay) and early stopping.
  • Calibrate probability thresholds on validation data.
  • Use data augmentation only when it preserves label meaning.

Minimal diagnostic workflow

  1. Train baseline model and save per-class metrics.
  2. Generate confusion matrix on validation set.
  3. Tune decision threshold for target business metric.
  4. Re-run evaluation on held-out test set.
  5. Sanity-check with manual examples from production.

Summary Table

Problem AreaExplanationPotential Solutions
Class ImbalanceMajority class dominates, inflating accuracyClass weights, resampling, stratified split
OverfittingModel memorizes training dataDropout, regularization, early stopping
Data LeakageValidation contains leaked target signalRebuild splits/features, strict pipeline boundaries
Evaluation GapsSingle metric hides failure modesConfusion matrix, F1, PR-AUC, per-class metrics
Train/Serve DriftDifferent preprocessing at inference timeShared preprocessing code and parity tests

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.