Is it possible to get prediction accuracy after call model.predict_classes?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Yes, but not from model.predict_classes() alone. Accuracy is not a property of predictions by themselves; it is a comparison between predicted labels and known true labels. So you always need the target values for the evaluation set, and in current Keras you should usually use model.predict() or model.evaluate() instead of the old predict_classes() helper.
Accuracy Needs Ground Truth
Suppose your model predicts classes for ten samples. Those predictions are only half of the information required. To compute accuracy, you must compare them against the real labels:
Without y_true, there is no accuracy value to compute. You can inspect predictions, but you cannot score them.
Why predict_classes() Is the Wrong Focus Now
Older Keras versions exposed model.predict_classes() as a convenience method. Modern Keras has standardized around model.predict(), model.evaluate(), and explicit post-processing of prediction outputs.
That is a better design because different models produce different kinds of outputs:
- Binary classifiers often produce probabilities from a sigmoid unit
- Multiclass classifiers often produce a softmax vector
- Regression models produce numeric values, not class labels
predict_classes() hid those differences behind a convenience API. In real evaluation code, you usually want to control how predictions are converted to final labels.
The Simplest Path: model.evaluate()
If your model was compiled with an accuracy metric, model.evaluate() is usually the easiest way to get loss and accuracy on a labeled dataset.
This is the direct answer when you already have x_test and y_test.
Manual Accuracy from model.predict()
If you want more control, use model.predict() and convert the output into labels yourself.
For binary classification:
This is conceptually what many older predict_classes() examples were doing behind the scenes.
Multiclass Example
For multiclass classification, the conversion step is usually argmax.
The key point is that the prediction format depends on the model output layer, but the final accuracy calculation is still "predicted labels compared with true labels."
Why Threshold Choice Matters
For binary classifiers, turning probabilities into class labels requires a threshold. Many examples use 0.5, but that is not always the right choice.
Fraud detection, anomaly detection, medical screening, and other cost-sensitive problems often need a threshold chosen from validation data rather than a hard-coded default.
That is another reason predict_classes() was limited: it hid a modeling decision that is often important.
Accuracy Is Not Always Enough
Even when you compute accuracy correctly, it may still be misleading. If one class dominates the dataset, a weak model can achieve high accuracy by predicting the majority class most of the time.
For a more realistic evaluation, consider additional metrics:
Precision, recall, F1, confusion matrices, and ROC-related metrics often tell a more useful story than accuracy alone.
Common Pitfalls
One common mistake is expecting predict_classes() to return an accuracy number. It never had enough information to do that without true labels.
Another issue is using argmax on binary sigmoid output. For binary probability vectors shaped as one column, thresholding is the correct operation, not argmax.
Developers also sometimes compare prediction arrays and label arrays with mismatched shapes, such as (n, 1) versus (n,). Flatten or reshape them consistently before scoring.
Finally, do not assume that the metric called "accuracy" in model.evaluate() is always the one you want. It depends on how the model was compiled and may not reflect business priorities.
Summary
- Accuracy requires both predictions and true labels.
- '
model.evaluate()is the easiest way to get accuracy if the model was compiled with that metric.' - In modern Keras, use
model.predict()and convert outputs to labels yourself instead of relying onpredict_classes(). - Use thresholding for binary outputs and
argmaxfor multiclass outputs. - Consider metrics beyond accuracy when class imbalance or cost asymmetry matters.

