AI & Machine Learning Fundamentals

Chapter 5
Machine Learning Workflow and Toolchain

Advance Diploma in Artificial Intelligence and Machine Learning
AI & Machine Learning Fundamentals   •   Advance Diploma

Machine Learning Workflow and Toolchain

Introduction

Machine learning (ML) projects rarely fail because an algorithm cannot be executed. They more often fail because the business problem is poorly defined, the data does not represent the intended population, evaluation is inappropriate, or the trained model cannot be maintained in production. A professional ML workflow therefore treats modelling as one stage in a broader evidence-based process.

This chapter presents an end-to-end workflow for translating a business problem into a learning task, exploring and preparing data, engineering features, selecting and validating models, documenting decisions, and conducting reproducible experiments. The emphasis is practical: learners should be able to move from an ambiguous organisational request to a defensible modelling pipeline using contemporary tools such as Python, pandas, scikit-learn, Jupyter, Git, MLflow, and container technologies.

A workflow is not necessarily a rigid sequence. Data exploration can reveal that the original question is invalid; validation results can require new features; and deployment constraints can change the choice of model. The workflow is therefore iterative, but its stages provide essential controls against error and bias.

Learning objectives

By the end of this chapter, you should be able to:

  1. Translate a business objective into a measurable ML task.
  2. Distinguish observations, targets, features, training data, validation data, and test data.
  3. Explore data using descriptive statistics and visualisation while identifying quality problems.
  4. Design leakage-resistant preprocessing and feature-engineering pipelines.
  5. Select models according to task type, data characteristics, performance, interpretability, and operational constraints.
  6. Train, validate, compare, and document models appropriately.
  7. Use version control, experiment tracking, fixed random seeds, and environment specifications to improve reproducibility.
  8. Recognise ethical, privacy, governance, and monitoring requirements in ML systems.

1. From business problem to learning problem

A business statement such as “reduce customer churn” is not yet a machine-learning problem. It must be converted into a decision, a population, a prediction time, a target, and an action. A useful formulation asks:

  • Who or what is being predicted? For example, an active subscription account.
  • When is the prediction made? For example, at the end of each billing cycle.
  • What outcome is predicted? For example, cancellation within the next 30 days.
  • What action follows the prediction? For example, offering assistance to selected customers.
  • What constraints apply? These may include latency, cost, fairness, privacy, and explainability.
  • How will success be measured? This may involve financial benefit rather than accuracy alone.

A learning task can then be expressed formally. Let an observation be represented by a feature vector xi and an outcome by yi. A supervised-learning dataset contains pairs (xi, yi), where i = 1, 2, ..., n and n is the number of observations. The model learns a function f_θ(x) parameterised by θ so that predictions are useful for future, unseen observations.

Task types

Business requirementLearning taskTypical outputExamples of metrics
Predict a categoryClassificationClass or class probabilitiesPrecision, recall, F1, ROC-AUC
Predict a numerical quantityRegressionContinuous valueMAE, RMSE, R²
Find natural groupsClusteringCluster assignmentSilhouette score, stability, domain usefulness
Rank itemsRanking/recommendationOrdered listPrecision@k, recall@k, NDCG
Detect unusual casesAnomaly detectionAnomaly score or flagPrecision at review capacity, false-alarm rate
Forecast future valuesTime-series forecastingFuture sequenceMAE, RMSE, MASE, service-level measures

The target must be defined with a clear observation window and outcome window. If a hospital wants to predict readmission within 30 days, information recorded after discharge cannot be used as a feature at admission. This temporal distinction is central to preventing leakage.

Success criteria beyond predictive accuracy

A model can have excellent statistical performance and little practical value. A complete success specification may include:

  • predictive performance on a representative holdout set;
  • maximum inference latency;
  • cost per prediction;
  • acceptable false-positive and false-negative rates;
  • fairness requirements across relevant groups;
  • interpretability and auditability;
  • integration with existing systems;
  • measurable operational or financial benefit.

