Data Analytics & Visualization

Chapter 11
Predictive Analytics and Machine Learning

Bachelors Program in Business Analytics
Data Analytics & Visualization   •   Bachelor

Predictive Analytics and Machine Learning

Introduction

Predictive analytics uses historical and current data to estimate future outcomes, classify cases, identify groups, detect unusual observations, or describe changing patterns over time. In business analytics, the purpose is not simply to produce a high-performing algorithm. A useful model must support a decision, operate reliably on new data, be understandable enough for its context, and respect legal, ethical, and organizational constraints.

Machine learning provides a family of computational methods for learning relationships from data. The central distinction is between supervised learning, where a target variable is available, and unsupervised learning, where the objective is to discover structure without a specified target. Regression and classification are supervised tasks; clustering and many anomaly-detection methods are unsupervised or semi-supervised. Time-series forecasting may be supervised or model-based, but it requires special treatment because observations are ordered in time.

A typical predictive-analytics project follows this logic:

  1. Translate a business problem into a measurable analytical task.
  2. Define the unit of analysis, target, prediction horizon, and decision rule.
  3. Acquire, clean, and document data.
  4. Split data into training, validation, and test sets without leakage.
  5. Select features and a suitable model.
  6. Tune and evaluate the model using metrics aligned with business costs.
  7. Explain, deploy, monitor, and periodically review performance.

A model estimates patterns; it does not automatically establish causation. A variable may be highly predictive because it is a proxy for another factor, because it records a downstream consequence, or because it reflects historical bias.

Learning Objectives

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

  • distinguish regression, classification, clustering, time-series forecasting, and anomaly detection;
  • construct appropriate train-validation-test workflows;
  • explain bias, variance, overfitting, regularization, and feature selection;
  • calculate and interpret common performance metrics;
  • select models according to data structure and decision costs;
  • interpret model outputs using global and local explainability methods;
  • recognize leakage, sampling problems, fairness risks, and deployment limitations;
  • evaluate a predictive-analytics solution in a realistic business case.

1. The Predictive Modeling Problem

Let a dataset contain observations indexed by i. Each observation has a feature vector xi = (xi1, xi2, ..., xip) and, for supervised learning, a target yi. A predictive model is a function \hat{y}i = f(xi; θ), where θ denotes parameters learned from data. The hat indicates a prediction rather than the observed value.

The model is trained by minimizing a loss function. In general:

θ̂ = arg min_θ (1/n) ∑i=1n L(yi, f(xi; θ))

Here, n is the number of training observations and L measures prediction error. The choice of loss should reflect the task: squared error is common for regression, while log loss is common for probabilistic classification. Minimizing training loss alone is insufficient because a very flexible model can memorize the training data.

Generalization, bias, and variance

Generalization is the ability to perform well on unseen observations from the relevant population. Underfitting occurs when a model is too simple to capture important structure. Overfitting occurs when a model learns noise, idiosyncrasies, or leakage in the training sample and performs poorly on new data.

Prediction error can be understood conceptually as a combination of irreducible noise, squared bias, and variance. For squared-error prediction at a given input, the decomposition is commonly represented as:

Expected prediction error = noise variance + bias² + variance

Bias is systematic error caused by restrictive assumptions; variance is sensitivity to the particular sample used for training. More complex models often reduce bias but increase variance. Regularization, larger samples, better features, and sound validation can improve this trade-off.

2. Data Preparation and Leakage Control

Data preparation is part of modeling, not an administrative prelude. Analysts should document the data-generating process, missing-value mechanisms, measurement units, business definitions, and the time at which each variable becomes available.

Units of analysis and target definition

The unit might be a customer, transaction, account-month, employee, store-day, or shipment. A target must be defined precisely. For churn, for example, “customer churns within 30 days after the scoring date” is more useful than “customer is likely to leave.” The prediction horizon determines which features are legitimate.

Training, validation, and test sets

The training set is used to estimate model parameters. The validation set is used to select algorithms, features, and hyperparameters. The test set is held back until the final model is fixed and provides an approximately unbiased estimate of performance on future data.

For independent and identically distributed observations, a random split may be reasonable. For time-dependent data, use an earlier period for training and a later period for validation and testing. For grouped observations, such as several transactions from one customer, group-aware splitting prevents records from the same entity appearing in both training and test sets.

