AAmit’s LibraryLEARN · PRACTISE · REFLECT

BCA

Machine learning: problem framing, validation, leakage, and metrics

Study map: BCA Semester 5; connects to AI/Data Science options

Mapping scope: Related foundation teaching only; not complete unit/topic coverage, syllabus equivalence, current legal validation or examination alignment. MBA t IDs are navigation fragments from continuous topic text, not official numbered units.

Machine learning learns patterns from examples for a defined task. Supervised learning uses labelled examples; unsupervised learning studies structure without the same target labels. Prediction, explanation, and causation are different objectives. A model that predicts accurately does not automatically explain a causal relationship.

1. Frame the prediction problem

Machine learning learns patterns from examples for a defined task. Supervised learning uses labelled examples; unsupervised learning studies structure without the same target labels. Prediction, explanation, and causation are different objectives. A model that predicts accurately does not automatically explain a causal relationship.

Define the unit of observation, target, available features, prediction time, and intended decision. A feature must be available when a real prediction is made. Information recorded after the outcome can make historical results appear excellent while being unusable in practice. Start with a simple baseline and ask what benefit improvement would create.

Further reading: scikit-learn common pitfalls

2. Separate training and evaluation

Training fits parameters. Validation supports model or tuning choices. A final test set estimates performance after those choices are fixed. Repeatedly choosing models based on test results turns the test into another tuning set. Cross-validation can support evaluation under appropriate data assumptions, but it is not automatically suitable for every time series or grouped dataset.

Split according to the real prediction setting. Randomly mixing records from the same person or future period into training and testing may leak information. Keep preprocessing fitted on training data only. A pipeline can help apply the intended sequence consistently.

For example, fitting an imputer or selecting features using all rows before splitting lets evaluation data influence the model. Within each cross-validation fold, fit these steps only on that fold’s training portion and apply the learned transformation to its validation portion. Put learned preprocessing inside the evaluated pipeline. A pipeline does not repair a split that mixes future information or related cases contrary to the intended evaluation. Use group separation when testing transfer to unseen customers; use chronological separation when testing later decisions, and justify any combined constraints.

Further reading: Cross-validation: evaluating estimator performance

3. Choose metrics and inspect errors

Regression predicts quantities and may use measures such as absolute or squared error. Classification predicts categories and may use precision, recall, confusion matrices, and other metrics. Accuracy can be misleading under class imbalance. If only 1% of cases are positive, always predicting negative gives 99% accuracy while detecting no positives.

Precision concerns how many predicted positives are truly positive; recall concerns how many actual positives are detected. Their importance depends on the consequences of false positives and false negatives. Inspect error groups, calibration, and practical thresholds rather than reporting a single impressive number.

Further reading: scikit-learn user guide

4. Generalisation and responsible use

Overfitting occurs when a model captures training-specific patterns that do not generalise well. Regularisation, simpler models, better data, and suitable validation can help, but none substitutes for correct problem definition. Distribution changes can reduce performance after deployment even when the original evaluation was careful.

Document assumptions, data provenance, limitations, and monitoring. Consider whether the decision should be automated and how people can challenge errors. For a lab, compare a baseline and one model on a well-defined dataset, preserve evaluation boundaries, and explain failures. More complexity is valuable only when it improves the relevant outcome.

Further reading: scikit-learn user guide

Applied business–computing case: reason, implement and review

A retailer trains a model to identify orders likely to be returned. Define the target and the moment at which prediction occurs. A field created after the return is processed cannot be a valid input for an earlier decision; including it creates leakage. Split related or time-dependent records appropriately and compare a transparent baseline.

Inspect errors by product and customer context. The business action might be a review or clearer pre-purchase information, not automatic rejection. Evaluate review capacity, false alarms and customer consequences. Preserve model and data versions and monitor changes in the operating environment. A better predictive score is useful only through a defensible action policy. Machine learning contributes evidence; managers and affected people need accountable ways to interpret and correct the resulting decisions.

Transfer practice: reconcile evaluation and review capacity

Use a held-out classifier fixture with 40 true positives, ten false positives, 20 false negatives and 30 true negatives. Precision is 40/50 = 80%; recall is 40/60, approximately 66.67%; accuracy is 70/100 = 70%; F1 is 80/110, approximately 72.73%. Keep the positive-class definition beside the counts. A zero denominator needs an explicit reporting policy rather than an invented perfect score.

Suppose every predicted positive is sent to a reviewer. This fixture generates 50 reviews, but the team can handle only 30 in the relevant period. The score alone does not provide an operating policy. Compare a higher threshold, increased review capacity and a restricted pilot. Recompute confusion counts from predictions at each threshold; these four counts do not reveal what the new threshold would do. Choose thresholds using development data, then evaluate the fixed policy on an appropriate untouched set.

