6. Machine Learning Concepts and End-to-End WorkflowIntroduction and ContextMachine learning (ML) is best understood not as a collection of algorithms, but as a disciplined approach to constructing systems that improve their performance through data or interaction. An ML project begins with a problem in the real world and ends—if successful—with a reliable decision, prediction, recommendation, or action embedded in an operational context. The algorithm is only one component of this larger process. A useful distinction is between a model's performance in a laboratory and the value of an ML system in practice. A model may achieve high accuracy on a carefully prepared test set yet fail after deployment because the data distribution changes, the target was poorly defined, or the prediction cannot be integrated into a business process. Consequently, professional machine learning requires problem framing, data governance, experimental design, evaluation, deployment planning, monitoring, and documentation. This chapter develops an end-to-end view of machine learning. It first differentiates major learning paradigms, then follows the stages of an ML workflow: framing the problem, acquiring and understanding data, preparing features, designing data splits, selecting and training models, evaluating results, and creating reproducible records. The discussion assumes that the reader has encountered basic AI concepts and introduces the reasoning required for postgraduate study and professional practice. Learning ObjectivesAfter studying this chapter, a learner should be able to: - distinguish supervised, unsupervised, semi-supervised, self-supervised, and reinforcement learning;
- translate an organizational or scientific objective into a precise ML problem;
- assess data quality, provenance, representativeness, and possible leakage;
- design preprocessing and feature-engineering pipelines appropriate to the data;
- construct train, validation, and test sets and select suitable evaluation metrics;
- compare models through controlled experimentation rather than isolated trial and error;
- identify technical, ethical, operational, and governance risks; and
- document an experiment so that another practitioner can reproduce and audit it.
The Main Learning ParadigmsSupervised learningIn supervised learning, a model learns a relationship between input variables and a labelled target. Given observations $(x_i,y_i)$, the learning process seeks a function that predicts $y$ from $x$. In classification, the target is categorical—for example, whether a transaction is fraudulent. In regression, the target is numerical—for example, the expected delivery time. The training objective is commonly expressed as minimizing empirical loss: $$\hat{f}=\arg\min_f \frac{1}{n}\sum_{i=1}^{n}L(f(x_i),y_i),$$ possibly with a regularization term that discourages excessive complexity. The central challenge is generalization: performing well on new examples rather than merely memorizing the training data. Linear models, decision trees, random forests, gradient-boosting methods, support-vector machines, and neural networks can all be used in supervised settings. Unsupervised learningUnsupervised learning operates without a target label supplied for each observation. Its purpose may be to discover structure, summarize variation, identify unusual cases, or learn useful representations. Clustering methods group similar observations; dimensionality-reduction methods create compact representations; density estimation models the distribution of observations. The absence of labels does not mean that evaluation is unnecessary. A cluster solution must be examined for stability, interpretability, usefulness, and alignment with the intended decision. A mathematically coherent grouping may have no practical meaning, while a useful business segmentation may require domain interpretation beyond a numerical score. Semi-supervised learningSemi-supervised learning uses a relatively small labelled set together with a larger unlabelled set. It is valuable when labelling requires experts, time, or expensive physical testing. Methods may propagate labels through a representation, impose consistency between related inputs, or assign carefully screened pseudo-labels to unlabelled examples. Its assumptions must be scrutinized. Unlabelled observations should generally come from a population relevant to the deployment setting, and pseudo-label errors can reinforce themselves. Semi-supervised learning is therefore not simply a way to add all available data; it requires controls for uncertainty and distribution mismatch. Self-supervised learningSelf-supervised learning creates supervisory signals from the data itself. In language, a system may predict masked or subsequent tokens; in images, it may predict a transformed view or learn whether two views belong to the same instance. The resulting representation can later be adapted to supervised tasks. Self-supervision is particularly influential where large quantities of raw data exist but labels are scarce. However, the pretext task must encourage representations useful for the downstream objective. Success on the pretext task alone does not establish success on the final application. Reinforcement learningReinforcement learning (RL) concerns an agent interacting with an environment. At time $t$, the agent observes a state, selects an action, receives a reward, and moves to another state. The objective is to maximize expected cumulative reward, often discounted over time: $$G_t=\sum_{k=0}^{\infty}\gamma^kR_{t+k+1}, \quad 0\leq\gamma<1.$$ RL differs from ordinary supervised learning because feedback may be delayed, actions influence later observations, and exploration is necessary. Applications include resource allocation, robotics, recommendation policies, and adaptive control. Safety constraints, reward design, simulation quality, and the cost of experimentation are central concerns. These paradigms may be combined. A modern language system, for example, may use self-supervised pretraining, supervised adaptation, and preference-based or reinforcement learning. The correct paradigm follows from the feedback available, not from the popularity of a particular algorithm. From Organizational Need to Machine-Learning ProblemProblem framingProblem framing is the bridge between a vague objective and a testable learning task. “Use AI to improve customer service” is not an ML specification. A useful framing identifies: - the decision or action to be supported;
- the prediction subject and prediction time;
- the target variable and its operational definition;
- the population to which the system applies;
- the time horizon;
- the costs of different errors;
- the intervention that follows a prediction; and
- constraints involving latency, privacy, fairness, interpretability, and resources.
Suppose a hospital wants to reduce missed appointments. Possible formulations include predicting non-attendance seven days before an appointment, ranking patients for reminder calls, or estimating the expected number of missed appointments in a clinic. These are different tasks with different labels, metrics, interventions, and ethical implications. A baseline is essential. It may be a majority-class predictor, a simple average, an existing business rule, or a previously deployed system. If a sophisticated model cannot improve on a credible baseline at an acceptable cost, complexity is not justified. Framing should also consider whether machine learning is necessary at all; a clearer policy or better data collection may produce greater value. Data collection and data understandingData collection includes not only downloading records but defining provenance, access rights, sampling procedures, measurement processes, and retention practices. Important questions include: Who generated the data? For what original purpose? Which cases are missing? Were labels assigned consistently? Does the sample represent future users? Exploratory data analysis should examine distributions, missingness, duplicates, outliers, class imbalance, temporal patterns, and relationships between variables. Data dictionaries should record units, coding conventions, valid ranges, and the meaning of missing values. Missingness may itself carry information, but treating every missing value as zero is usually unjustified. Data quality is inseparable from measurement. A target such as “customer churn” depends on a definition of inactivity and an observation window. If that definition changes over time, apparent model degradation may actually reflect label drift. Preprocessing and feature engineeringPreprocessing converts raw observations into a form suitable for learning. Numerical variables may require imputation, scaling, transformation, or robust treatment of extreme values. Categorical variables can be encoded using one-hot, ordinal, frequency, or learned representations, depending on their semantics and cardinality. Text, images, audio, and time series require modality-specific representations. Feature engineering uses domain knowledge to create variables that express relevant structure. Examples include ratios, rolling time-window statistics, lag variables, interaction terms, calendar features, and counts of recent events. Feature selection may reduce noise, computation, or interpretive difficulty. It should not be used mechanically: removing a feature merely because it correlates with another can harm a model, while retaining a proxy for a protected attribute may create fairness concerns. A preprocessing operation must be fitted only on the training data within each experimental split. For example, the mean used for imputation, the scaling parameters, and the vocabulary for a text representation must not be calculated using validation or test observations. A pipeline object that couples transformations with the estimator is an effective way to enforce this rule. Train, validation, and test designThe training set is used to fit parameters. The validation set supports choices such as hyperparameters, features, thresholds, and model families. The test set is reserved for a final, relatively unbiased estimate after those decisions are complete. Repeatedly examining the test set turns it into an informal validation set and makes its performance optimistic. Random splitting is appropriate only when observations are approximately independent and identically distributed. For time-dependent data, training must precede validation and testing chronologically. For repeated measurements from the same person, customer, machine, or household, group-based splitting is needed to prevent related records from appearing in multiple partitions. In spatial problems, geographic separation may be necessary. Cross-validation repeatedly divides the training data into folds and averages validation performance. Stratified cross-validation preserves class proportions where appropriate; grouped and time-series variants preserve the relevant dependency structure. The test set may be used once, or very sparingly, for final comparison. Nested cross-validation is useful when hyperparameter selection and performance estimation must be separated rigorously, especially with limited data. Model selection and experimentationModel selection should begin with a small set of candidates matched to the problem, data type, constraints, and baseline. A linear or logistic model may provide a strong and interpretable benchmark. Tree ensembles can capture nonlinear interactions in tabular data. Neural networks may be appropriate for high-dimensional unstructured data when sufficient data and computational resources exist. Hyperparameters are settings chosen outside the direct fitting process, such as tree depth, regularization strength, learning rate, or network architecture. They may be selected through grid search, random search, Bayesian optimization, or resource-aware methods. Search procedures must operate inside the training data and respect group or temporal structure. Experiments should change one meaningful factor at a time where feasible, use fixed or recorded random seeds, and report variation across folds or runs. A result should include the data version, preprocessing, model configuration, metric definition, confidence or variability information, and computational environment. A single best score without context is weak evidence. Evaluation and decision thresholdsMetric selection follows the consequences of errors. Accuracy can be misleading for imbalanced classification. Precision measures the proportion of predicted positives that are correct; recall measures the proportion of actual positives detected. The F1 score combines them through their harmonic mean. Specificity measures the true-negative rate. A precision–recall curve is often informative when positive cases are rare. ROC-AUC summarizes ranking performance across thresholds but may obscure poor precision at the operating region that matters. For regression, mean absolute error is readily interpretable and less sensitive to large errors than root mean squared error. RMSE penalizes large deviations more strongly. Mean absolute percentage error can be problematic near zero and should not be used without considering its assumptions. A threshold converts a score into an action. It should be selected using validation data and the relative costs of false positives and false negatives. Calibration is also important when predicted probabilities inform resource allocation. A well-ranked model is not necessarily well calibrated. Evaluation should be disaggregated across relevant subgroups, time periods, regions, and operating conditions. Aggregate performance can conceal systematic failures. Confidence intervals, bootstrap estimates, or repeated validation can communicate uncertainty rather than implying that a metric is exact. A Practical Workflow for Reproducible MLAn end-to-end workflow is iterative rather than strictly linear: 1. Define the decision, target, population, constraints, and baseline. 2. Obtain authorized data and document provenance, sampling, and label creation. 3. Explore quality, missingness, leakage risks, imbalance, and distributional structure. 4. Create a split strategy before extensive feature engineering. 5. Build a leakage-safe preprocessing pipeline. 6. Establish simple baselines and then train candidate models. 7. Tune and compare candidates using validation procedures suited to the data. 8. Evaluate the selected approach once on a protected test set. 9. Conduct error, subgroup, robustness, and calibration analyses. 10. Assess operational feasibility, governance, and deployment risks. 11. Document the experiment, release versioned artifacts, and plan monitoring. Reproducibility has several levels. Computational reproducibility means that the same code and environment can recreate a result. Data reproducibility requires access to the same data or a documented substitute. Conceptual reproducibility means that the design and reasoning are sufficiently clear for an independent team to implement the study. Version control, environment files, data schemas, experiment trackers, model cards, and data sheets can support these goals. Illustrative Case Study: Predicting Loan DelinquencyBackground and situationConsider a fictional regional lender seeking to identify accounts at risk of becoming 30 days delinquent within the next month. The proposed system will prioritize voluntary financial-counselling outreach; it will not automatically reject applications or change interest rates. Analysis and framingThe target is a binary event observed after a defined prediction date. Features must be restricted to information available on that date. The lender identifies false negatives as costly because support may be missed, but false positives also matter because unnecessary outreach can burden customers and staff. A logistic-regression model and the existing rule-based alert are selected as baselines. The data include repayment history, account age, recent balances, payment timing, and customer-service contacts. A serious leakage risk appears: a “collections referral” field is often entered after staff already recognize delinquency. Although highly predictive, it is unavailable at the intended prediction time and is removed. Records are split chronologically so that earlier accounts train the model and later accounts form validation and test periods. ApproachMissing numerical values are imputed within the training folds, categorical variables are encoded in a pipeline, and rolling repayment features are calculated using only prior events. A gradient-boosting model improves recall over the baseline, but its probability estimates are poorly calibrated. Calibration is applied using validation data. The operating threshold is chosen with staff capacity and the relative costs of missed and unnecessary interventions explicitly represented. The team evaluates performance by customer tenure, geography, language preference, and economic segment. One group has lower recall because historical records contain fewer observations. Rather than simply lowering its threshold, the team investigates data collection and service-access causes, tests subgroup calibration, and consults governance and community representatives. Outcome and learning pointsThe model is approved only as a decision-support tool, with human review, an appeal route, and monitoring for drift. Its deployment documentation states the target definition, exclusion rules, training period, metrics, threshold, known limitations, and prohibited uses. The case demonstrates that leakage control, temporal validation, calibration, subgroup analysis, and operational design are as important as selecting the algorithm. Common Failure Modes and Professional RisksA frequent mistake is beginning with an algorithm rather than a decision. Other failures include target leakage, random splitting of related or temporal records, preprocessing before splitting, optimizing accuracy under severe class imbalance, and repeatedly tuning against the test set. Overfitting can arise from excessive feature engineering, extensive hyperparameter searches, or unexamined analyst decisions even when the chosen algorithm is regularized. Data drift occurs when input distributions change; concept drift occurs when the relationship between inputs and the target changes. Label delay can make recent performance appear artificially good or bad. Feedback loops may occur when predictions influence the outcomes later used as labels—for example, a risk model changes who receives assistance, thereby changing observed default rates. Operational risks include latency, unavailable features at inference time, integration failures, model obsolescence, and lack of ownership. Security threats include data poisoning, adversarial inputs, unauthorized access, and model extraction. A model should therefore be monitored for data quality, missingness, distribution shifts, calibration, subgroup performance, outcome rates, and service-level reliability. Ethical, Legal, and Governance ConsiderationsMachine-learning governance begins with purpose limitation: collect and use data for a legitimate, defined purpose. Privacy protection may involve minimization, access controls, retention limits, de-identification, and appropriate consent or legal basis. De-identification reduces risk but does not guarantee anonymity, particularly when records can be linked. Fairness is not a single metric. Demographic parity, equalized error rates, calibration, and individual notions of fairness can conflict, especially when base rates differ. The appropriate analysis depends on the decision, legal requirements, harms, and context. Protected attributes may be excluded from a model but still represented through proxy variables; they may also be needed for auditing. Exclusion is not automatically fairness. High-impact applications require transparency about purpose, data, limitations, human oversight, contestability, and accountability. Documentation should identify who approved the system, who can override it, how incidents are handled, and when the model must be withdrawn. Professional responsibility extends beyond technical performance to the consequences of deployment. Emerging DirectionsCurrent ML practice increasingly emphasizes foundation models and transfer learning, in which self-supervised models are adapted to specialized tasks. Automated machine learning can assist with preprocessing and model search, but it does not replace problem framing, governance, or domain judgment. Federated and privacy-enhancing methods seek to learn across distributed data without centralizing all raw records, although they introduce communication, security, and statistical challenges. MLOps integrates software engineering, data engineering, experimentation, deployment, and monitoring. Reproducible pipelines, model registries, feature stores, continuous evaluation, and documented approval gates support reliable operation. The emerging emphasis is not merely on larger models, but on trustworthy, efficient, observable, and maintainable systems. Best Practices for End-to-End WorkA strong practitioner defines success before training, keeps a credible baseline, preserves temporal and group structure, isolates the test set, and makes every transformation leakage-safe. Decisions are recorded rather than reconstructed from memory. Error analysis is treated as a source of knowledge, not as an afterthought. Simpler models are preferred when they meet the requirement with lower risk and cost. Teams should involve domain experts, data stewards, security specialists, affected stakeholders, and operational owners. Before deployment, they should specify monitoring signals, retraining criteria, rollback procedures, access controls, and human responsibilities. After deployment, performance must be assessed against real outcomes and not assumed from predeployment test results. Chapter SummaryMachine learning is an end-to-end discipline linking data, models, decisions, and operational consequences. Supervised learning uses labelled targets; unsupervised learning discovers structure; semi-supervised learning combines limited labels with unlabelled data; self-supervised learning derives signals from the data itself; and reinforcement learning learns through sequential interaction and reward. A reliable workflow begins by framing a precise decision and target, then proceeds through authorized data collection, quality assessment, leakage-safe preprocessing, feature engineering, appropriate train-validation-test design, model selection, controlled experimentation, and metric-based evaluation. Validation supports choices, whereas a protected test set estimates final generalization. Reproducible documentation records data, code, parameters, environment, results, assumptions, and limitations. Practical success also requires calibration, subgroup analysis, monitoring, privacy, fairness, security, human oversight, and operational ownership. The central lesson is that a high-performing algorithm is not automatically a useful or responsible ML system; value emerges when technical evidence and organizational judgment are integrated throughout the lifecycle. Key TermsSupervised learning: Learning from examples paired with labelled target values. Unsupervised learning: Learning patterns or representations without supplied target labels. Semi-supervised learning: Learning that combines labelled and unlabelled examples. Self-supervised learning: Learning supervisory signals generated from the data itself. Reinforcement learning: Learning a policy through interaction, actions, rewards, and environmental feedback. Feature: An input variable or representation used by a model. Target: The outcome a supervised model is trained to predict. Data leakage: Use of information during training that would not be available at prediction time. Generalization: Performance of a model on previously unseen, relevant data. Training set: Data used to fit model parameters. Validation set: Data used to select models, features, thresholds, or hyperparameters. Test set: Held-out data reserved for final performance estimation. Cross-validation: Repeated training and validation across complementary data folds. Hyperparameter: A model or training setting selected outside parameter fitting. Calibration: Agreement between predicted probabilities and observed event frequencies. Concept drift: Change over time in the relationship between inputs and the target. Data drift: Change over time in the distribution of input data. Baseline: A simple or existing method used as a reference for improvement. Reproducibility: The ability to recreate or independently implement an experiment from documented materials. Model card: A document describing a model's purpose, performance, limitations, and appropriate use. Review QuestionsShort Answer Questions1. What distinguishes semi-supervised learning from self-supervised learning? 2. Why should preprocessing parameters be fitted only on training data? 3. What is the purpose of a validation set? 4. Define target leakage and give one example. 5. Why may accuracy be unsuitable for an imbalanced classification problem? Long Answer Questions1. Explain the differences among supervised, unsupervised, semi-supervised, self-supervised, and reinforcement learning, including a suitable application for each. 2. Describe the stages of an end-to-end ML workflow from problem framing to post-deployment monitoring. 3. Discuss how temporal, grouped, and random train-validation-test splits differ and when each is appropriate. 4. Explain how feature engineering, regularization, model complexity, and cross-validation affect generalization. 5. Discuss the ethical and governance requirements for deploying a predictive model in a high-impact domain. Analytical / Application Questions1. A fraud dataset contains 1% fraudulent transactions. Recommend evaluation metrics, a validation strategy, and a threshold-selection approach, and justify each choice. 2. A model performs well on randomly split customer records but poorly after deployment. Diagnose at least four possible causes and propose tests for each. 3. Design a reproducible experiment for comparing a logistic-regression baseline with a gradient-boosting model on a time-dependent prediction problem. Specify data splitting, preprocessing, evaluation, documentation, and monitoring decisions. 22. Multiple Choice Questions with AnswersQuestion 1A hospital has a small set of expert-labelled images and a much larger set of unlabelled images from the same clinical setting. Which learning paradigm most directly matches this situation? A. Semi-supervised learning B. Reinforcement learning C. Unsupervised learning only D. Pure supervised learning Correct Answer: A. Semi-supervised learning Question 2Which action creates target leakage in a model intended to predict delinquency before a collections decision is made? A. Using account age measured at prediction time B. Using a collections-referral field entered after staff identify risk C. Using repayment history from prior months D. Using customer tenure recorded when the account opened Correct Answer: B. Using a collections-referral field entered after staff identify risk Question 3Why is a chronological split preferable to a random split for many demand-forecasting problems? A. It guarantees higher accuracy B. It removes the need for a validation set C. It better represents predicting future observations from past data D. It ensures every class has equal frequency Correct Answer: C. It better represents predicting future observations from past data Question 4Which dataset should normally remain untouched while hyperparameters and decision thresholds are selected? A. Training set B. Validation set C. Feature-engineering set D. Test set Correct Answer: D. Test set Question 5A classifier ranks positive cases well but its predicted probabilities are systematically too high. Which property is deficient? A. Calibration B. Recall C. Clustering stability D. Feature cardinality Correct Answer: A. Calibration Question 6A company wants to predict which customers will cancel service, but it has not defined cancellation or the action that follows a prediction. What should occur first? A. Select a neural network architecture B. Increase the number of hyperparameter trials C. Frame the decision, target, population, and intervention D. Deploy the model and observe user behaviour Correct Answer: C. Frame the decision, target, population, and intervention Question 7Which split is most appropriate when several records belong to the same individual and the model must generalize to new individuals? A. A record-level random split B. A group-based split by individual C. A split based only on class labels D. A split after fitting the scaler on all records Correct Answer: B. A group-based split by individual Question 8In reinforcement learning, what makes the learning problem different from ordinary supervised prediction? A. The agent receives no input observations B. The target is always a categorical label C. Actions can influence future states and rewards D. The data must always be independently and identically distributed Correct Answer: C. Actions can influence future states and rewards Question 9Which practice most strongly supports computational reproducibility? A. Reporting only the best score B. Recording code, data version, random seeds, parameters, and environment C. Changing several modelling decisions without logging them D. Using the test set after every experiment Correct Answer: B. Recording code, data version, random seeds, parameters, and environment Question 10A deployed model's input distributions remain stable, but the relationship between inputs and outcomes changes. This is best described as: A. Data drift B. Concept drift C. Feature scaling D. Cross-validation Correct Answer: B. Concept drift
|