The Central Idea

Model fitting balances two competing risks:

\[ \boxed{ \text{too little structure} \quad\longleftrightarrow\quad \text{appropriate structure} \quad\longleftrightarrow\quad \text{too much adaptation} }. \]

A model should be flexible enough to learn the signal and constrained enough to ignore unstable noise.

Generalization Is the Real Objective

Generalization is a model's ability to perform well on new cases drawn from the population and operating conditions of interest.

A model that explains its training sample beautifully but fails on new observations has not achieved the main predictive objective.

Training Error

Training error measures loss on the observations used to fit the model. For squared-error regression,

\[ \operatorname{MSE}_{\mathrm{train}} = \frac{1}{n_{\mathrm{train}}} \sum_{i\in\mathrm{train}} (y_i-\hat{y}_i)^2. \]

Training error describes in-sample fit. By itself, it does not estimate performance on unseen data.

Validation Error

Validation error measures loss on observations not used to estimate the fitted coefficients:

\[ \operatorname{MSE}_{\mathrm{validation}} = \frac{1}{n_{\mathrm{validation}}} \sum_{i\in\mathrm{validation}} (y_i-\hat{y}_i)^2. \]

It provides evidence about generalization and can guide choices such as polynomial degree, regularization strength, tree depth, or number of neighbors.

Test Error

A test set is reserved for a final evaluation after model design, hyperparameter tuning, and threshold selection are complete. Test performance estimates how the finalized workflow may perform on comparable unseen cases.

Using the test set to choose the model converts it into another validation set and makes the reported test error optimistic.

Underfitting

A model underfits when it is too restricted, poorly specified, or insufficiently trained to capture important structure. Typical signs include

Overfitting

A model overfits when it learns idiosyncrasies of the training sample that do not repeat. Typical signs include

An Appropriate Fit

An appropriately fitted model captures the stable predictive structure available in the data while controlling sensitivity to noise. It need not reproduce every training observation.

\[ \boxed{ \text{best training fit} \ne \text{best expected future performance} }. \]

The Model-Complexity Pattern

In nested model families fitted to minimize the same raw training loss, training error cannot increase as flexibility is added. Validation error often falls at first as underfitting is reduced, then rises when unstable adaptation begins.

The resulting validation curve is often U-shaped, but real curves can be noisy, flat, or more complicated.

Training and Validation Curves

Training and validation error across model complexity Training error decreases as model complexity increases. Validation error first decreases and then increases, reaching its minimum at an intermediate complexity. The left region is labeled underfitting and the right region is labeled overfitting. complexity error training validation underfitting overfitting selected region
Training error generally rewards added flexibility. Validation error identifies whether that flexibility transfers to new cases.

What Counts as Complexity?

Model family Typical complexity control
Polynomial regression Polynomial degree
Multiple regression Number and form of predictors
Nearest neighbors Smaller \(k\) is more locally flexible
Decision tree Depth, leaves, and minimum node size
Spline Knots or smoothing penalty
Neural network Architecture, weights, regularization, and training duration

Parameters and Effective Complexity

Counting coefficients is a useful first approximation, but it is not a universal measure of flexibility. Regularization can constrain a model with many coefficients, and structural restrictions can make some parameters behave as a smaller effective model.

Effective degrees of freedom, margins, tree structure, smoothness, and algorithmic stability may better describe operational complexity.

Hyperparameters

Model coefficients are estimated directly during fitting. A hyperparameter controls the fitting process or model family and is selected using validation evidence.

Examples include polynomial degree, ridge penalty \(\lambda\), tree depth, neighbor count \(k\), and number of boosting iterations.

Bias

Statistical bias describes systematic error in the average fitted prediction across repeated training samples:

\[ \operatorname{Bias} [\hat{f}(x)] = E[\hat{f}(x)]-f(x). \]

A rigid model can have high bias because its average prediction misses real structure.

Variance

Model variance describes how much the fitted prediction changes across repeated training samples:

\[ \operatorname{Var} [\hat{f}(x)] = E \left[ \left( \hat{f}(x)-E[\hat{f}(x)] \right)^2 \right]. \]

Highly flexible models can have high variance because small data changes produce large prediction changes.

Irreducible Error

Suppose

\[ Y=f(X)+\varepsilon, \qquad E(\varepsilon\mid X)=0, \qquad \operatorname{Var}(\varepsilon\mid X=x)=\sigma^2. \]