A classification threshold is a decision rule, not an inherent property of a model. If a model produces probability p, a positive decision may be made when p ≥ t, where t is a chosen threshold. The threshold should reflect the relative costs of errors and available intervention capacity.

2. The data understanding stage

Data understanding combines provenance investigation, schema inspection, descriptive analysis, and domain consultation. The analyst should establish where each field came from, how it was generated, its unit and meaning, and whether it was available at prediction time.

Data structures and measurement levels

Common variable types include:

  • Numerical: counts, amounts, durations, and measurements.
  • Nominal categorical: labels without a natural order, such as region.
  • Ordinal categorical: ordered levels, such as low, medium, and high.
  • Boolean: true/false indicators.
  • Datetime: timestamps requiring time-zone and calendar interpretation.
  • Text, image, or audio: unstructured data requiring specialised representation.
  • Identifier: values used to distinguish records, which are usually not predictive features.

A data dictionary should record field name, business definition, data type, unit, permissible values, missing-value meaning, source, collection time, and permitted use. “Missing” may mean not collected, not applicable, refused, or system failure; these meanings should not automatically be treated as equivalent.

Exploratory data analysis

Exploratory data analysis (EDA) is used to discover structure and detect risks, not to confirm a preferred model. Important checks include:

  • number of rows and columns;
  • duplicate records;
  • unique values and category frequencies;
  • missingness by field and by subgroup;
  • minimum, maximum, mean, median, and quantiles for numerical variables;
  • distributions and extreme values;
  • relationships between features and target;
  • temporal ordering and changes in data collection;
  • class imbalance;
  • possible proxies for sensitive characteristics.

For a numerical variable x1, x2, ..., xn, the arithmetic mean is:

x̄ = (1/n) ∑ᵢ₌₁ⁿ xᵢ

Here n is the number of observed values and x̄ has the same unit as x. The mean is sensitive to extreme observations. The median, the middle ordered value, is often more robust for skewed distributions. A sample standard deviation is:

s = √[(1/(n − 1)) ∑ᵢ₌₁ⁿ (xᵢ − x̄)²]

The denominator n − 1 is appropriate when estimating population variability from a sample under conventional random-sampling assumptions. Standard deviation has the same units as the measured variable.

For a binary target, class prevalence is:

π = n₊ / (n₊ + n₋)

where n₊ and n₋ are the counts of positive and negative cases. A highly imbalanced target means that accuracy may be misleading. A classifier predicting the majority class can obtain high accuracy while failing to identify the class of interest.

EDA must be performed with care when a final test set exists. Repeatedly inspecting test results and adapting the workflow to them makes the test set part of model development. The test set should remain an approximately untouched estimate of final generalisation performance.

3. Data quality and preparation

Data preparation converts raw records into valid model inputs. It should be explicit, justified, and fitted only on appropriate training data.

Missing values

Options include deletion, constant replacement, statistical imputation, model-based imputation, and a separate missingness indicator. No method is universally best. Median imputation is often robust for skewed numerical variables; most-frequent imputation can be suitable for some categorical variables. However, imputation may distort relationships, especially when missingness is informative.

A general principle is that an imputer learns parameters from training data only. If the overall dataset median is calculated before splitting, information from validation or test records has entered the training process. Although this may appear harmless, it can bias evaluation and is especially problematic when distributions shift.

Duplicates, errors, and outliers

Duplicate rows may represent repeated transactions or data-entry errors; they should not be removed without understanding their meaning. Domain rules can identify impossible values, such as negative age or a delivery date before an order date. Outliers may be errors, legitimate rare events, or the cases most important to the business. Blind deletion can reduce usefulness and fairness.

Possible treatments include robust transformations, winsorisation, log transformation for positive right-skewed variables, or algorithms less sensitive to extreme values. Any alteration should be recorded and justified.

Encoding and scaling