An undergraduate should explain the denominators and split boundary. A postgraduate learner should compare error costs, queue capacity and subgroup uncertainty. A research learner should specify an evaluation of human correction and accepted outcomes. Predictions must use only features available at the decision time; outcome labels used for evaluation may be collected later. Monitor changing prevalence and workflow behaviour rather than treating one held-out result as permanent evidence.

Further reading: Tuning the decision threshold for class prediction

Study questions and answers

Why can 99% accuracy be poor?

With a 1% positive class, an always-negative model achieves 99% accuracy but zero positive recall.

What is data leakage?

Information unavailable or inappropriate at prediction time influences training or evaluation, producing overly optimistic performance.

Extended practice questions

Explain the distinction between training, validation and final testing using a customer-support classifier.

Training adjusts the model from labelled examples. Validation supports choices such as settings or thresholds without treating those examples as untouched final evidence. A final test estimates performance on held-out cases not used for those decisions, subject to the sampling and task assumptions. Keep records from the same customer or time-linked event appropriately separated where leakage would otherwise occur. The split should reflect the intended deployment setting. Computers can train efficiently, but a high reported metric is weak evidence when evaluation data influenced model choices or differs from future work.

Marking guide: Threeroles; heldoutdecisions; leakage; deploymentsampling. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.

Marks: 10

A classifier has 40 true positives, ten false positives, 20 false negatives and 30 true negatives. Calculate precision, recall, accuracy and F1.

Precision is 40 divided by 50 predicted positives, or 80%. Recall is 40 divided by 60 actual positives, approximately 66.67%. Accuracy is 70 correct predictions divided by 100 cases, or 70%. F1 is twice 40 divided by twice 40 plus ten plus 20, giving approximately 72.73%. Define the positive class and confirm the counts refer to the same test set. These metrics do not assign business costs or establish future reliability. False and missed cases can have different consequences, so model selection needs the task context and appropriate human review.

Marking guide: 80/66.67/70/72.73%; counts/class; cost/futurelimits. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.

Marks: 10

Critique claiming that high test accuracy proves an AI system creates business value.

Accuracy describes a defined prediction comparison, not the complete business outcome. A model may perform well on common cases but fail on costly rare events, change staff workload or produce advice people cannot act upon. Compare it with a meaningful baseline and evaluate error costs, data suitability, monitoring and human responsibility. The surrounding workflow must support correction and exceptions. Software can generate an impressive score while the test omits deployment conditions. Business value requires evidence about useful, accepted outcomes and consequences, beyond one predictive metric.

Marking guide: Metricversusoutcome; costlyrareerrors; baseline/workflow; monitoring/responsibility. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.

Marks: 10

Frame research on human review thresholds in a business classifier.

Study a support-ticket triage classifier: how does the review threshold change missed urgent tickets and reviewer workload? Define urgency, ticket arrival time, label collection and the review period. Fit the model on training data; select a threshold on separate development evidence or suitable cross-validation, and reserve a final evaluation set. Separate customers when evaluating unseen customers and preserve time order when evaluating later tickets.

For each candidate threshold, retain ticket scores and labels, specify the tie rule, and count true positives, false positives, false negatives and true negatives. If every flagged ticket receives exactly one review, workload is TP + FP reviews in the same period used to define capacity. Compare missed-urgent-ticket cost and false-alert cost subject to the stated review capacity. The chapter’s 40 TP and 10 FP imply 50 reviews, exceeding capacity 30 by 20; these counts cannot reveal the outcome at a different threshold. Tied scores may prevent a single threshold from meeting exact capacity, so declare a tie or selection policy rather than silently choosing among tied tickets. Recompute from scores, then evaluate the fixed choice on untouched cases.

Report uncertainty and case-group coverage. Observe reviewer corrections and delays separately: retrospective classification metrics do not demonstrate accepted resolutions or causal business benefit. Monitor changes in prevalence, arrivals and review capacity. Other business examples are valid when they define the same evaluation boundaries, workload units and decision policy.

Marking guide: Define the question, labels and review period (2); separate training, threshold selection and final evaluation with a justified split (2); derive TP + FP workload and describe a score-based method for comparing costs and capacity, with a declared tie policy (3); explain uncertainty, reviewer outcomes and limits of retrospective evidence (3). Total 10 marks; justified alternatives may be valid.

Marks: 10

A manager chooses the majority label after inspecting the final test set. Why is the reported test score no longer independent?