Even perfect knowledge of \(f\) cannot predict the future noise \(\varepsilon\). This irreducible component sets a lower bound on expected squared prediction error under the model.

The Bias–Variance Decomposition

At a fixed predictor value \(x\), under squared-error conditions,

\[ \boxed{ E \left[ \left( Y-\hat{f}(x) \right)^2 \right] = \operatorname{Bias}[\hat{f}(x)]^2 + \operatorname{Var}[\hat{f}(x)] + \sigma^2 }. \]

Added flexibility often reduces squared bias but increases variance.

The Bias–Variance Tradeoff

Model behavior Bias Variance Typical risk
Too rigid High Often low Underfitting
Balanced Controlled Controlled Better generalization
Too adaptive Often low High Overfitting

Underfitting as Misspecification

Underfitting is not limited to using too few coefficients. A model can be underfit because it uses the wrong response distribution, omits a key interaction, imposes constant variance, ignores dependence, or excludes essential predictive information.

Adding arbitrary complexity will not necessarily repair the specific misspecification.

Overfitting as Instability

Overfitting is closely connected to sensitivity. If replacing a few observations, changing a random seed, or slightly perturbing measurements produces very different predictions, the fitted pattern may be unstable.

Resampling and repeated validation can reveal this variability.

Polynomial Example

A straight line may underfit a curved relationship. Increasing the polynomial degree can capture curvature, but a high-degree polynomial may bend sharply through individual training observations and oscillate between them.

\[ \hat{y} = b_0+b_1x+b_2x^2+\cdots+b_dx^d. \]

The degree \(d\) is a complexity choice to validate, not a quantity to maximize.

Interpolation Is Not Automatically Generalization

A sufficiently flexible model may achieve zero training error by interpolating every training observation. This proves that the model can reproduce those observations; it does not prove that it has recovered the stable generating relationship.

Some modern interpolating models can generalize well because of regularization and algorithmic structure, so parameter count or zero training error alone is not a complete diagnosis. Unseen-data evidence remains decisive.

A Worked Model-Selection Example

Five polynomial models are fitted to the same training data and evaluated on the same untouched validation set:

Degree Training MSE Validation MSE Validation gap
1 \(25.0\) \(28.0\) \(3.0\)
2 \(12.0\) \(14.0\) \(2.0\)
3 \(6.0\) \(8.0\) \(2.0\)
4 \(3.0\) \(10.0\) \(7.0\)
8 \(0.2\) \(22.0\) \(21.8\)

Read the Worked Table

Training MSE decreases at every step. Validation MSE reaches its minimum of \(8.0\) at degree \(3\), then rises. The degree-\(1\) model underfits relative to the available alternatives. The degree-\(8\) model has excellent training fit but severe validation deterioration.

\[ \boxed{ \text{select degree }3 \text{ from these candidates} }. \]

The Generalization Gap

A simple descriptive gap is

\[ \boxed{ \text{generalization gap} = \text{validation error} - \text{training error} }. \]

In the worked table, the gap grows from \(2.0\) at degree \(3\) to \(21.8\) at degree \(8\). A large positive gap is evidence of poor transfer, though its magnitude also reflects sampling variability and the difficulty of the validation cases.

Do Not Select by the Gap Alone

A model can have a small generalization gap because both training and validation errors are high. That is underfitting, not success. Model selection should prioritize low, stable validation loss and relevant operational performance.

The Validation Minimum Is Uncertain

Validation error is an estimate based on a finite sample. The apparent best model may change under another split. Report uncertainty or repeated results when candidate performance is close.

Choosing the most complex model because its estimated error is lower by a negligible amount can amplify selection noise.

The One-Standard-Error Rule

One conservative strategy selects the simplest model whose estimated validation error is within one standard error of the minimum. If the minimum error is \(8.0\) with standard error \(0.7\), models with estimated error at most

\[ 8.0+0.7=8.7 \]

are eligible, and the simplest among them is selected. This rule favors stability when performance differences are not clearly resolved.

Learning Curves

A learning curve plots training and validation performance against training sample size. It helps distinguish several situations:

Residuals Can Reveal Underfitting

Curvature, group patterns, time dependence, or a changing spread in residuals can indicate that important structure is missing. These patterns are visible even on training data because a rigid model cannot represent them.

Residual diagnostics identify how a model fails; validation measures whether proposed changes improve transfer.

