Computational Engineering / AI and machine learning for structural engineers
Bias, and what the model never saw
Inspect class-specific errors and their consequences.
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 notesWhy this matters
A high overall accuracy can conceal poor detection of a rare but important defect. Examine the error types and populations that matter to use.
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
Count error types before reporting a percentage
- Actual defect row
- Missed defects remain in the recall denominator.
- Flagged column
- False alarms remain in the precision denominator.
Read the confusion matrix
A classifier can be accurate by predicting the common class while missing most rare cases. Calculate recall and precision for each relevant class and inspect how false negatives and false positives affect engineering decisions. Retain sample counts and uncertainty.
Separate class imbalance from distribution shift. A test set may be balanced yet represent different materials, structural forms or collection practices from future work. Test the conditions in which the tool is intended to operate.
Inspect selection, labels, missing populations and changes over time. Domain checks or abstention can help handle unfamiliar inputs, but they need evaluation too. A confident prediction is not evidence that the input resembles the training data.
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.
| Class | Trained on | Recall | Precision |
|---|---|---|---|
| Missing or excessive restraint | 80 | 96.7 % | 56.9 % |
| Unit or scale error | 80 | 85.0 % | 87.9 % |
| Mesh density or quality | 80 | 91.7 % | 85.9 % |
| Disconnected or duplicated geometry | 3 | 26.7 % | 100.0 % |
- Overall accuracy
- 75.0 %
- Balanced training would give
- 90.4 %
- Worst class recall
- 26.7 %
- Accuracy cost of the imbalance
- 15.4 points
- Recall cost on the starved class
- 68.3 points
the headline figure
connectivity
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 %
- Neighbours consulted
- 3
3 of 3 neighbours agreed
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
- Inspect class-specific errors and their consequences.
- Test intended populations and unfamiliar conditions.
- Report sample counts alongside percentages.
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.