Many algorithms require numerical inputs. One-hot encoding represents a categorical variable with indicator columns. For a category with levels A, B, and C, an observation may become (1,0,0), (0,1,0), or (0,0,1). For linear models with an intercept, one category is often omitted to avoid exact linear dependence; this is called drop-first or reference-category encoding.

Standardisation transforms a feature using training-set mean and standard deviation:

z = (x − μtrain) / σtrain

Here x is the original value, μtrain is the training mean, and σtrain is the training standard deviation. The result is dimensionless. Standardisation is important for distance-based methods, support-vector machines, and many gradient-based models, but usually unnecessary for decision trees and random forests.

Robust scaling, logarithmic transformation, binning, and domain-specific ratios may be preferable in particular settings. A ratio must be meaningful and its denominator must be handled safely; for example, revenue per active user is undefined when the active-user count is zero.

Leakage

Data leakage occurs when information unavailable at prediction time, or information derived from the outcome, influences training. Examples include:

  • using a post-event medical code to predict an admission;
  • computing a customer’s lifetime value after the prediction date;
  • selecting features using the entire dataset before cross-validation;
  • allowing the same individual to appear in both training and test sets when the task is person-level generalisation;
  • randomly splitting data that have a temporal ordering.

Leakage often produces impressive but non-deployable results. The remedy is to define the prediction point, enforce time-aware feature availability, and place transformations inside a pipeline.

4. Feature engineering

Feature engineering creates representations that make relevant structure easier for a model to learn. It is a combination of domain knowledge, statistical reasoning, and controlled experimentation.

Examples include:

  • extracting hour, day of week, or season from a timestamp;
  • calculating recency, frequency, and monetary aggregates from historical transactions;
  • converting text into term-frequency or embedding representations;
  • creating interaction terms when the combined effect matters;
  • aggregating event sequences over a fixed historical window;
  • representing cyclic variables, such as hour of day, with sine and cosine components.

For a cyclical variable t with period P, a common representation is:

sin(2πt/P), cos(2πt/P)

This prevents the artificial discontinuity between the final and first values of a cycle. The transformation is appropriate only when the variable genuinely has a cycle and P is known.

Feature selection may be filter-based, wrapper-based, or embedded in model training. Selection should occur within each training fold when cross-validation is used. Otherwise, the validation fold influences which features are chosen, causing optimistic estimates.

Feature engineering should be evaluated for stability, maintainability, and fairness. A sophisticated feature that cannot be computed reliably in production is inferior to a simpler, dependable feature.

5. Splitting data and validating models

Holdout sets

For independent and identically distributed observations, data may be divided into training, validation, and test sets. The training set estimates model parameters, the validation set supports model and hyperparameter choices, and the test set provides a final estimate after decisions are complete.

For small datasets, a single split can be unstable. K-fold cross-validation divides the training data into k folds. Each fold is used once as validation while the remaining folds are used for training. If the fold scores are [[MATH{s_1, s_2, ..., s_k}]], the mean score is:

s̄ = (1/k) ∑ⱼ₌₁ᵏ sⱼ

and the sample standard deviation of scores is:

scv = √[(1/(k − 1)) ∑ⱼ₌₁ᵏ (sⱼ − s̄)²]

Cross-validation assumes that the splitting scheme reflects deployment. Stratified folds preserve approximate class proportions for classification. Grouped folds keep records from the same person, household, or organisation in one fold. Time-series validation trains on earlier periods and validates on later periods; random shuffling is usually inappropriate when future prediction is intended.

Evaluation metrics

For binary classification, a confusion matrix contains true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN). Important metrics include:

Accuracy = (TP + TN) / (TP + TN + FP + FN)
Precision = TP / (TP + FP)
Recall = TP / (TP + FN)
F1 = 2 × (Precision × Recall) / (Precision + Recall)

These formulas assume denominators are non-zero. Precision measures the proportion of predicted positives that are positive; recall measures the proportion of actual positives detected. F1 is the harmonic mean of precision and recall and does not incorporate true negatives.