Training Residuals Can Hide Overfitting

An overfit model may leave tiny, patternless training residuals because it has adapted to those exact observations. Residual appearance on the training sample is therefore not sufficient evidence of good generalization.

Examine residuals and loss on data that did not guide the fit.

Sample Size and Complexity

The same model can be stable with a large, representative dataset and unstable with a small dataset. What matters is the information available relative to the model's effective complexity, noise level, predictor structure, and deployment diversity.

No universal observations-per-parameter rule replaces validation and subject-matter judgment.

High-Dimensional Predictors

When the number of candidate features is large relative to the sample, many accidental correlations become available. A search procedure can find combinations that appear highly predictive in-sample even when their relationships are unstable.

Regularization, dimensionality reduction, larger samples, and honest nested evaluation become especially important.

Noisy Features

Adding irrelevant predictors cannot improve the true signal, but it gives a flexible procedure more opportunities to fit noise. Their estimated coefficients or split importance may look meaningful merely by chance.

Feature inclusion should combine substantive plausibility with appropriately isolated validation.

Noisy Labels

Measurement errors, inconsistent human decisions, delayed outcomes, and ambiguous definitions can introduce label noise. A highly flexible model may memorize these irregularities.

Improving outcome definitions and audit procedures can create more value than increasing model complexity.

Data Leakage Mimics Success

Leakage occurs when training uses information unavailable at the intended prediction time or information from evaluation outcomes. It can make an overfit or invalid model appear extraordinarily accurate.

Repeated Search Creates Selection Overfitting

Even without direct leakage, testing hundreds of model variants on the same validation set can overfit that set. The winning validation score includes favorable random noise from the search.

Preserve an untouched final test set or use nested resampling when the search itself is extensive.

Regularization

Regularization adds a penalty for model complexity:

\[ \boxed{ \text{minimize} \quad \text{training loss} + \lambda(\text{complexity penalty}) }. \]

The tuning parameter \(\lambda\) controls the strength of shrinkage. Larger penalties usually increase bias and reduce variance.

Ridge Regression

Ridge regression minimizes

\[ \operatorname{SSE} + \lambda \sum_{j=1}^{p}\beta_j^2, \]

ordinarily excluding the intercept from the penalty. Ridge shrinks coefficients toward zero and can stabilize predictions when predictors are numerous or correlated.

Lasso Regression

Lasso regression uses an absolute-value penalty:

\[ \operatorname{SSE} + \lambda \sum_{j=1}^{p}|\beta_j|. \]

It can set some coefficients exactly to zero, combining shrinkage and feature selection. The selected variables can still be unstable when predictors are strongly related.

Standardize before Coefficient Penalties

Ridge and lasso penalties depend on coefficient scale. Predictors measured in different units are therefore commonly standardized using parameters learned from the training data.

Applying full-dataset means or standard deviations before splitting leaks evaluation information.

Tree Pruning

A deep decision tree can create small leaves tailored to individual training cases. Pruning removes weak branches or penalizes tree size, trading some training fit for greater stability.

Maximum depth, minimum leaf size, and cost-complexity penalties are validation-controlled hyperparameters.

Early Stopping

Iterative methods may first learn broad signal and later adapt to finer noise. Early stopping monitors validation performance and stops training before further iterations reduce training loss but damage transfer.

Because the validation set determines the stopping point, a separate test set is still needed for final evaluation.

Nearest Neighbors

In \(k\)-nearest-neighbor methods, small \(k\) creates a flexible local fit with potentially high variance. Large \(k\) averages over broader regions, increasing smoothness and potentially bias.

Predictor scaling and irrelevant dimensions strongly affect which cases count as neighbors.

Feature Engineering Can Reduce Underfitting

Useful transformations, interactions, lags, ratios, or domain-specific summaries can make stable structure easier for a model to learn. The value comes from representing the mechanism more appropriately, not merely from adding columns.

Every engineered feature must be computable at the intended prediction time.

Feature Selection Can Overfit

Selecting variables from the full dataset and then evaluating the chosen model on a held-out subset is not a valid holdout analysis. The outcome information already influenced the feature set.

Feature selection must occur inside each training split or resampling fold.

More Data Often Reduces Variance

Additional representative observations can make flexible models more stable and reduce overfitting. However, more rows do not repair biased measurement, data leakage, missing predictors, or a deployment population that differs from the training population.