A common workflow is cross-validation. In k-fold cross-validation, the training data are partitioned into k folds. Each fold is used once for validation while the remaining folds are used for training. The average validation score estimates expected performance, and the variation across folds indicates instability. Cross-validation must be performed inside the training portion; the test set must remain untouched.

Data leakage

Leakage occurs when information unavailable at prediction time enters the model. Examples include:

  • using a loan’s eventual default status to predict whether it will default;
  • calculating a customer’s “current” balance using transactions recorded after the scoring date;
  • imputing missing values using the entire dataset before splitting;
  • allowing duplicate customers to occur in both training and test data;
  • selecting features because they correlate with the target in the test set.

All learned transformations—scaling, imputation, encoding, feature selection, and dimensionality reduction—should be fitted on training data only and then applied to validation or test data. A reproducible pipeline makes this rule operational.

3. Regression

Regression predicts a numerical target such as revenue, demand, delivery time, or credit loss. The simplest model is multiple linear regression:

yi = β0 + β1xi1 + β2xi2 + ... + βpxip + εi

Here, β₀ is the intercept, βⱼ is the expected change in the target associated with a one-unit increase in feature xⱼ, holding the other included features constant, and εᵢ is an error term. The target and features must have meaningful units. The “holding other features constant” interpretation is associational, not automatically causal.

Ordinary least squares estimates coefficients by minimizing the sum of squared residuals:

β̂ = arg min_β ∑i=1n (yi − xiᵀβ)²

The method is especially interpretable when relationships are approximately linear, observations are appropriately independent, predictors are not perfectly collinear, and residual behavior is acceptable. Normal residuals are not required for prediction, but they matter for some classical inferential procedures.

Regression metrics

Let ei = yi − ŷi be the residual for observation i.

Mean absolute error (MAE) is:

MAE = (1/n) ∑i=1n |yi − ŷi|

MAE is in the target’s units and gives equal absolute weight to errors.

Mean squared error (MSE) is:

MSE = (1/n) ∑i=1n (yi − ŷi)²

Root mean squared error (RMSE) is:

RMSE = √MSE

RMSE is also in the target’s units but penalizes large errors more strongly. Mean absolute percentage error is:

MAPE = (100/n) ∑i=1n |(yi − ŷi)/yi|

MAPE is inappropriate when actual values are zero or close to zero and can overemphasize errors on small denominators. The coefficient of determination is:

R² = 1 − [∑(yi − ŷi)² / ∑(yi − ȳ)²]

where ȳ is the training or evaluation-sample mean, as specified. R² compares the model with a mean-only baseline; it is not a percentage of accuracy and may be negative on test data.

Worked regression example

Suppose actual weekly demand is [100, 120, 80] units and predicted demand is [90, 130, 70]. The absolute errors are 10, 10, and 10, so:

MAE = (10 + 10 + 10)/3 = 10 units

The squared errors are 100, 100, and 100. Therefore:

MSE = 300/3 = 100 units²; RMSE = √100 = 10 units

Both metrics happen to be numerically 10 here, but they are not conceptually interchangeable and generally differ.

4. Classification

Classification predicts a category, such as fraud versus legitimate, retained versus churned, or approved versus declined. Binary classifiers often estimate a probability:

pi = P(Yi = 1 | xi)

A decision threshold converts probability into a class. Predict class 1 when pi ≥ τ, where τ is selected according to the relative costs of false positives and false negatives.

The confusion matrix contains four outcomes:

Actual positiveActual negative
Predicted positiveTrue positive (TP)False positive (FP)
Predicted negativeFalse negative (FN)True negative (TN)

Accuracy is:

Accuracy = (TP + TN)/(TP + TN + FP + FN)

Precision, also called positive predictive value, is:

Precision = TP/(TP + FP)

Recall, or sensitivity, is:

Recall = TP/(TP + FN)

Specificity is TN/(TN + FP). The F1 score is the harmonic mean of precision and recall:

F1 = 2 × (Precision × Recall)/(Precision + Recall)

These metrics assume the denominators are nonzero. Accuracy can be misleading under class imbalance. For a rare-fraud problem, a classifier that labels every transaction legitimate may have high accuracy but zero recall for fraud.