For regression, mean absolute error is:

MAE = (1/n) ∑ᵢ₌₁ⁿ |yᵢ − ŷᵢ|

and root mean squared error is:

RMSE = √[(1/n) ∑ᵢ₌₁ⁿ (yᵢ − ŷᵢ)²]

Here yi is the observed value and ŷi is the prediction, both in the target’s units. RMSE penalises large errors more strongly than MAE. Neither metric alone establishes business usefulness.

For probability predictions, calibration matters: among cases assigned probability approximately 0.7, about 70% should experience the outcome if the model is well calibrated. Discrimination and calibration are different properties. A model can rank cases correctly while producing poorly calibrated probabilities.

6. Model selection and training

There is no universally best algorithm. Selection should begin with a transparent baseline and proceed according to data, task, and constraints.

Model familyStrengthsLimitationsTypical preparation
Linear/logistic regressionInterpretable, fast, strong baselineLimited nonlinear structureImputation, encoding, often scaling
Decision treeRules, nonlinearities, mixed relationshipsCan overfitLittle scaling required
Random forestRobust nonlinear baseline, feature interactionsLarger model, less transparentHandles varied numerical inputs; encoding still needed for categories
Gradient boostingOften strong predictive performanceTuning and leakage control requiredCareful validation; many implementations support missing values differently
k-nearest neighboursIntuitive local predictionsSensitive to scale and dimensionalityScaling essential
Neural networksFlexible representation learningData, tuning, and operational complexityNumeric tensors, regularisation, careful training

A baseline may be a majority-class classifier, mean predictor, or simple business rule. Without it, a complex model cannot be shown to add value.

Training commonly minimises an empirical loss. In general form:

θ̂ = arg min_θ [ (1/n) ∑ᵢ₌₁ⁿ L(yᵢ, f_θ(xᵢ)) + λΩ(θ) ]

Here L is the loss function, Ω(θ) is a regularisation penalty, and λ ≥ 0 controls its strength. The equation applies to optimisation-based models where a loss and penalty are defined. Increasing regularisation can reduce variance but may increase bias; the appropriate value must be selected using training-only validation procedures.

Hyperparameters, such as tree depth or regularisation strength, are selected through cross-validation or a validation set. Nested cross-validation is useful when an unbiased performance estimate is needed while extensive hyperparameter selection is performed: an inner loop selects settings and an outer loop estimates performance.

A scikit-learn-style pipeline conceptually combines preprocessing and an estimator:

from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.linear_model import LogisticRegression

numeric = Pipeline([
    ("imputer", SimpleImputer(strategy="median")),
    ("scale", StandardScaler())
])
categorical = Pipeline([
    ("imputer", SimpleImputer(strategy="most_frequent")),
    ("encode", OneHotEncoder(handle_unknown="ignore"))
])
preprocess = ColumnTransformer([
    ("num", numeric, numeric_columns),
    ("cat", categorical, categorical_columns)
])
model = Pipeline([
    ("preprocess", preprocess),
    ("classifier", LogisticRegression(max_iter=1000))
])

The important principle is not the exact library syntax but the encapsulation of learned transformations with the estimator. The pipeline can then be fitted inside each cross-validation split, reducing leakage risk.

7. Reproducible experimentation and the toolchain

A professional toolchain separates data, code, configuration, environments, results, and documentation.

Core tools

  • Python: general-purpose language with a large ML ecosystem.
  • Jupyter: interactive exploration and explanation; notebooks should be converted into tested scripts or reports for repeatability.
  • NumPy and pandas: numerical arrays and tabular data manipulation.
  • scikit-learn: preprocessing, classical models, pipelines, metrics, and validation.
  • Matplotlib or Seaborn: visual analysis.
  • Git: version control for code, configuration, and documentation.
  • MLflow or similar systems: experiment runs, parameters, metrics, artifacts, and model versions.
  • Virtual environments, conda, or containers: dependency isolation.
  • Continuous integration: automated tests and quality checks.