Data Augmentation

In image, audio, and other structured applications, label-preserving transformations can expand the effective training sample. Augmentation should encode realistic invariances, such as small image translations when position should not change the class.

Unrealistic transformations can introduce bias rather than reduce overfitting.

Bagging and Random Forests

Bagging fits models to resampled data and averages their predictions. Averaging can reduce variance when component-model errors are not perfectly correlated. Random forests add randomized feature selection to diversify trees.

Ensembles still require honest validation and do not eliminate dataset shift or leakage.

Boosting

Boosting builds a sequence of models that focuses on previous errors. Learning rate, tree depth, and number of iterations control complexity. Too few iterations may underfit; too many can overfit, depending on the data and regularization.

Model Averaging

Combining diverse, reasonably accurate models can stabilize predictions. Averaging does not help when every model shares the same systematic misspecification, and optimizing ensemble weights on limited validation data can itself overfit.

Classification Overfitting

A classification model can overfit probabilities, rankings, labels, or all three. Evaluate unseen-data log loss and calibration as well as threshold metrics such as sensitivity, specificity, precision, and accuracy.

Accuracy alone can hide overfitting to the majority class.

Threshold Selection Can Overfit

Searching many probability thresholds and reporting the best one on the same data produces an optimistic metric. Select the threshold on validation data using documented costs or constraints, then evaluate the finalized policy on untouched test data.

Calibration Can Deteriorate

Highly flexible classifiers may produce probabilities near \(0\) or \(1\) for patterns supported by few training cases. These confident estimates can be poorly calibrated on new data.

Evaluate reliability plots, Brier score, or log loss on unseen cases and recalibrate only within a valid data-splitting workflow.

Use the Right Validation Boundary

Random row splitting can conceal overfitting when related observations appear on both sides of the split. The evaluation boundary should match deployment:

Distribution Shift Is Not Ordinary Overfitting

A model may be properly controlled for the development population and still fail when the deployment distribution changes. This is a transport or dataset-shift problem, although its symptoms resemble poor generalization.

Validation must represent the intended operating conditions, and postdeployment monitoring remains necessary.

Subgroup Performance

Overall validation error can conceal underfitting in one region and overfitting in another. Examine relevant groups, predictor ranges, and operational contexts while reporting sample sizes and uncertainty.

Repeatedly optimizing to noisy subgroup estimates can also overfit, so subgroup analysis needs predefinition and adequate data.

Prediction Intervals Reflect Model Fit

Underfitting can leave systematic residual structure, while overfitting can underestimate future error if uncertainty is computed as though a selected model were fixed. Prediction intervals should be evaluated for empirical coverage on unseen data.

Narrow intervals are not an asset when they systematically miss.

Interpretability and Complexity

Simpler models are often easier to audit and explain, but simplicity does not guarantee truth. A simple linear model can be misleading if the relationship is strongly nonlinear or interactive.

Choose the simplest model that adequately supports the predictive and governance requirements—not the simplest model available.

Prediction Is Not Causation

A model may generalize well for prediction while its coefficients have no causal interpretation. Conversely, a causal model may prioritize identification and uncertainty rather than the lowest predictive loss.

Model complexity control does not replace study design, intervention definition, or confounding control.

Inference after Model Selection

Confidence intervals and \(p\)-values calculated after data-driven variable or model selection can be too optimistic if they ignore the selection process. Predictive validation and conventional coefficient inference solve different problems.

Prespecified models, sample splitting, selective-inference methods, or resampling of the complete workflow may be needed.

Reproducibility

Record data versions, split logic, random seeds, preprocessing steps, candidate models, hyperparameter ranges, metrics, and selection rules. Reproducibility makes it possible to distinguish genuine improvement from a favorable one-time run.

Deployment Monitoring

After deployment, track

Define ownership, alert thresholds, rollback procedures, and retraining criteria before performance deteriorates.

A Practical Model-Complexity Workflow

  1. Define the prediction target, future population, loss, and constraints.
  2. Create a validation design that reproduces the deployment boundary.
  3. Build a transparent baseline model.
  4. Specify a limited, justified range of candidate complexity.
  5. Fit every preprocessing step using training data only.
  6. Compare candidates on validation performance and stability.
  7. Inspect residuals, calibration, and subgroup behavior.
  8. Prefer the simpler candidate when performance is practically tied.
  9. Lock the workflow and evaluate once on untouched test data.
  10. Monitor generalization after deployment.

