AI & Machine Learning · reviewed in July 2026
Overfitting
Overfitting happens when a model learns the training data in so much detail — including its noise and quirks — that it loses the ability to generalize to new data it hasn't seen. It shows up when a model performs very well on training data but much worse on test data.
from sklearn.metrics import accuracy_score model.fit(X_train, y_train) print(accuracy_score(y_train, model.predict(X_train))) # 0.99 print(accuracy_score(y_test, model.predict(X_test))) # 0.68 <- overfitting
Frequently asked questions
How do you detect overfitting?
By comparing the model's performance on the training data against its performance on a separate test set it never saw during training; a large gap between the two is the classic signal.
How do you fight overfitting?
With more training data, with regularization techniques that penalize model complexity, by simplifying the model, or by stopping training before it starts memorizing instead of learning general patterns.
What is underfitting?
It's the opposite problem: the model is too simple to capture the real pattern in the data, and performs poorly on both training and new data.