Why my keras code doesn't show the accuracy value?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
If your Keras model training output shows loss but not accuracy, the most common cause is not including metrics=['accuracy'] in the model.compile() call. Keras only tracks and displays metrics that are explicitly specified at compilation time. Other causes include using the wrong metric name for your task, using a custom training loop that does not log metrics, or running an older Keras version with different metric naming. This article covers all the reasons and fixes.
Cause 1: Missing metrics in model.compile()
metrics=['accuracy'] tells Keras to compute and display accuracy after each epoch.
Cause 2: Wrong Metric Name
Keras automatically selects the right accuracy variant when you pass 'accuracy' as a string, but using the explicit class avoids ambiguity.
Cause 3: Regression Task (Accuracy Does Not Apply)
Accuracy compares predictions to labels for exact equality. For regression, use MAE, MSE, or RMSE instead.
Cause 4: Custom Training Loop Without Metric Tracking
Cause 5: Verbose Setting
Viewing Accuracy History
Common Pitfalls
- Forgetting
metrics=['accuracy']incompile(): This is the most common cause. Without explicitly requesting accuracy, Keras only computes and displays the loss function. Always pass the desired metrics list. - Using
'accuracy'for regression tasks: Accuracy measures exact match between predicted and true values. For continuous regression outputs, accuracy is always near zero. Use'mae'or'mse'for regression tasks. - Recompiling the model without metrics after loading: Loading a saved model with
tf.keras.models.load_model()restores metrics, but if you callmodel.compile()again withoutmetrics, the previously saved metrics are lost. - Confusing
'acc'with'accuracy': Older Keras versions (pre-2.3) used'acc'as the metric key inhistory.history. Modern Keras uses'accuracy'. Check your version ifhistory.history['accuracy']raisesKeyError. - Not including validation data:
val_accuracyonly appears if you passvalidation_dataorvalidation_splittomodel.fit(). Without it, only training accuracy is shown.
Summary
- Add
metrics=['accuracy']tomodel.compile()— this is the fix for most cases - Keras auto-selects the right accuracy variant (binary, categorical, sparse) based on the loss function
- Do not use accuracy for regression — use MAE, MSE, or RMSE instead
- Custom training loops must manually track metrics using
tf.keras.metricsclasses - Access accuracy history via
history.history['accuracy']andhistory.history['val_accuracy'] - Set
verbose=1orverbose=2inmodel.fit()to see metric output during training
Related reading
- Why no weight decay on the convolutional layers in the cifar10 example of tensorflow?
- Why not use Flatten followed by a Dense layer instead of TimeDistributed?
- Why Pearson correlation is different between Tensorflow and Scipy
- why set return_sequencesTrue and statefulTrue for tf.keras.layers.LSTM?
- Why my Model has a low MAE and low R2 score at the same time?
- Why neural network predicts wrong on its own training data?
- Why Neo4J docker authentication doesn't work
- Why node.js async module stops after the first step using async.eachLimitarray, limit, function, callback?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.