Reporting Checklist

Common Error: Choosing the Lowest Training Error

Training error usually rewards flexibility. It cannot determine whether the added structure will repeat on new data. Use validation evidence for complexity selection.

Common Error: Calling Every Poor Model Overfit

Poor validation performance can result from underfitting, leakage, shift, weak features, noisy labels, or an inappropriate loss. Overfitting is specifically poor transfer caused by excessive adaptation to the training information.

Common Error: Adding Complexity without Diagnosis

If residuals show a missing threshold, add a feature that represents the threshold. If variance changes, model the variance. Arbitrary complexity can hide the symptom without representing the mechanism.

Common Error: Simplifying without Validation

Reducing parameters can decrease variance but increase bias. A simpler model should still be evaluated against the same decision-relevant validation standard.

Common Error: Reusing the Test Set

Each test-guided revision transfers information from the test set into the model-development process. After repeated reuse, the score no longer represents an untouched evaluation.

Practice 1: Identify Underfitting

A straight-line model has high training error, high validation error, and a clear U-shaped residual pattern. What is the likely problem?

Practice 2: Identify Overfitting

A model has training MSE \(=0.4\) and validation MSE \(=18.0\). Small changes to the training sample produce very different predictions. What does this evidence suggest?

Practice 3: Calculate a Generalization Gap

A model has training error \(5.5\) and validation error \(9.2\). Find the descriptive generalization gap.

Practice 4: Select from the Worked Table

Which polynomial degree in the worked table has the smallest validation MSE, and why is degree \(8\) not preferred?

Practice 5: Apply the One-Standard-Error Rule

The minimum cross-validated error is \(12.0\) with standard error \(0.8\). Candidate A is simpler with error \(12.6\); candidate B is more complex with error \(12.0\). Which candidate does the one-standard-error rule prefer?

Practice 6: Diagnose Leakage

An analyst standardizes all predictors using the complete dataset and then creates training and test sets. What is wrong?

Practice 7: Choose a Regularization Direction

A flexible regression has a large validation gap and unstable coefficients. What effect would increasing a well-chosen regularization penalty generally have on bias and variance?

Practice 8: Read Learning Curves

Training and validation errors are both high, close together, and nearly flat as more observations are added. What response is more promising than merely collecting more of the same data?

Practice 9: Protect the Test Set

A team evaluates twenty model revisions on the test set and reports the best score. Why is the final score optimistic?

Practice 10: Separate Prediction and Causation

A well-validated model predicts customer churn from service calls. A manager concludes that preventing one service call will reduce churn by the fitted coefficient amount. What is missing?

Practice Answers

Practice 1

The evidence indicates underfitting or mean-structure misspecification. A straight line cannot represent the observed curvature. A justified nonlinear feature or model should be evaluated.

Practice 2

The very low training error, much larger validation error, and prediction instability are classic evidence of overfitting.

Practice 3

\[ 9.2-5.5=3.7. \]

Practice 4

Degree \(3\) has the smallest validation MSE, \(8.0\). Degree \(8\) reduces training MSE to \(0.2\) but raises validation MSE to \(22.0\), indicating poor generalization.

Practice 5

The eligibility threshold is

\[ 12.0+0.8=12.8. \]

Candidate A has error \(12.6\), so it is within one standard error of the minimum. The rule prefers the simpler candidate A.

Practice 6

The test-set predictor distribution influenced the scaling parameters. Fit the standardization on the training data and apply those stored parameters unchanged to the test data.

Practice 7

Increasing the penalty generally increases bias and reduces variance. The penalty strength should be selected through valid training and validation, not assumed.

Practice 8

The pattern suggests underfitting. Improve the model representation, features, measurement, or loss before assuming that more comparable rows will solve the problem.

Practice 9

The test set influenced model selection twenty times. The winning score benefits from favorable test-set noise and no longer represents a final untouched evaluation.

Practice 10

Predictive validity does not identify the causal effect of changing service calls. The intervention, time order, confounders, selection process, and causal assumptions require separate analysis.

What to Remember

Where We Go Next

Detecting overfitting requires performance evidence from observations that did not determine the fitted model. That separation must be designed carefully because every modeling choice can transfer information across the boundary.

The next lesson, Training and Validation Data, develops holdout sets, cross-validation, structured splits, leakage prevention, and final test-set governance in greater detail.