The test labels influenced model selection, so the score describes performance on data used in the decision rather than an untouched evaluation. Fit the majority class using training labels only, state the tie rule and preserve a separate evaluation set. If the final set has already been used repeatedly for choices, obtain an appropriate new evaluation rather than relabelling the old score as independent. Analytics documents the split and decisions; management agrees the relevant population and costs. A tiny synthetic split demonstrates the principle without establishing deployment accuracy.

Marking guide: Test-informed choice;training-only fitting;new independent evaluation;population and ownership.

Compare majority-class prediction with the fitted text baseline in the AI practice workshop.

The majority baseline estimates the most common training class and ignores message features. The text model estimates priors and class-specific token counts from training messages, then combines smoothed likelihoods to predict. Both are fitted models, but their information requirements and failure modes differ. Unseen-only text falls back to the prior in the supplied text implementation; majority prediction always follows the learned class. Compare both on the same held-out cases and cost policy. Added model complexity is useful only if the evidence and operational benefit justify it.

Marking guide: Distinct fitting;features versus no features;unseen behaviour;matched evaluation.

Fit y on x for training points(1,3),(2,5),(3,7). Evaluate test x4,5 with actual y9,12.

The means are x2 and y5. The centred cross-product sum is4 and the centred squared-x sum is2, so slope is2. Intercept is5−2×2=1. At x4 and5 the predictions are9 and11. Absolute held-out errors are0 and1; MAE is(0+1)/2=0.5 in the outcome unit. Test outcomes were not used in fitting. Both test inputs extend beyond the training range, so extrapolation and uncertainty remain relevant even though the arithmetic is simple and the training line fits exactly.

Marking guide: Centred sums4/2;slope2/intercept1;predictions9/11;MAE0.5;split and extrapolation.

Design an evaluation gate for a triage classifier before a pilot.

Define the positive class, observation unit, label process and decision timing. Separate fitting and evaluation by an appropriate temporal or grouped split, and retain a simple benchmark. Report confusion counts, undefined metrics, subgroup coverage and error costs under an agreed policy. Test unknown vocabulary and ambiguous cases, and provide human escalation rather than forcing an automatic answer. Document model and data versions, monitoring owners and pilot stop conditions. Passing fixture tests checks implementation behaviour; approval for a real pilot requires evidence from the relevant operating context.

Marking guide: Contract and split;benchmark/metrics;unknowns/human route;versions and stop conditions.

Revision cards

Explain the distinction between training, validation and final testing using a customer-support classifier.

For support-message triage, training fits labelled messages, validation chooses settings or thresholds, and untouched testing evaluates the fixed choices. Split customers and time-linked events to reflect use and prevent leakage.

A classifier has 40 true positives, ten false positives, 20 false negatives and 30 true negatives. Calculate precision, recall, accuracy and F1.

Precision 80%, recall 66.67%, accuracy 70%, F1 72.73%; task costs and future reliability require separate evaluation.

What is data leakage in model evaluation?

Leakage occurs when evaluation information influences fitting or selection, or a feature uses information unavailable at the decision time. Examples include fitting an imputer on all rows before splitting or using a post-outcome field. Fit learned preprocessing within each training fold; choose splits to match future use.

Why compare a model with a simple baseline?

A baseline shows whether complexity adds useful performance under the same evaluation conditions. Compare costs and error consequences as well as scores; a sophisticated model can be less useful than a simple decision rule.

Why can accuracy be misleading when urgent cases are rare?

Predicting the common class may yield high accuracy while missing consequential rare cases. Inspect the confusion counts, class-specific measures and operational costs. Choose evaluation measures according to the task rather than a convenient aggregate score.

What changes when a classification threshold changes?

Changing the threshold can change predicted labels while leaving model scores unchanged. On a finite test set, labels change only when the threshold crosses a relevant score boundary under the chosen tie rule. Compare false positives, false negatives and review workload; lowering the threshold is not automatically better.

Why distinguish model selection from final evaluation?

Use development evidence to choose settings and hold back an appropriate final evaluation set. Repeatedly choosing settings from the final results can make that set part of development and weaken the claimed unseen-data evaluation.

Why should a predictive feature be available at the decision time?

A model that relies on information learned after the decision uses evidence unavailable in practice. This can inflate evaluation scores. Trace feature timestamps and generation rules, not merely the date attached to each row.

Practice task

Design a model predicting late deliveries using only information available when the order is accepted. State the split strategy, baseline, metric, leakage risks, and deployment limitations.

Sources and further reading

  • scikit-learn common pitfalls
    Type: Free learning material; no paid certificate required
    Use: Study leakage and consistent preprocessing in primary documentation.
  • scikit-learn user guide
    Type: Free learning material; no paid certificate required
    Use: Free reference for methods and evaluation; broader index.

Related courses

Open interactive reading and progress tools