The Chartership Forum

Computational Engineering / AI and machine learning for structural engineers

Bias, and what the model never saw

Class imbalance, distribution shift, and the two numbers that behave completely differently.

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.

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

Evaluate performance by class and on data representative of intended use. Rare classes can be poorly represented, and unfamiliar cases can receive confident predictions. Neither outcome is inevitable; the evaluation should test whether it occurs and whether the system can abstain or flag uncertainty.

By the end of this lesson you should be able to

  • Distinguish accuracy from per-class recall and say which hides what
  • Read a confusion matrix
  • Explain distribution shift and the limits of detection or abstention mechanisms
  • Name the classes of bias that matter in engineering data

Class-specific performance

Accuracy is the fraction of all test cases classified correctly. Recall measures the fraction found within a particular class. Both depend on the evaluated population; also report precision and the consequences of different errors.

In the fictional balanced 240-case example, reducing connectivity training cases from 80 to 3 changes overall accuracy from 90.4% to 75.0% and connectivity recall from 95.0% to 26.7%. These are results of that model and dataset, not a universal law of class proportions. Read the confusion matrix and retain uncertainty from the finite sample.

Distribution shift

New structural forms, materials, practices or data-collection methods can change performance. A plain classifier may still return an answer; range checks, out-of-distribution detection and abstention can help but also require evaluation.

Data provenance

Check selection and survivorship, office practices, measurement and labelling procedures, and changes over time. Some biases are visible in the records or comparisons with external data; others require knowledge of what was never collected. Record missing populations and test performance where the tool will actually be used.

Try it

Training data bias explorer

Starve one class in the training set, then test on a balanced set. Watch what happens to accuracy, and to that class's recall.

Connectivity faults are rare in an archive — that is why this happens.

Per-class results on a balanced test set of 60 cases each.
ClassTrained onRecallPrecision
Missing or excessive restraint8096.7 %56.9 %
Unit or scale error8085.0 %87.9 %
Mesh density or quality8091.7 %85.9 %
Disconnected or duplicated geometry326.7 %100.0 %
Overall accuracy
75.0 %

the headline figure

Balanced training would give
90.4 %
Worst class recall
26.7 %

connectivity

Accuracy cost of the imbalance
15.4 points
Recall cost on the starved class
68.3 points

Overall accuracy is 75.0 % — respectable enough to be accepted in a report. Recall on connectivity is 26.7 %, so the model misses most of the class it was probably built to catch.

Why this is the normal case, not the pathological one

  • The rarest class in an archive is usually the one worth detecting — anomalies, defects and unusual failures are rare by definition.
  • So the class most likely to be starved in training is the class the model exists to find.
  • And overall accuracy is least sensitive to exactly that class, because it is the smallest share of the test set.
  • With more classes it gets worse: a class collapsing costs 16 accuracy points out of four classes and 3 points out of twenty.

What this shows: Accuracy summarises how common the common classes are. Only per-class recall shows what happened to the one you built the model for.

Try it

Engineering classifier

Two abstract symptom scores, four fictional warning categories. Move the point and see which class it is assigned to — and which training examples decided it.

The features are deliberately unnamed. The point is about the data, and naming them would invite you to reason about the symptom instead of the distribution.

Classified as
Missing or excessive restraint
Confidence
100 %

3 of 3 neighbours agreed

Neighbours consulted
3

The neighbours agree — which tells you the point is well inside a cluster of training examples, and nothing more than that.

What confidence is and is not

  • It is the proportion of the k nearest training examples that voted for the winning class. Nothing more.
  • It is NOT a probability that the answer is right. Move the point far outside every cluster and the confidence can still be 100 %, because the nearest neighbours still agree with each other.
  • That is the same failure as the surrogate's: a fitted method is defined everywhere, and has no representation of 'outside my experience'.
  • k-nearest-neighbour is used here because every prediction is traceable to specific examples — the circled points are the ones that decided it.

What this shows: Confidence is the proportion of neighbours that agreed. It is not a probability that the answer is right.

Worked example

The classifier that stopped finding what it was built for

Given

  • A classifier over four warning categories, tested on 60 balanced cases of each
  • Version A trained on 80 examples of every class
  • Version B trained on 80, 80, 80 and 3 — connectivity faults being rare in the archive

Find

What each version achieves, and which number reveals the difference

    Practice

    A classifier is tested on 60 connectivity cases and correctly identifies 16 of them. What is its recall on that class, as a percentage to one decimal place?

    Practice

    Three classes score 90 % recall and a fourth scores 26.7 %, on a balanced test set. What is the overall accuracy, as a percentage to one decimal place?

    Check yourself

    A model trained on data from completed projects is used to assess whether a proposed scheme is likely to be buildable. What bias should concern you most?

    Practice

    A class has 60 cases in the test set. The model correctly identifies 51 of them. What is its recall on that class, as a percentage?

    Practice

    Four classes are trained on 80, 80, 80 and 20 examples. What percentage of the training set does the smallest class make up?

    Practice

    Overall accuracy falls from 90.4 % to 75.0 % when one class is starved, while that class's recall falls from 95.0 % to 26.7 %. What is the ratio of the recall drop to the accuracy drop?

    Check yourself

    A defect classifier is trained on models from one practice, and deployed across a group of practices. What is the risk?

    Check yourself

    Why does re-balancing a training set by discarding majority-class examples have a cost?

    Check yourself

    A tool's worst-class recall is 27 %. What is it safe to use it for?

    Summary

    • Accuracy summarises how common the common classes are; recall shows what happened to each
    • Starving one class in four dropped accuracy 15 points and recall on that class 68 points
    • The rarest class is usually the one you built the model for
    • A fitted function is defined everywhere, so it answers outside its experience without saying so
    • Selection, survivor, practice, measurement and temporal bias are all properties of how the data came to exist