Evaluation, Experimentation and Error AnalysisIntroductionA neural network is useful only when its behaviour is measured against a clearly defined objective and its failures are understood. Training loss alone is not sufficient: a model may reduce loss while performing poorly on unseen data, minority classes, or operationally important cases. Evaluation therefore connects model development with evidence-based decisions. This chapter presents a practical framework for evaluating classification and regression models. It explains baselines, data splitting, validation, performance metrics, learning curves, confusion matrices, experimental design, and systematic error analysis. The emphasis is on selecting measurements that reflect the real cost and purpose of a machine-learning application. Learning ObjectivesBy the end of this chapter, you should be able to: - distinguish training, validation and test data;
- construct meaningful classification and regression baselines;
- calculate and interpret common evaluation metrics;
- use stratification, cross-validation and learning curves appropriately;
- interpret confusion matrices and threshold-dependent results;
- design controlled neural-network experiments;
- perform structured error analysis and recommend improvements;
- identify leakage, overfitting, underfitting and misleading evaluation practices.
1. Evaluation as a Model-Development ProcessEvaluation is not a single number obtained at the end of training. It is a sequence of questions: - Does the model learn the relationship in the training data?
- Does it generalise to data not used for parameter fitting?
- Does it outperform a simple, credible baseline?
- Are its errors acceptable for the intended users and risks?
- Is the result stable across samples, classes and relevant subgroups?
A metric is meaningful only relative to a target population, a prediction task and a decision context. For example, accuracy may be suitable for balanced image classes, but inappropriate for detecting a rare disease where false negatives are costly. TerminologyA sample is one observation. A feature is an input variable, and a target is the value to be predicted. A parameter is learned during training, whereas a hyperparameter—such as learning rate or batch size—is selected by the practitioner. Generalisation is performance on unseen data. Data leakage occurs when information unavailable at prediction time influences training or evaluation. 2. Experimental Data SplitsA conventional supervised-learning workflow separates data into three sets: | Set | Main purpose | Used to fit weights? | Used for final reporting? |
|---|
| Training | Learn model parameters | Yes | No | | Validation | Select architecture, hyperparameters and threshold | No | Usually no | | Test | Estimate final generalisation | No | Yes, once or very sparingly |
A common split is 70% training, 15% validation and 15% test, but the appropriate proportions depend on dataset size. With limited data, cross-validation can provide more efficient use of observations. With time-dependent data, random splitting may be invalid; earlier observations should generally be used to predict later observations. For classification, stratification maintains approximately the same class proportions in each split. For grouped data, such as multiple medical records from one patient, all records from a person should remain in the same split. Otherwise, the model may recognise the individual rather than learn a general pattern. Preprocessing must be fitted only on training data. For standardisation, the training mean and standard deviation are used: z = (x − μtrain) ÷ σtrain Here, x is an observed feature value, μ_train is the training-set mean, σ_train is the training-set standard deviation, and z is the transformed value. The same training values are applied to validation and test data. Computing μ or σ using the whole dataset leaks information from evaluation data. Cross-ValidationIn k-fold cross-validation, the training portion is divided into k approximately equal folds. The model is trained k times; each fold serves as validation once. The estimated mean score is: M̄ = (1 ÷ k) ∑ᵢ₌₁ᵏ Mᵢ Mᵢ is the metric from fold i, and k is the number of folds. The procedure assumes that observations can be treated as sufficiently independent after any necessary grouping or temporal ordering. Cross-validation estimates performance variability, but it does not remove bias caused by leakage or an unrepresentative dataset. The test set should remain untouched while models and hyperparameters are selected. Repeatedly checking the test score gradually turns it into another validation set. 3. Baselines and Reference ModelsA baseline establishes the minimum performance a useful model should exceed. Without one, a seemingly high score may be meaningless. For classification, a majority-class baseline always predicts the most frequent class. For a binary problem whose positive class proportion is p, its accuracy is max(p, 1 − p). A stratified random baseline predicts classes according to their observed frequencies. For regression, useful baselines include predicting the training mean or median. The mean baseline minimises squared error on the training data, whereas the median is more resistant to outliers and minimises absolute error. A baseline can also be a non-neural model, such as logistic regression, a decision tree or a linear regression model. Such models are valuable because they are fast, interpretable and often reveal whether a deep network is justified. A fair experiment keeps the data split, preprocessing, target definition and evaluation metric consistent across the baseline and neural model. 4. Classification MetricsFor binary classification, predictions are compared with actual labels using four outcomes: | Actual positive | Actual negative |
|---|
| Predicted positive | True positive (TP) | False positive (FP) | | Predicted negative | False negative (FN) | True negative (TN) |
AccuracyAccuracy = (TP + TN) ÷ (TP + TN + FP + FN) Accuracy is the proportion of correct predictions. It is most informative when classes and error costs are reasonably balanced. In a dataset with 99% negative cases, a model that always predicts negative obtains 99% accuracy but detects no positive cases. Precision and RecallPrecision = TP ÷ (TP + FP) Precision is the proportion of predicted positives that are actually positive. It matters when false alarms are costly. Recall = TP ÷ (TP + FN) Recall, also called sensitivity or true-positive rate, is the proportion of actual positives detected. It matters when missing a positive case is costly. Specificity measures performance on negative cases: Specificity = TN ÷ (TN + FP) The denominator must be non-zero for each metric to be defined. In reporting, the handling of zero denominators should be stated rather than silently ignored. F1 ScoreF1 = 2 × (Precision × Recall) ÷ (Precision + Recall) F1 is the harmonic mean of precision and recall. It is useful when both are important, but it does not include true negatives and may not reflect business costs. A weighted or macro-averaged alternative may be needed for multiclass problems. Multiclass AveragingFor macro averaging, calculate a metric independently for every class and take the unweighted mean. It gives each class equal importance. Weighted averaging weights each class by its support, or number of actual examples. Micro averaging aggregates all class-level decisions before calculating the metric and is strongly influenced by common classes. The selected averaging method should be reported because the same model can receive substantially different scores under macro and weighted averaging. Probabilities, Thresholds and ROC-AUCA neural classifier commonly produces a probability p for the positive class. A threshold t converts this probability into a class prediction: ŷ = 1, if p ≥ t; otherwise ŷ = 0 Changing t changes the balance between false positives and false negatives. The default threshold of 0.5 is not universally optimal, particularly when classes are imbalanced or error costs differ. A receiver operating characteristic (ROC) curve plots true-positive rate against false-positive rate across thresholds. The area under this curve, ROC-AUC, measures ranking ability across thresholds. It can appear optimistic when the negative class is extremely large. Precision–recall curves are often more informative for rare positive events because they focus on positive prediction quality. AUC is not a probability calibration measure. A model can rank cases well while producing probabilities that are systematically too high or too low. Calibration plots, reliability diagrams and measures such as Brier score are appropriate when probabilities will guide decisions. 5. Regression MetricsRegression evaluates numerical predictions ŷ against observed values y. Let n be the number of observations and eᵢ = yᵢ − ŷᵢ be the residual for observation i. Mean Absolute ErrorMAE = (1 ÷ n) ∑ᵢ₌₁ⁿ |yᵢ − ŷᵢ| MAE has the same units as the target and treats errors linearly. It is relatively less influenced by extreme errors than squared-error measures. Mean Squared Error and Root Mean Squared ErrorMSE = (1 ÷ n) ∑ᵢ₌₁ⁿ (yᵢ − ŷᵢ)² RMSE = √MSE MSE has squared target units, while RMSE returns to the target’s units. Squaring gives large errors disproportionate influence. RMSE is therefore useful when large mistakes are especially undesirable. Coefficient of DeterminationR² = 1 − [∑ᵢ₌₁ⁿ(yᵢ − ŷᵢ)²] ÷ [∑ᵢ₌₁ⁿ(yᵢ − ȳ)²] ȳ is the mean of the observed target values. R² compares the model with a mean-prediction baseline on the evaluated sample. It can be negative when the model is worse than that baseline. R² is not a percentage of correct predictions and should not replace an error metric with meaningful units. Worked Regression ExampleSuppose actual values are 10, 12 and 8, while predictions are 9, 15 and 7. The absolute errors are 1, 3 and 1, so MAE = (1 + 3 + 1) ÷ 3 = 1.67 units. Squared errors are 1, 9 and 1, so MSE = 11 ÷ 3 = 3.67 units² and RMSE ≈ 1.91 units. The example shows why RMSE exceeds MAE when a relatively larger error is present. 6. Confusion Matrices and Error ProfilesA confusion matrix is more informative than a single classification score because it shows which types of decisions are wrong. In multiclass classification, each row can represent the actual class and each column the predicted class, provided the convention is stated. Normalised matrices can show percentages rather than counts. Row normalisation answers, “For cases of this actual class, where are they predicted?” Column normalisation answers, “For cases predicted as this class, what are their actual labels?” These answer different questions and must not be confused. Error analysis should inspect examples, not only aggregate counts. Useful categories include: - false positives and false negatives;
- errors near the decision boundary;
- rare classes;
- low-quality or ambiguous inputs;
- errors concentrated in a demographic or operational subgroup;
- systematic errors caused by missing features or label ambiguity.
For regression, plot residuals against predictions and important features. A funnel-shaped residual plot may indicate non-constant variance. Curvature may indicate that the model is missing a nonlinear relationship. Clusters of large residuals may reveal a distinct population requiring additional features or a separate model. 7. Learning Curves and Diagnosing GeneralisationA learning curve plots training and validation performance as training progresses, often by epoch or by training-set size. For loss, a typical overfitting pattern is decreasing training loss while validation loss begins to increase. Early stopping can retain the parameter state associated with the best validation loss. Learning curves also help distinguish: - underfitting: training and validation performance are both poor and close together;
- overfitting: training performance is strong but validation performance is substantially worse;
- high variance: performance changes considerably across folds or samples;
- high bias: even the training fit is inadequate.
When both training and validation performance are poor, increasing model capacity may help, but so may better features, improved labels or reduced noise. When the gap is large, regularisation, augmentation, a smaller model, more data or early stopping may help. Validation curves should not be interpreted mechanically. A noisy validation curve may result from a small validation set, stochastic optimisation or distribution shift. 8. Designing Reliable ExperimentsA professional experiment changes one major factor at a time where feasible. Record the dataset version, split seed, preprocessing, architecture, optimiser, learning rate, batch size, number of epochs, random seed, metric definitions and stopping rule. Multiple random seeds can reveal whether an apparent improvement is stable. Report mean and spread when repeated runs are affordable. A small difference between models should not be presented as meaningful without considering uncertainty and practical significance. Hyperparameter tuning must occur within the training and validation process. Nested cross-validation is useful when an unbiased performance estimate is required after extensive selection: an outer loop estimates performance, while an inner loop selects hyperparameters. For a diploma-level workflow, a fixed validation set plus a final untouched test set is often a reasonable compromise. Compare models using the metric that reflects the decision. If false negatives cost five times as much as false positives, a cost-sensitive evaluation may be more appropriate than accuracy. A simple expected-cost expression is: Expected cost = cFN × FN + cFP × FP where c_FN and c_FP are the costs assigned to false negatives and false positives. These costs should be justified with domain experts rather than invented after seeing results. 9. A Structured Error-Analysis WorkflowA repeatable workflow is more reliable than inspecting a few memorable mistakes. Step 1: Establish the task and baseline. Define the prediction unit, target, prediction time and acceptable error. Report a simple baseline. Step 2: Verify data integrity. Check duplicates, missing values, label conflicts, leakage, class proportions and train–test overlap. Step 3: Build an error table. Store the input identifier, actual label, prediction, probability, loss, subgroup, data-quality flags and relevant metadata. Do not store sensitive information unnecessarily. Step 4: Rank and stratify errors. Inspect high-loss examples, false positives, false negatives and errors by class, subgroup, time period and input quality. Step 5: Form hypotheses. Examples include insufficient resolution, confusing labels, distribution shift, inadequate representation or an unsuitable threshold. Step 6: Test an intervention. Add targeted data, revise labels, change preprocessing, adjust the threshold or modify the architecture. Keep the comparison controlled. Step 7: Re-evaluate broadly. Confirm that improvement on one slice does not damage overall performance or another important subgroup. 10. Illustrative Case: Defect Detection in ManufacturingBackground. A factory uses images of circuit boards to identify defective boards before shipment. Defects are rare: approximately 3% of inspected boards contain a defect. Problem. A neural classifier reports 97.4% accuracy, apparently close to the majority baseline. However, quality engineers are concerned that missed defects may reach customers. Analysis. The confusion matrix shows that the model detects only 60 of 150 defective boards, giving recall of 60 ÷ 150 = 40%. It predicts 300 boards as defective, of which 60 are truly defective, giving precision of 60 ÷ 300 = 20%. Accuracy hid the operational problem because non-defective boards dominate the data. Approach. The team establishes the majority baseline, reports recall, precision, F1 and a precision–recall curve, and chooses a lower probability threshold to increase recall. Engineers review false negatives and find that many defects occur near board edges, where the image crop removes context. The imaging process is changed, targeted edge examples are added to training, and group-aware validation is used so images from the same production batch do not appear in both training and validation. Outcome. Recall improves substantially, although precision decreases at the chosen threshold. The factory accepts additional manual inspections because the cost of a false negative is greater than the cost of a false positive. The final test set is evaluated only after the design is frozen. Learning points. The relevant metric depends on consequences; a baseline exposes whether accuracy is informative; error review can reveal a data-collection problem rather than a purely architectural problem; and threshold selection is part of deployment design. 11. Limitations, Ethics and GovernanceEvaluation data may not represent future users, environments or demographic groups. A high average score can coexist with poor performance for a minority subgroup. Report subgroup metrics where legally and ethically appropriate, while protecting privacy and avoiding unnecessary collection of sensitive attributes. Labels may encode human bias, inconsistent judgement or historical decisions. Improving a metric against biased labels does not necessarily improve fairness. Decisions should document the label source, annotation agreement, exclusions and known limitations. Sensitive data must be governed through access controls, minimisation, retention limits and appropriate consent or legal authority. Model cards, dataset documentation and an audit trail of experiments improve accountability. In high-impact applications, human review, appeal mechanisms, monitoring and post-deployment evaluation are essential. Metrics can also be gamed. Repeatedly selecting a model based on a hidden test set, choosing a favourable subgroup definition, or reporting only the best random seed produces an unreliable claim. Honest evaluation includes negative results, uncertainty, data limitations and the operational meaning of errors. 12. Contemporary Practice and Best PracticesModern evaluation increasingly combines discriminative performance with calibration, robustness and monitoring. Distribution-shift detection compares deployment inputs with training data. Drift monitoring tracks changes in class frequencies, feature distributions and error rates when labels become available. For neural networks, uncertainty estimates can help identify cases requiring human review, although uncertainty methods themselves require validation. Recommended practice is to: - define the deployment decision before choosing metrics;
- use a credible baseline;
- prevent leakage through pipeline discipline;
- preserve an untouched test set;
- report confusion matrices and class-wise results;
- examine both aggregate and subgroup performance;
- inspect learning curves and residuals;
- repeat important experiments across seeds;
- select thresholds using validation data and documented costs;
- monitor the model after deployment.
Chapter SummaryEvaluation is a structured process for determining whether a neural model generalises and whether its errors are acceptable. Training, validation and test sets have different roles, and leakage must be prevented during preprocessing and tuning. Baselines provide essential reference points. Classification should be evaluated with metrics such as accuracy, precision, recall, specificity, F1 and AUC selected according to class balance and error costs. Regression requires measures such as MAE, MSE, RMSE and R², interpreted with attention to units and outliers. Confusion matrices, learning curves, residual plots and stratified error tables reveal information hidden by a single score. Reliable experimentation requires controlled comparisons, documented configurations, appropriate validation and, when possible, repeated runs. Error analysis converts failures into hypotheses for improving data, labels, thresholds or model design. Finally, evaluation must include fairness, privacy, monitoring and governance considerations because technical performance alone does not establish that a system is safe or fit for use. Key TermsBaseline: A simple reference method against which a model is compared. Calibration: Agreement between predicted probabilities and observed frequencies. Confusion matrix: A table of actual and predicted classification outcomes. Cross-validation: Repeated training and validation across partitions of data. Data leakage: Use of information unavailable at prediction time. False negative: An actual positive case predicted as negative. False positive: An actual negative case predicted as positive. Generalisation: Performance on previously unseen data. Learning curve: A plot showing performance as training progresses or data increases. Macro average: An unweighted mean of class-specific metrics. MAE: Mean absolute error, measured in the target’s units. Precision: The fraction of predicted positives that are truly positive. Recall: The fraction of actual positives that are detected. Residual: The difference between an observed and predicted regression value. RMSE: The square root of mean squared error. Specificity: The fraction of actual negatives correctly identified. Stratification: Splitting data while preserving class proportions. Test set: Data reserved for final generalisation assessment. Threshold: A value used to convert a probability into a class decision. Validation set: Data used for model and hyperparameter selection. Review QuestionsShort Answer Questions- Why is a majority-class baseline important for an imbalanced classification problem?
- Distinguish precision from recall.
- What is data leakage, and why is fitting a scaler on all data unsafe?
- What does a learning curve reveal about overfitting?
- Why should the test set remain untouched during model selection?
Long Answer Questions- Explain how training, validation and test sets should be used in a neural-network project.
- Compare accuracy, F1, ROC-AUC and precision–recall analysis for an imbalanced binary classifier.
- Explain MAE, RMSE and R², including situations in which each is useful.
- Describe a structured workflow for analysing classification errors.
- Discuss how ethical and governance considerations affect evaluation design.
Analytical / Application Questions- A screening model has high accuracy but low recall for a rare condition. Which measurements and threshold decisions should be investigated, and why?
- A regression model has low training error but much larger validation error. Propose several experiments to diagnose and reduce the generalisation gap.
- Design an evaluation plan for a multiclass image classifier in which some images come from the same individuals. Specify the split strategy, baseline, metrics and error analyses.
Multiple Choice Questions with AnswersQuestion 1Which dataset should normally be used to select hyperparameters? A. Training set only B. Validation set C. Final test set D. A dataset containing duplicated test examples Correct Answer: B. Validation set Question 2A model predicts 80 positive cases, of which 60 are truly positive. What is its precision? A. 20% B. 60% C. 75% D. 80% Correct Answer: C. 75% Question 3Which metric is usually most directly concerned with missing actual positive cases? A. Recall B. Specificity C. Accuracy D. R² Correct Answer: A. Recall Question 4Why can accuracy be misleading for a rare-event classifier? A. It ignores all true negatives B. A majority prediction can achieve a high score while detecting few positives C. It is measured in squared units D. It can only be calculated for regression Correct Answer: B. A majority prediction can achieve a high score while detecting few positives Question 5Which regression metric has the same units as the target and penalises errors linearly? A. MSE B. R² C. MAE D. Accuracy Correct Answer: C. MAE Question 6In preprocessing, which quantities should normally be used to standardise validation data? A. Validation mean and validation standard deviation B. Test mean and test standard deviation C. Training mean and training standard deviation D. The mean of all available data Correct Answer: C. Training mean and training standard deviation Question 7What pattern most strongly suggests overfitting during training? A. Training and validation losses both decrease together B. Training loss decreases while validation loss begins to increase C. Both losses remain constant at zero D. Validation performance is always better because of leakage Correct Answer: B. Training loss decreases while validation loss begins to increase Question 8What does macro averaging do in multiclass evaluation? A. Weights common classes more heavily B. Uses only the majority class C. Calculates a metric after removing false negatives D. Gives each class equal weight when averaging class-specific metrics Correct Answer: D. Gives each class equal weight when averaging class-specific metrics Question 9A confusion matrix is especially useful because it: A. Shows the types and directions of classification errors B. Automatically proves that a model is calibrated C. Replaces the need for a test set D. Measures regression residuals only Correct Answer: A. Shows the types and directions of classification errors Question 10If false negatives are substantially more costly than false positives, a practitioner may reasonably: A. Increase the decision threshold without analysis B. Ignore recall C. Choose a threshold using documented costs and validation data D. Use the test set repeatedly to select the threshold Correct Answer: C. Choose a threshold using documented costs and validation data
|