Batch size and shuffling affect how well and how fast a model learns. The key metrics to watch are training loss and validation accuracy. A good batch size helps the model learn stable patterns, shown by smooth loss decrease. Shuffling helps the model see data in different orders, avoiding bias and improving generalization, seen in better validation accuracy.
Batch size and shuffling in PyTorch - Model Metrics & Evaluation
Batch size and shuffling do not directly change confusion matrix numbers, but they influence model quality which affects it. For example, a well-shuffled dataset with a good batch size might produce this confusion matrix:
| Predicted Positive | Predicted Negative |
|--------------------|--------------------|
| True Positive (TP): 85 | False Negative (FN): 15 |
| False Positive (FP): 10 | True Negative (TN): 90 |
This shows the model learned well, partly thanks to good batch size and shuffling.
Batch size and shuffling influence how well the model balances precision and recall. For example:
- Small batch size with shuffling can help the model learn subtle patterns, improving recall (finding more true positives).
- Large batch size might make training faster but less flexible, possibly lowering recall.
- Without shuffling, the model might see similar examples in a row, hurting both precision and recall.
Good shuffling and a balanced batch size help the model find the right balance between precision and recall.
Good:
- Training loss steadily decreases without big jumps.
- Validation accuracy improves and stays stable.
- Precision and recall are balanced and high.
Bad:
- Training loss jumps or oscillates wildly.
- Validation accuracy is low or drops after some epochs.
- Precision or recall is very low, showing poor learning.
- Model overfits or underfits due to poor batch size or no shuffling.
- Accuracy paradox: High accuracy with no shuffling might hide poor generalization.
- Data leakage: If shuffling is done incorrectly, test data might leak into training, inflating metrics.
- Overfitting: Large batch sizes can cause the model to memorize training data, seen as low training loss but poor validation accuracy.
- Underfitting: Too small batch size or no shuffling can cause unstable training and poor metrics.
Your model has 98% accuracy but only 12% recall on fraud cases. Is it good for production? Why not?
Answer: No, it is not good. The low recall means the model misses most fraud cases, which is dangerous. High accuracy can be misleading if the data is imbalanced. You need better shuffling and possibly a smaller batch size to improve recall.