The receiver operating characteristic (ROC) curve plots recall against false-positive rate over thresholds. Its area, ROC-AUC, measures ranking ability across thresholds. Precision-recall curves are often more informative when the positive class is rare. A probability model should also be assessed for calibration: among cases assigned probability 0.7, approximately 70% should be positive in a well-calibrated group.

Cost-sensitive decisions

Metrics should reflect consequences. If a false negative costs CFN and a false positive costs CFP, the expected cost for a decision rule can be estimated as:

Expected cost = CFN × FN + CFP × FP

This simplified expression assumes each error has the same cost within its category and ignores operational benefits and true-negative costs. In practice, threshold selection should consider intervention capacity, customer impact, and uncertainty.

5. Clustering and Dimensionality Reduction

Clustering groups observations so that members of the same group are more similar under a selected representation and distance measure. It is exploratory: clusters are not automatically natural, stable, or economically meaningful.

k-means clustering

Given a chosen number of clusters k, k-means seeks centroids μ1, μ2, ..., μk that minimize within-cluster squared Euclidean distance:

minC1,...,Ck, μ1,...,μk ∑j=1k ∑xi ∈ Cj ||xi − μj||²

The algorithm alternates between assigning each observation to its nearest centroid and recalculating each centroid as the arithmetic mean of its assigned points. It can converge to a local optimum, so multiple initializations are advisable.

K-means assumes that numeric features are meaningfully scaled, uses a distance geometry that may not fit the domain, and tends to favor compact, roughly spherical clusters of comparable scale. Standardization is often needed:

zij = (xij − μj)/σj

where μⱼ and σⱼ are the training-data mean and standard deviation for feature j. The transformation is dimensionless and must be fitted only on training data when clustering supports a later predictive task.

The number of clusters may be explored using the elbow method, silhouette coefficient, stability analysis, and—most importantly—business interpretability. Hierarchical clustering, density-based methods such as DBSCAN, and mixture models offer alternatives when cluster shape or noise structure differs.

Principal component analysis (PCA) creates orthogonal linear combinations of centered features. It can reduce dimensionality, compress correlated variables, and support visualization, but components may be difficult to interpret and should not be treated as business constructs without analysis.

6. Time-Series Forecasting

Time-series data are ordered observations indexed by time, such as daily sales or monthly website visits. Their special features include trend, seasonality, autocorrelation, changing variance, calendar effects, and structural breaks.

A simple baseline is the naïve forecast:

ŷt+1 = yt

For seasonal data with period s, a seasonal naïve forecast is:

ŷt+s = yt

Baselines are essential: a sophisticated model should outperform a credible simple alternative.

An autoregressive model of order p is:

yt = c + φ1yt−1 + φ2yt−2 + ... + φpyt−p + εt

where c is a constant, φⱼ are autoregressive coefficients, and εₜ is an innovation term. Forecast validation must preserve chronology. Randomly mixing future observations into training produces optimistic results.

Forecast accuracy can be measured with MAE, RMSE, or scale-free measures such as mean absolute scaled error. Prediction intervals are often more useful than point forecasts because managers need to know uncertainty. Intervals become wider as the forecast horizon increases and may be unreliable if the data-generating process changes.

7. Anomaly Detection

An anomaly is an observation that differs substantially from expected behavior. It may represent fraud, equipment failure, a data-quality problem, or a legitimate rare event. The correct response depends on context; unusual does not mean wrong.

A univariate standardized score is:

zi = (xi − μ)/σ

where μ and σ are estimated from a suitable reference population. A large absolute score may flag an observation, but the threshold is domain-dependent and the mean and standard deviation can be distorted by outliers.

The interquartile range rule uses IQR = Q3 − Q1. Observations below Q1 − 1.5 × IQR or above Q3 + 1.5 × IQR are often flagged as potential outliers. This is a screening rule, not proof of error.

Multivariate methods include isolation forests, local outlier factor, one-class support vector machines, and autoencoders. Analysts should evaluate alert volume, investigation capacity, false-alert costs, and temporal drift. When labeled incidents exist, anomaly detection should be assessed as a classification or ranking problem rather than only by an unsupervised score.

