The Chartership Forum

Computational Engineering / AI and machine learning for structural engineers

Overfitting and generalisation

Separate fitting, selection and final evaluation.

Lesson review: expert verification remains open

This lesson has received a full-context editorial review and a check of its technical explanations. Selected arithmetic has been checked separately. This is not independent engineering sign-off.

Checks needed for project use

  • A computational engineering reviewer must check algorithms, convergence claims, statistical assumptions and numerical examples beyond the cases explicitly recorded.
  • Reproduce seeded learning experiments and label model-selection data as validation, retaining an independent test procedure.
  • Obtain qualified review for legal responsibility statements; this is not a legal opinion.
  • Review domain guards and calibration before any real engineering use.
  • Specialist statistical review remains required for representative data, leakage, validation strategy, uncertainty and deployment monitoring.

These are educational models and exercises. Check their assumptions before using the results. The full technical content and every diagram have not yet been independently verified.

Concrete and steel calculations retain their stated first-generation Eurocode teaching basis. Use the standards and amendments specified for your project; do not mix generations without an appropriate design basis.

Read the lesson register and outstanding review notes

Why this matters

A flexible curve can fit training points closely while predicting new points poorly. Separate the evidence used to fit, choose and evaluate the model.

By the end of this lesson you should be able to

  • Explain why training error falls with every added parameter
  • Read the point where test error turns round
  • Explain the role of a held-back test set
  • Recognise the engineering analogue in curve-fitting practice

A flexible curve can follow noise between samples

A flexible curve can follow noise between samplesThe blue low-order reference and orange oscillatory curve illustrate different flexibility around fixed sample positions. This illustration is not a fitted data experiment; use the lab for computed training and validation errors.Training fit and new-data predictionInput
The blue low-order reference and orange oscillatory curve illustrate different flexibility around fixed sample positions. This illustration is not a fitted data experiment; use the lab for computed training and validation errors.

Increase the illustrated curve’s oscillation between fixed samples.

Illustrative fit flexibility. Geometry and movement are schematic; use the lesson calculations for numerical results.

Samples
A small training residual is evidence about fitted observations.
Between samples
Evaluate predictive error on representative data not used to choose the configuration.

Compare prediction outside the fitting data

Training adjusts parameters to reduce a chosen loss. A more flexible nested model family can attain no larger minimum training loss, but an actual numerical routine may not reach that minimum. A small training error alone says little about performance on new cases.

Use validation data or cross-validation to compare configurations. Fit preprocessing only on the relevant training subset. Once validation results influence the degree or settings chosen, they are part of model selection; reserve independent test evidence or use a suitable nested procedure for the final estimate.

Inspect residual patterns, sample coverage and numerical conditioning. Higher-degree polynomial normal equations can become ill-conditioned even when the data are sufficient in count. A training/validation gap can also reflect distribution shift or data errors, so investigate its cause.

Try it

Overfitting explorer

Fit polynomials to synthetic observations of a straight line. Compare error on the fitting data with error on separate validation data.

Compare coverage and sample count. Degree is capped at training count minus one to avoid a non-unique unregularised fit.

Horizontal axis: x →

Blue points: synthetic training observations. Solid orange line: fitted polynomial at the selected degree.

Horizontal axis: degree →

Solid blue: training error. Dashed orange: validation error.

Degree selected
3

4 parameters

Training error
0.6990
Validation error
1.4310
Validation / training ratio
2.0

No universal acceptable ratio; inspect absolute errors, data coverage and intended use.

Best degree by validation error
3
Points needed to fit exactly
12

degree 11 has one parameter per point

This is the best degree by validation error. Note that the data came from a STRAIGHT LINE — the best model on a finite noisy sample is not necessarily the true one.

What to try

  • Push the degree to 10 and watch the training error collapse while the validation error rises. A model chosen on training error alone would pick this.
  • Set the noise to zero. The two curves converge, because there is no noise for the extra parameters to learn.
  • Increase the training points. The best degree moves back towards 1 — more data shifts the balance towards the true relationship.
  • The polynomial fit itself is a least-squares solve, and at high degree the normal-equations matrix becomes ill-conditioned — the same arithmetic problem as Module 12's stiffness range.

What this shows: The validation curve helps compare candidate degrees. Once it informs model choice, it is not an independent final test. Error trends vary with noise, sample size and numerical conditioning.

Worked example

Choosing a model on the wrong curve

Given

  • The table above: training and test error against polynomial degree
  • An engineer with access to the training data only

Find

What degree they would choose, and what it costs

    Practice

    A model achieves a training error of 0.089 and a test error of 1.657. What is the ratio of test error to training error?

    Practice

    Twelve observations have distinct x coordinates. What unregularised polynomial degree has exactly enough coefficients to interpolate them in exact arithmetic?

    Worked example

    How many parameters is too many

    Given

    • A model is fitted to 40 measured floor deflections
    • The candidate is a polynomial in span, depth and load, with all cross terms up to second order

    Find

    How many parameters that is, and whether 40 data points can support it

      Practice

      A full second-order polynomial in three variables has how many parameters, counting the constant?

      Practice

      40 data points are used to fit a model with 10 parameters. How many observations per parameter is that?

      Practice

      A model’s training error is 0.20 and its test error is 1.60. What is the ratio of test error to training error?

      Check yourself

      Why can the minimum unregularised training loss not increase in a nested polynomial model family fitted to the same data?

      Check yourself

      An engineer tries fifteen model configurations and reports the test error of the best one. What is wrong with that figure?

      Check yourself

      What does cross-validation buy that a single train/test split does not?

      Summary

      • Separate fitting, selection and final evaluation.
      • Prevent leakage during preprocessing.
      • Check conditioning as well as statistical fit.

      Sources & further information

      scikit-learn, common pitfalls and cross-validation.

      Reviewed 19 October 2026: explanations, teaching calculations and figures checked within the recorded course audit. This is not independent engineering approval. Specialist statistical review remains required for representative data, leakage, validation strategy, uncertainty and deployment monitoring.