A useful experiment record includes a unique run identifier, code commit, dataset version, feature definition, train/validation split method, random seed, hyperparameters, metrics, hardware, software versions, and model artifact. Random seeds improve repeatability but do not guarantee exact reproducibility across operating systems, library versions, parallel hardware, or nondeterministic algorithms.

Data should not normally be committed directly to Git repositories. Use a data-versioning system or controlled object store, retain checksums, and document access permissions. A model card or equivalent report should state intended use, limitations, training data characteristics, evaluation results, subgroup performance, and known risks.

Reproducibility has several levels:

  1. Computational reproducibility: the same code and data produce the same result.
  2. Methodological reproducibility: another team can understand and repeat the procedure.
  3. External reproducibility: the approach works on independently collected data.

The third is the strongest and most difficult. It requires careful sampling, clear definitions, and evaluation under realistic distribution change.

8. Applied case: predicting subscription cancellation

The following is an illustrative case, not a report of a real organisation.

Background and problem

A digital learning service wants to identify subscribers at risk of cancelling in the next 30 days so that a retention team can offer technical support or relevant learning guidance. The company has account, billing, usage, and support data.

The initial request—“build a churn model”—is refined as follows: at midnight on each Monday, predict whether an active subscriber will cancel during the subsequent 30 days. Only information recorded before that Monday may be used. The intervention team can contact at most 5% of subscribers per week.

Analysis

The target is binary. The data contain multiple weekly snapshots per subscriber, so a random row split would allow the same person to appear in both training and validation sets and could overstate performance. A time-based split is selected: earlier weeks for training, a later period for validation, and the most recent period for final testing.

Potential features include number of active days in the previous 14 days, completed lessons, unresolved support tickets, payment failures before the prediction date, and days since last activity. Cancellation status is excluded after the prediction date. A field called “retention offer accepted” is also excluded because it occurs after intervention and is unavailable when the prediction is made.

EDA shows that cancellation prevalence is 8%. A majority-class baseline therefore achieves 92% accuracy but zero recall for cancellation. The team chooses average precision and recall at the top 5% of ranked subscribers as operational metrics, because the intervention capacity is fixed. Calibration is also assessed because the retention team wants interpretable risk estimates.

Approach and solution

The team creates a leakage-resistant pipeline with median imputation for numerical features, explicit missing indicators for support-ticket data, one-hot encoding for plan type, and logistic regression as a transparent baseline. A gradient-boosted model is then evaluated using the same time-based folds. Hyperparameters are selected using only the training period and internal validation windows.

The final model is not chosen solely by its highest score. The boosted model gives slightly better ranking, but its explanations are harder for support staff to use and its performance degrades more during a simulated seasonal shift. The team selects the model with the best balance of ranking, calibration, stability, latency, and explanation quality.

The threshold is set so that exactly the highest-risk 5% are contacted. The model is deployed as a batch job, and each prediction stores the model version, feature snapshot time, score, threshold, and decision. Outcomes are later joined using the predefined 30-day window.

Outcome and monitoring

The organisation monitors recall among contacted subscribers, calibration, subgroup performance, data missingness, feature distributions, intervention uptake, and actual cancellation rates. It distinguishes model failure from intervention failure: a customer may be correctly identified as high risk but still not respond to an unsuitable offer.

Learning points

  1. The prediction timestamp and outcome window determine which features are legal.
  2. Row-level random splitting is unsafe for repeated customer records.
  3. Operational capacity can determine the evaluation metric and threshold.
  4. A small performance advantage may not justify lower interpretability or stability.
  5. Deployment requires logging, monitoring, and a plan for retraining and review.

9. Deployment, governance, and limitations

A model’s lifecycle continues after training. Data drift occurs when input distributions change; concept drift occurs when the relationship between inputs and outcomes changes. Monitoring should compare current data with a reference period and investigate changes rather than automatically retraining.