8. Feature Selection and Regularization

Features should be selected for predictive value, availability, stability, interpretability, and ethical appropriateness. Remove identifiers that merely memorize entities unless entity effects are explicitly intended and validated. Examine missingness, leakage, high cardinality, redundant variables, and post-outcome fields.

Filter methods select variables using statistics independent of a final model, such as correlation or mutual information. Wrapper methods evaluate subsets through model performance, such as recursive feature elimination. Embedded methods perform selection during estimation, as in regularized regression or tree-based importance. Selection must occur inside cross-validation to avoid optimistic estimates.

Ridge regression adds an L2 penalty:

min_β ∑i=1n(yi − xiᵀβ)² + λ∑j=1pβj²

Lasso regression adds an L1 penalty:

min_β ∑i=1n(yi − xiᵀβ)² + λ∑j=1p|βj|

Here, λ ≥ 0 controls regularization strength. The intercept is usually not penalized, and predictors should generally be standardized when penalty magnitudes are to be comparable. Larger λ increases bias and typically reduces variance. Lasso can set coefficients exactly to zero, although selection can be unstable with highly correlated predictors. Elastic net combines L1 and L2 penalties.

Regularization does not replace validation. The penalty parameter must be selected using training data and validation or nested cross-validation. A test set used repeatedly for tuning is no longer a genuine test set.

9. Model Selection, Explainability, and Overfitting Control

Candidate models may include linear or logistic regression, decision trees, random forests, gradient boosting, support vector machines, and neural networks. The best choice depends on sample size, data type, latency, interpretability, maintenance, and error costs—not merely on the highest single score.

Decision trees recursively partition the feature space and are easy to visualize but can overfit. Bagging methods such as random forests reduce variance by averaging many randomized trees. Boosting builds learners sequentially to correct previous errors and can be highly accurate, but it requires careful tuning and may be sensitive to leakage and drift.

Controls against overfitting include:

  • simpler models and meaningful baselines;
  • cross-validation and an untouched test set;
  • regularization, pruning, early stopping, and limited tree depth;
  • more representative data;
  • feature selection and leakage audits;
  • data augmentation only where it preserves the data-generating logic;
  • monitoring performance after deployment.

Explainability

Global explanations describe overall behavior, such as coefficients, partial dependence, permutation importance, or summary plots. Local explanations describe one prediction, using methods such as local surrogate models or SHAP-style additive attribution. Explanations are approximations and can be unstable when predictors are correlated or the model is extrapolating.

A coefficient is not automatically a causal effect. Feature importance is not fairness, and a plausible explanation does not prove that the model is valid. Explanations should be accompanied by uncertainty, data coverage, and documentation of the model’s intended use.

10. Applied Case: Illustrative Retail Churn Model

Background

The following is a fictional illustrative case. A subscription retailer wants to identify customers who are likely to cancel within the next 30 days so that a retention team can offer appropriate assistance.

Problem definition

The unit of analysis is a customer at a weekly scoring date. The target is cancellation during the subsequent 30 days. Candidate features include recent purchase frequency, customer-service contacts, tenure, payment failures recorded before the scoring date, and recent engagement. The team must not use cancellation requests, refunds processed after the scoring date, or any field created after the outcome window begins.

Analysis and approach

The analyst creates customer-week records and uses the first 70% of calendar time for training, the next 15% for validation, and the final 15% for testing. All customers from a given scoring record remain in one temporal partition. Missing-value imputation, scaling, and feature selection are fitted within the training pipeline.

A logistic-regression baseline is compared with a gradient-boosted tree model. The evaluation emphasizes recall among the top 10% of customers that the retention team can contact, precision at that operating point, calibration, and expected intervention cost. ROC-AUC alone is rejected as the main decision metric because churn is relatively uncommon and capacity is limited.

Suppose the final test-period results for 1,000 customers at the selected threshold are TP = 72, FP = 78, FN = 48, and TN = 802. Then:

Precision = 72/(72 + 78) = 0.48
Recall = 72/(72 + 48) = 0.60
Accuracy = (72 + 802)/1000 = 0.874

The F1 score is approximately:

F1 = 2 × (0.48 × 0.60)/(0.48 + 0.60) ≈ 0.533

