Artificial intelligence • Original RRTutors lesson
Overfitting, Underfitting, and Generalization
Diagnose models that memorize training examples or fail to capture useful patterns.
Concept and explanation
Overfitting occurs when a model fits idiosyncrasies in training data and performs worse on new examples. Underfitting occurs when the model or features cannot capture the relevant pattern. Regularization, more representative data, simpler models, and sound validation can help, but should be guided by learning curves and error analysis.
How to apply it
Compare training and validation performance, inspect errors by slice, and change one modeling assumption at a time.
Worked example
A high-degree polynomial can match every training point yet oscillate sharply between observations.
Illustrative Python example
train_error = 0.02
validation_error = 0.28
if validation_error > train_error:
print("Investigate overfitting or a split mismatch")
Expected result
A large train-validation gap is a warning signal, not a complete diagnosis.
Limitations and cautions
A distribution shift or flawed split can mimic overfitting; regularization alone may not fix it.
Practice exercise
Sketch learning curves for underfitting and overfitting and suggest one intervention for each.
Key takeaway: Generalization must be measured on data representative of future use.