model.predict_classes is deprecated - What to use instead?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
model.predict_classes() was removed because it bundled prediction and label-decoding into one opinionated helper. Modern Keras expects you to call model.predict() and then decide how to turn raw outputs into labels based on the model's output layer and your task.
Why predict_classes() Went Away
The old helper looked convenient, but it quietly assumed too much:
- binary classification should use a threshold of
0.5 - multiclass classification should use
argmax - the caller always wants class labels rather than scores
Those assumptions are not always correct. Some applications need:
- custom thresholds
- top-k predictions
- calibrated probabilities
- multilabel outputs instead of single-class outputs
So Keras removed the convenience method and left the interpretation step in user code, where it can be reviewed and customized.
The Modern Replacement Pattern
The replacement is always some version of:
- run
model.predict(...) - inspect the output shape and activation
- convert outputs into labels explicitly
For binary classification with a sigmoid output:
For multiclass classification with a softmax output:
Those two patterns cover most migrations from predict_classes().
Binary, Multiclass, and Multilabel Are Different
The correct replacement depends on model semantics, not just on Keras version.
Binary classifier
Typical shape:
- '
(batch, 1)or(batch,)'
Typical conversion:
Multiclass classifier
Typical shape:
- '
(batch, num_classes)'
Typical conversion:
Multilabel classifier
Here argmax is wrong, because more than one label can be true.
but applied per output unit, not as a single winner-takes-all decision.
That is exactly why the old helper became too limited.
Keep the Probability Output
A major advantage of the new style is that you still have the scores after prediction.
From there you can:
- compute confidence
- inspect uncertainty
- tune thresholds on validation data
- produce top-k candidates
Example top-3 classes:
That was awkward with predict_classes() because the probabilities were already discarded.
Migrating Legacy Evaluation Code
A lot of older code looked like this:
Modern equivalent for a softmax classifier:
If y_true is one-hot encoded, decode it first:
Always make sure your label format and prediction format match before computing metrics.
Write a Small Helper if You Miss the Old Convenience
If you want the older convenience back, create your own utility rather than relying on a removed framework API.
This keeps your project code short while preserving explicit rules.
The important part is that the decoding behavior now belongs to your codebase, not to a hidden default inside Keras.
Common Pitfalls
- Replacing
predict_classes()blindly without checking whether the model is binary, multiclass, or multilabel. - Applying
argmaxto a sigmoid output. - Hardcoding a
0.5threshold when the application needs a tuned decision threshold. - Comparing one-hot targets against integer predictions without decoding first.
- Throwing away probabilities too early when later evaluation still needs them.
Summary
- '
predict_classes()was removed because it hid task-specific label-decoding logic.' - Use
model.predict()and decode outputs explicitly. - Threshold sigmoid outputs for binary or multilabel tasks.
- Use
argmaxfor softmax multiclass outputs. - Keep probability outputs available when you need confidence, calibration, or top-k behavior.