Although accuracy is 87.4%, it does not reveal that 40% of actual churners were missed. Management should compare the expected value of interventions with the cost of contacting customers and the possible harm of inappropriate offers.

Outcome and governance

The team deploys a weekly scoring pipeline with a human review process. It monitors calibration, recall, precision, contact volume, subgroup performance, feature drift, and realized cancellation rates. Customers are not denied a service because of the score; the model prioritizes supportive outreach. A model card records the training period, target definition, exclusions, metrics, limitations, and escalation process.

Learning points

The case demonstrates that a business model requires a precise prediction horizon, temporal leakage controls, capacity-aware metrics, threshold selection, calibration, monitoring, and governance. A technically accurate model can still fail if the intervention is poorly designed or if the target is defined inconsistently.

11. Ethics, Governance, and Contemporary Practice

Predictive systems can reproduce historical discrimination. Protected attributes may be excluded while proxies—such as location, language, purchasing patterns, or employment history—retain similar information. Fairness must therefore be investigated empirically and contextually. Relevant measures may include group-specific false-positive and false-negative rates, selection rates, calibration, and equalized performance, but these criteria can conflict mathematically and normatively. There is no universal fairness metric.

Organizations should establish purpose limitation, data minimization, access controls, retention rules, audit trails, and human accountability. Individuals may require notice, explanation, correction, or appeal depending on the application and applicable law. High-impact decisions demand stronger validation and oversight than low-risk recommendation systems.

Contemporary practice increasingly uses automated machine-learning operations (MLOps): versioned data and code, reproducible pipelines, model registries, continuous monitoring, drift detection, and controlled rollback. Generative AI may assist with feature engineering, documentation, or code generation, but outputs require testing. It should not be treated as an evidence source or allowed to expose confidential data without appropriate controls.

Concept drift occurs when the relationship between inputs and outcomes changes. Data drift occurs when the distribution of inputs changes. Both can reduce performance. Monitoring should include not only technical metrics but also business outcomes, subgroup impacts, alert fatigue, and changes in operating conditions.

Best-Practice Checklist

Before deployment, an analyst should be able to answer “yes” to the following questions:

  • Is the target, horizon, unit of analysis, and decision action explicit?
  • Does every feature exist at the time of prediction?
  • Were splitting and preprocessing designed to prevent leakage?
  • Was a credible baseline evaluated?
  • Do metrics reflect class balance, capacity, uncertainty, and business costs?
  • Was the final test set used only after model selection?
  • Are explanations, limitations, and subgroup results documented?
  • Is there a monitoring, retraining, appeal, and retirement plan?
  • Has the use been reviewed for privacy, fairness, security, and regulatory risk?

Chapter Summary

Predictive analytics converts data into estimates that support future-oriented decisions. Regression predicts numerical quantities, classification predicts categories or probabilities, clustering discovers groups, time-series models exploit temporal structure, and anomaly detection identifies unusual observations. Each task requires a definition of the prediction target, observation unit, information-availability point, and decision context.

Reliable evaluation depends on appropriate train-validation-test workflows, temporal or group-aware splitting where necessary, leakage prevention, and metrics aligned with consequences. MAE, RMSE, precision, recall, F1, calibration, clustering diagnostics, and forecast baselines answer different questions. Feature selection and regularization can reduce overfitting, while explainability helps users understand model behavior without implying causation. Deployment adds responsibilities involving fairness, privacy, security, monitoring, drift, documentation, and human accountability.

Key Terms

Predictive analytics: Analysis that estimates future or unknown outcomes from data.

Supervised learning: Learning from observations with a known target.

Unsupervised learning: Learning structure without a specified target.

Regression: Prediction of a numerical outcome.

Classification: Prediction of a categorical outcome.

Feature: An input variable used by a model.

Target: The outcome a supervised model predicts.

Generalization: Performance on relevant unseen data.

Overfitting: Learning noise or sample-specific patterns that do not generalize.

Data leakage: Use of information unavailable at prediction time.

Cross-validation: Repeated partitioning of training data for model assessment or tuning.

Precision: The proportion of predicted positives that are truly positive.

Recall: The proportion of actual positives correctly identified.