Important governance controls include:

  • lawful and transparent data collection;
  • purpose limitation and data minimisation;
  • access control and encryption for sensitive data;
  • retention and deletion policies;
  • documentation of model purpose and limitations;
  • human oversight for high-impact decisions;
  • appeal and correction mechanisms;
  • audit logs and versioned releases;
  • testing for disparate performance across relevant groups.

Fairness cannot be reduced to one universal metric. For a group [[MATH{g]], recall can be written as TPg/(TPg+FNg). Comparing recall across groups may reveal unequal access to benefits, but equal recall may conflict with other objectives when base rates differ. Fairness analysis requires domain, legal, and ethical judgement rather than mechanical metric optimisation.

Privacy risks can arise even when direct identifiers are removed. Rare combinations of fields may permit re-identification, and model outputs can sometimes reveal training information. Techniques such as aggregation, access restriction, privacy-preserving learning, and formal differential privacy may be appropriate depending on risk and context.

Common technical limitations include small or biased samples, unreliable labels, non-stationary environments, hidden confounding, unmeasured outcomes, and the tendency of benchmark performance to exceed real-world performance. A model should not be used outside its validated population without explicit review.

10. Best-practice checklist

Before approving an ML experiment, ask:

  • Is the business decision and prediction time explicit?
  • Is the target measurable and labelled consistently?
  • Is every feature available at prediction time?
  • Does the split reflect deployment, including groups and time?
  • Is there a simple baseline?
  • Are preprocessing and feature selection inside the validation pipeline?
  • Are metrics aligned with costs, capacity, and risk?
  • Have calibration, subgroup performance, and robustness been assessed?
  • Can another practitioner reproduce the run from recorded code, data, and configuration?
  • Are privacy, security, governance, monitoring, and retirement plans defined?

Chapter Summary

A machine-learning project is an end-to-end workflow rather than an isolated algorithm. The process begins by translating a business objective into a precisely timed prediction task with an action and measurable success criteria. Data understanding then establishes provenance, variable meaning, quality, missingness, distributions, and possible bias.

Preprocessing and feature engineering must respect the boundary between information available at prediction time and information revealed later. Pipelines reduce leakage by fitting transformations inside training folds. Validation must reflect deployment: stratified methods support classification, grouped methods protect against entity overlap, and temporal methods are essential for future prediction.

Model selection should compare transparent baselines with more complex alternatives using metrics appropriate to the decision. Classification metrics describe different error priorities, while MAE and RMSE describe different aspects of regression error. Reproducible practice requires versioned code and data, recorded environments, experiment tracking, fixed configurations, and clear documentation. Finally, deployment introduces monitoring, fairness, privacy, security, human oversight, and model-lifecycle responsibilities.

Key Terms

Business objective: The organisational decision or outcome that motivates an ML project.

Learning task: A formal prediction, grouping, ranking, or detection problem derived from a business objective.

Feature: An input variable used by a model.

Target: The outcome a supervised model is trained to predict.

Observation window: The period during which information is available for prediction.

Outcome window: The future period over which the target is measured.

Data leakage: Use of information that would not be available at prediction time.

Exploratory data analysis: Systematic investigation of data structure, quality, and relationships.

Imputation: Replacement or modelling of missing values.

One-hot encoding: Representation of categorical levels as indicator variables.

Standardisation: Transformation using a mean and standard deviation, commonly producing a z-score.

Feature engineering: Creation or transformation of inputs using domain and statistical knowledge.

Cross-validation: Repeated partitioning of data to estimate performance and select models.

Hyperparameter: A model or training setting selected before or during model development.

Calibration: Agreement between predicted probabilities and observed frequencies.

Baseline: A simple reference method against which more complex models are compared.

Reproducibility: Ability to repeat an analysis using recorded code, data, and environment information.

Data drift: Change in the distribution of model inputs over time.

Concept drift: Change in the relationship between inputs and outcomes.

Model card: Documentation describing a model’s purpose, performance, limitations, and risks.

Review Questions

5 Short Answer Questions

  1. Why must a business request be converted into a prediction time, target, and action before modelling?
  2. Distinguish training, validation, and test data.
  3. What is data leakage? Give one example.
  4. Why can accuracy be misleading for an imbalanced classification problem?
  5. Name four items that should be recorded for a reproducible ML experiment.

5 Long Answer Questions

  1. Explain how EDA, data dictionaries, and domain consultation contribute to reliable feature design.
  2. Compare stratified, grouped, and time-based validation, including when each should be used.
  3. Discuss the advantages and limitations of linear models, tree ensembles, and neural networks in a professional toolchain.
  4. Explain how an ML pipeline prevents leakage during imputation, encoding, scaling, and feature selection.
  5. Discuss why deployment monitoring and governance are necessary even when a model performs well on a test set.

3 Analytical / Application Questions

  1. A bank has repeated monthly records for each customer and wants to predict default in the next month. Design a splitting and validation strategy and justify it.
  2. A hospital model has high accuracy but very low recall for a rare complication. Recommend a revised evaluation framework and explain the trade-offs.
  3. Design an experiment-tracking specification for comparing two churn models, including data version, split, features, metrics, model artefacts, and release criteria.

Multiple Choice Questions with Answers

Question 1

Which statement best defines data leakage?

A. Using a model with too many parameters

B. Using information unavailable at prediction time during model development

C. Having missing values in a training table

D. Deploying a model with low latency

Correct Answer: B. Using information unavailable at prediction time during model development

Question 2

Which validation strategy is generally most appropriate for forecasting future demand?

A. Random splitting with unrestricted shuffling

B. Leave-one-feature-out validation

C. Time-based validation using earlier periods for training

D. Validation using only the majority class

Correct Answer: C. Time-based validation using earlier periods for training

Question 3

A classifier has TP = 80 and FN = 20. What is its recall?

A. 20%

B. 50%

C. 80%

D. 100%

Correct Answer: C. 80%

Question 4

Which operation should normally be fitted only on training data before being applied to validation data?

A. Computing an imputation median

B. Reading the column names

C. Counting the number of rows in the file

D. Recording the prediction timestamp

Correct Answer: A. Computing an imputation median

Question 5

Why is a majority-class baseline potentially misleading for an imbalanced classification task?

A. It always requires feature scaling

B. It may achieve high accuracy while missing nearly all minority cases

C. It cannot be implemented in Python

D. It produces calibrated probabilities by definition

Correct Answer: B. It may achieve high accuracy while missing nearly all minority cases

Question 6

What is the main purpose of a model baseline?

A. To guarantee the final model is linear

B. To provide a simple reference for judging added complexity

C. To remove the need for a test set

D. To increase the number of features automatically

Correct Answer: B. To provide a simple reference for judging added complexity

Question 7

Which metric is expressed in the same units as the regression target?

A. MAE

B. ROC-AUC

C. Precision

D. F1 score

Correct Answer: A. MAE

Question 8

Why should repeated records from the same customer often be kept in one validation group?

A. To increase the number of categories

B. To prevent entity information from appearing in both training and validation

C. To guarantee perfect accuracy

D. To eliminate all missing values

Correct Answer: B. To prevent entity information from appearing in both training and validation

Question 9

What does calibration assess for a probabilistic classifier?

A. Whether the model uses a GPU

B. Whether predicted probabilities correspond to observed frequencies

C. Whether all features have equal units

D. Whether the training set is larger than the test set

Correct Answer: B. Whether predicted probabilities correspond to observed frequencies

Question 10

Which item most directly supports computational reproducibility?

A. Changing the random seed for every run without recording it

B. Recording code version, data version, configuration, and environment

C. Selecting the most complex model available

D. Inspecting the test set repeatedly during tuning

Correct Answer: B. Recording code version, data version, configuration, and environment

AI & Machine Learning Fundamentals
Chapter 5 of 14