November 4, 2026 · krey

Understanding Overfitting, Underfitting and Model Evaluation

Model evaluation is the process of estimating how a method will behave on new data and whether that behaviour supports a decision. Overfitting and underfitting are not diagnosed by training score alone; they require a comparison between training and validation behaviour, a baseline and a sound split.

Underfitting and overfitting

Underfitting means the model cannot capture useful structure under the chosen representation or constraints. Overfitting means it captures noise or peculiarities that do not generalize. More parameters do not automatically improve a model. Data quality, feature design and evaluation often matter more.

Reliable splitting

Split before fitting learned preprocessing. Use stratification for many classification problems, groups when related observations must stay together, and chronological splits for time series. Keep the final test set untouched while choosing models and thresholds.

from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression

pipeline = Pipeline([
    ("imputer", SimpleImputer(strategy="median")),
    ("model", LogisticRegression(max_iter=1000)),
])
pipeline.fit(X_train, y_train)

The imputer is fitted inside the training workflow, so validation information does not determine its median. Compare against a simple baseline and evaluate with a metric connected to error cost.

Metrics and error analysis

Use MAE when absolute error is easy to interpret, RMSE when larger errors deserve more weight, and classification precision/recall when class costs are asymmetric. Inspect false positives, false negatives, residuals, calibration and subgroup performance. Cross-validation estimates variability but does not repair leakage.

Common mistakes and FAQs

Do not tune repeatedly on the test set, report only the best fold, oversample before splitting or call a higher training score success. Regularization, simpler features, more data and better labels can all help. Next read the Machine Learning Fundamentals course. Further reading: scikit-learn common pitfalls.