Calibration: Agreement between predicted probabilities and observed frequencies.

Clustering: Grouping observations according to similarity.

Regularization: Penalization used to constrain model complexity.

Feature selection: Choosing a subset of input variables.

Explainability: Methods for describing model behavior or individual predictions.

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

Anomaly detection: Identification of observations that differ from expected patterns.

Review Questions

Short Answer Questions

  1. What is the difference between a validation set and a test set?
  2. Why can accuracy be misleading for rare-event classification?
  3. State one condition under which random train-test splitting is inappropriate.
  4. What does the regularization parameter λ control?
  5. Why is a naïve forecast an important benchmark?

Long Answer Questions

  1. Explain the bias-variance trade-off and describe at least three methods for controlling overfitting.
  2. Compare MAE, RMSE, MAPE, and R², including situations in which each may be unsuitable.
  3. Explain how data leakage can arise during preprocessing and feature engineering.
  4. Compare k-means clustering with a density-based clustering approach, including assumptions and business applications.
  5. Discuss how explainability, fairness, privacy, and monitoring should be incorporated into a deployed predictive model.

Analytical / Application Questions

  1. A fraud classifier produces TP = 45, FP = 15, FN = 30, and TN = 910. Calculate precision, recall, and accuracy. Which metric would you prioritize if missed fraud is much more costly than investigation?
  2. A retailer has daily sales with strong weekly seasonality. Design a train-validation-test procedure and select an appropriate baseline. Explain why a random split could produce misleading results.
  3. A churn model has excellent test accuracy but performs poorly for a small customer group. Propose an investigation and remediation plan covering data, metrics, thresholding, fairness, and governance.

Multiple Choice Questions with Answers

Question 1

Which dataset should normally remain untouched until the final model has been selected?

A. Training set

B. Validation set

C. Test set

D. Feature-engineering set

Correct Answer: C. Test set

Question 2

A classifier has TP = 80 and FP = 20. What is its precision?

A. 0.20

B. 0. fifty

C. 0.80

D. 0. same

Correct Answer: C. 0.80

Question 3

Which situation is a clear example of data leakage?

A. Standardizing a feature using training-set mean and standard deviation

B. Using a customer’s post-cancellation refund to predict cancellation

C. Using a naïve forecast as a benchmark

D. Removing duplicate records before splitting by customer

Correct Answer: B. Using a customer’s post-cancellation refund to predict cancellation

Question 4

Which metric penalizes large regression errors more strongly than MAE?

A. RMSE

B. Recall

C. Precision

D. Specificity

Correct Answer: A. RMSE

Question 5

What is the main effect of increasing the regularization parameter in a penalized regression model?

A. It generally increases model flexibility without constraint

B. It generally constrains coefficients and can reduce variance

C. It guarantees zero prediction error

D. It converts regression into clustering

Correct Answer: B. It generally constrains coefficients and can reduce variance

Question 6

Why should features commonly be standardized before k-means clustering?

A. To make all observations identical

B. To ensure distance is not dominated by feature scale

C. To remove the need to select the number of clusters

D. To guarantee globally optimal clusters

Correct Answer: B. To ensure distance is not dominated by feature scale

Question 7

Which validation design is most appropriate for forecasting future demand?

A. Randomly mixing all dates before splitting

B. Training on later dates and testing on earlier dates

C. Training on earlier periods and validating on later periods

D. Using only the highest-demand weeks

Correct Answer: C. Training on earlier periods and validating on later periods

Question 8

If a business wants to catch as many actual fraud cases as possible, which metric is most directly relevant?

A. Recall

B. Precision only

C. R²

D. Silhouette coefficient

Correct Answer: A. Recall

Question 9

What does calibration assess in a probabilistic classifier?

A. Whether predicted probabilities correspond to observed frequencies

B. Whether all coefficients are statistically significant

C. Whether clusters are spherical

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

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

Question 10

Which statement about anomaly detection is most accurate?

A. Every anomaly is necessarily an error

B. An anomaly score automatically establishes fraud

C. An unusual observation may be a valid rare event or a data problem

D. Anomaly detection never requires domain knowledge

Correct Answer: C. An unusual observation may be a valid rare event or a data problem

Data Analytics & Visualization
Chapter 11 of 15