Data Mining and Data Warehousing

Chapter 8
Classification and Predictive Modeling

Bachelors Program in AI & ML
Data Mining and Data Warehousing   •   Bachelor

Classification and Predictive Modeling

Introduction and Context

Classification is the task of assigning an observation to one of a set of predefined categories. Predictive modeling uses historical data to learn relationships between input variables and an outcome, then applies those relationships to new cases. In data mining and data warehousing, classification commonly supports credit-risk assessment, customer retention, medical diagnosis, fraud detection, quality control, document categorization, and recommendation systems.

A classification problem contains a target variable, usually called the class label, and one or more predictor variables. For example, a bank may use income, debt ratio, repayment history, and account age to classify a loan application as low or high risk. The model is trained using labeled historical records and evaluated on data that were not used during training.

Classification differs from clustering. Classification is supervised: the desired classes are known during training. Clustering is unsupervised: the algorithm discovers groups without a predefined target. Classification also differs from regression, whose target is numerical and continuous, such as sales revenue or house price. Some classifiers produce only a class, while others produce class probabilities that support ranking and risk-sensitive decisions.

Learning Objectives

After studying this chapter, you should be able to:

1. Explain the classification workflow and distinguish training, validation, and test data.

2. Construct and interpret decision-tree, rule-based, probabilistic, nearest-neighbor, logistic, and ensemble classifiers.

3. Select suitable evaluation metrics for balanced and imbalanced data.

4. Explain overfitting, regularization, resampling, and hyperparameter tuning.

5. Compare model interpretability, predictive performance, computational cost, and operational risk.

6. Apply classification methods to a realistic business or public-sector problem.

The Classification Workflow

A reliable classification project begins with a precise decision problem. The analyst must define the population, prediction time, outcome window, allowable predictors, and cost of errors. A model predicting customer default within 90 days is different from one predicting default within five years. The data must be available at the time the prediction is made; using later information creates target leakage.

A typical workflow is:

1. Data understanding and preparation. Inspect data types, missing values, outliers, duplicate records, class proportions, and possible leakage. Encode categorical variables, scale features when required, and document transformations.

2. Data splitting. Divide observations into training and test sets. A validation set or cross-validation is used for model selection. In temporal applications, chronological splitting is often safer than random splitting.

3. Model training. Estimate model parameters from the training data.

4. Model selection and tuning. Select algorithms and hyperparameters using validation data or cross-validation, without repeatedly using the final test set.

5. Evaluation. Assess discrimination, calibration, error costs, subgroup performance, and operational feasibility.

6. Deployment and monitoring. Record model versions, input definitions, predictions, outcomes, and drift indicators. Retrain only under a controlled process.

For a binary problem, let the actual class be either positive or negative and the prediction have the same two possibilities. The confusion matrix contains:

  • True positive (TP): a positive case correctly identified.
  • True negative (TN): a negative case correctly identified.
  • False positive (FP): a negative case incorrectly flagged positive.
  • False negative (FN): a positive case missed by the model.

Accuracy is

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

It is useful when class proportions and error costs are reasonably balanced. Precision, also called positive predictive value, is

Precision = TP / (TP + FP),

provided the denominator is nonzero. Recall, or sensitivity, is

Recall = TP / (TP + FN),

provided the denominator is nonzero. The F1 score is the harmonic mean of precision and recall:

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

when both measures are defined. Specificity is TN/(TN+FP). A classifier may rank cases well but use a poor decision threshold. Consequently, threshold selection should reflect the relative costs of false positives and false negatives.

For example, suppose a screening model produces TP = 80, FN = 20, FP = 40, and TN = 860. Accuracy is 940/1000 = 0.94, precision is 80/120 = 0.667, recall is 80/100 = 0.80, and specificity is 860/900 = 0.956. The high accuracy should not obscure the fact that one-third of flagged cases are false positives and one-fifth of actual positive cases are missed.

For probabilistic predictions, the receiver operating characteristic (ROC) curve plots true-positive rate against false-positive rate over thresholds. The area under this curve, ROC-AUC, measures ranking ability across thresholds. Precision–recall curves are often more informative when the positive class is rare. Calibration asks whether predicted probabilities correspond to observed frequencies; among cases assigned probability near 0.7, approximately 70% should be positive in a well-calibrated model.

Decision Trees

A decision tree recursively partitions the feature space using questions such as “Is income less than 40,000?” or “Is account type equal to business?” Internal nodes contain tests, branches represent outcomes, and leaves contain predicted classes or probabilities. Trees are attractive because their logic is visual and can represent nonlinear relationships and interactions without explicit feature engineering.

A common split criterion is entropy. If a node contains class proportions p1, p2, ..., pk, its entropy is

H(S) = −Σ(i=1 to k) pi log2(pi).

The convention 0 log2 0 = 0 is used. Entropy is zero when a node is pure and is largest when classes are evenly distributed. For a candidate split producing child nodes S1, ..., Sm, information gain is

IG = H(S) − Σ(j=1 to m) (|Sj|/|S|) H(Sj).

The split with larger gain produces a greater reduction in weighted impurity. Another widely used measure is the Gini impurity:

Gini(S) = 1 − Σ(i=1 to k) pi².

Both measures are suitable for categorical classification; differences between them are often less important than pruning and validation.

Worked split example

A node contains 10 records: six “approve” and four “reject.” Its entropy is approximately −0.6 log2(0.6) − 0.4 log2(0.4) = 0.971 bits. A candidate split creates a left child with four approve and one reject, and a right child with two approve and three reject. The left entropy is approximately 0.722 and the right entropy is approximately 0.971. Weighted child entropy is (5/10)(0.722) + (5/10)(0.971) = 0.847. Information gain is therefore 0.971 − 0.847 = 0.124 bits. This calculation compares candidate splits; it does not by itself establish that the tree will generalize well.

A fully grown tree can memorize noise. Pre-pruning limits growth through maximum depth, minimum samples per leaf, minimum impurity decrease, or maximum number of leaves. Post-pruning first grows a larger tree and then removes branches that do not improve validation performance. A cost-complexity objective can be written as

Rα(T) = R(T) + α|T|,

where R(T) is training impurity or error, |T| is a measure of tree size, and α ≥ 0 controls the penalty. The exact implementation may define tree size and impurity in different ways, so the objective should be interpreted according to the software and documentation used.

Advantages of trees include interpretability, mixed-type feature support, and limited scaling requirements. Limitations include instability under small data changes, bias toward features with many possible split points in some criteria, and weaker extrapolation than certain parametric models.

Rule-Based Classification

A rule-based classifier expresses decisions as IF–THEN statements, for example:

IF missed payments ≥ 2 AND debt ratio > 0.5 THEN high risk.

Rules can be extracted from trees, learned directly, or supplied by domain experts. A rule has an antecedent (conditions) and a consequent (class prediction). Coverage is the proportion of records satisfying the antecedent. Accuracy or confidence is the proportion of covered records that belong to the predicted class:

Confidence(rule) = records satisfying antecedent and consequent / records satisfying antecedent.

Rules may overlap or conflict. A rule list imposes an order, with the first matching rule applied; a rule set needs a conflict-resolution policy, such as highest confidence or weighted voting. An explicit default rule handles records matching no rule.

Rule systems are valuable when regulations or business procedures require traceable logic. They can, however, become long, brittle, and difficult to maintain. A high-confidence rule with very low coverage may be operationally unimportant. Rules should therefore be evaluated using both predictive quality and coverage, and reviewed for fairness and stability.

Probabilistic Classifiers

Probabilistic classifiers estimate P(Y = c | X), the probability that class Y equals c given features X. They support ranking, threshold adjustment, and expected-cost decisions.

Naive Bayes

Bayes’ theorem gives

P(Y=c | X) = P(X | Y=c)P(Y=c) / P(X).

The denominator normalizes probabilities across classes. Naive Bayes assumes that features are conditionally independent given the class:

P(X | Y=c) = Π(j=1 to d) P(Xj | Y=c).

Thus classification selects the class maximizing P(Y=c) multiplied by the product of class-conditional feature probabilities. In practice, logarithms are used to avoid numerical underflow. For categorical data, Laplace smoothing can prevent a zero probability for an unseen feature value. For continuous data, a Gaussian version commonly assumes each feature is normally distributed within a class, although this assumption can be imperfect.

The independence assumption is usually false, but the classifier can still perform well, especially with text and high-dimensional sparse data. Its benefits are speed, small memory requirements, and useful baseline performance. Its probabilities may require calibration.

Logistic regression

For binary classification, logistic regression models the log odds of the positive class:

log[p(x)/(1−p(x))] = β0 + β1x1 + ... + βdxd.

Equivalently,

p(x) = 1/[1 + exp(−(β0 + Σj βjxj))].

Here p(x) is the estimated probability of the positive class, β0 is the intercept, and βj is the coefficient for feature xj. A one-unit increase in xj changes the log odds by βj, holding other variables constant. The odds ratio is exp(βj), subject to the model’s linearity and coding assumptions. Logistic regression estimates coefficients by maximizing likelihood, or equivalently minimizing negative log-likelihood.

Regularization is often added. L2 regularization penalizes large coefficients using λΣj βj²; L1 regularization uses λΣj |βj|. The intercept is commonly excluded from the penalty. λ controls the trade-off between fit and coefficient size and must be selected using validation. L1 can set some coefficients exactly to zero, supporting feature selection; L2 generally shrinks correlated coefficients together. Standardization is important when comparing or penalizing numerical features on different scales.

Logistic regression is interpretable and often well calibrated, but its basic form assumes a linear relationship between predictors and log odds. Interactions, nonlinear transformations, splines, or alternative models may be needed. Coefficients should not be interpreted causally unless the study design and assumptions support causal inference.

Nearest-Neighbor Classification

The k-nearest-neighbor (k-NN) method stores training examples. To classify a new observation, it identifies the k closest training observations and assigns the majority class, or a distance-weighted vote. For numerical vectors, Euclidean distance is

d(x,z) = √[Σj (xj − zj)²].

This distance is meaningful only when features are appropriately scaled and comparable. Other distances may be suitable for binary, categorical, text, or mixed data. A small k produces flexible boundaries and low bias but can be sensitive to noise. A large k smooths the boundary, increasing bias and often reducing variance. k must be selected using validation.

The method is simple and can represent complex boundaries, but prediction can be expensive for large datasets, storage-intensive, and vulnerable to irrelevant features. In high-dimensional spaces, distances become less discriminative, a phenomenon often called the curse of dimensionality. Approximate nearest-neighbor indexes and dimensionality reduction can improve scalability, but they introduce design trade-offs.

Ensemble Classifiers

Ensemble learning combines multiple models. The goal is often to reduce variance, bias, or sensitivity to a particular sample.

Bagging trains models on bootstrap samples and aggregates their predictions. Random forests are bagged decision trees with random feature selection at each split, which reduces correlation among trees. For classification, majority voting or averaged class probabilities is used. Random forests are robust and effective on tabular data, though individual-tree explanations can be difficult and probability calibration may need attention.

Boosting trains weak learners sequentially, emphasizing observations that previous learners handled poorly. Gradient boosting fits new learners to reduce a differentiable loss function. Important hyperparameters include number of learners, learning rate, tree depth, and subsampling. Smaller learning rates often require more learners. Boosting can be highly accurate but may overfit noisy data and is sensitive to tuning and data quality.

Stacking combines predictions from different base models through a meta-model. To avoid leakage, the meta-model should be trained on out-of-fold predictions rather than predictions generated from the same records used to fit each base learner.

Ensembles can improve predictive performance, but complexity affects latency, monitoring, interpretability, and governance. The most accurate model is not automatically the best model when decisions must be justified or challenged.

Overfitting, Generalization, and Model Selection

Overfitting occurs when a model captures random variation or peculiarities of the training data rather than general patterns. It typically produces low training error but substantially higher validation or test error. Underfitting occurs when the model is too simple to capture important structure.

Generalization performance is estimated using unseen data. In k-fold cross-validation, the training data are divided into k folds; each fold is used once for validation while the remaining folds are used for training. The reported score is commonly the mean across folds, and variation across folds should also be considered. For time-dependent data, random folds may leak future information; rolling or forward-chaining evaluation is more appropriate.

A sound model-selection procedure keeps the test set untouched until the final evaluation. Feature selection, imputation, scaling, and resampling must be fitted within each training fold. If preprocessing is performed before cross-validation, information from validation folds can leak into training and produce optimistic results.

Regularization, simpler models, pruning, early stopping, more data, feature selection, and augmentation can reduce overfitting. Hyperparameter search should be constrained by computational budget and reproducible through recorded seeds, data versions, and configurations.

Class Imbalance and Decision Thresholds

Class imbalance occurs when one class is much more common than another. Accuracy can then be misleading. A model that labels every case as the majority class may achieve 99% accuracy when the minority class is only 1%, while detecting no cases of practical interest.

Useful responses include stratified splitting, class-weighted loss, over- or under-sampling, synthetic sampling, anomaly-detection methods, and threshold adjustment. Resampling must be applied only to training folds; oversampling before splitting duplicates information across training and validation data. Synthetic examples should be inspected for plausibility and should not be treated as independent real-world evidence.

The appropriate metric depends on the decision. Recall may be prioritized in disease screening, precision in expensive investigations, and a cost-weighted measure in fraud operations. If the cost of a false negative is C_FN and the cost of a false positive is C_FP, a simple expected-cost estimate is

Expected cost = C_FN × FN + C_FP × FP,

possibly with additional costs for correct decisions and unequal case volumes. A probability threshold should be selected using validated probabilities and explicit costs, not automatically fixed at 0.5.

Interpretability, Fairness, and Governance

Interpretability has several meanings. A decision tree or sparse logistic model may be intrinsically interpretable: its complete logic or coefficients can be inspected. A complex ensemble may require post hoc explanations. Global explanations describe overall feature influence; local explanations describe one prediction. Feature importance is not automatically causal evidence, and correlated predictors can make importance unstable.

Useful practices include documenting the target definition, data provenance, feature construction, exclusions, performance by subgroup, threshold policy, and known limitations. Explanations should be faithful to the model, understandable to the audience, and accompanied by uncertainty. In high-impact settings, individuals may require notice, contestability, human review, and an appeal process.

Fairness analysis should examine whether error rates, selection rates, calibration, and access differ across relevant groups. Metrics can conflict: satisfying equalized error rates may not be compatible with equal calibration when base rates differ. Sensitive attributes may be excluded from a model yet remain inferable through proxy variables. Fairness is therefore a socio-technical governance issue, not merely a feature-removal exercise.

Privacy requirements may constrain collection, linkage, retention, and use of personal data. Security controls should protect training data and model interfaces from unauthorized access and manipulation. Organizations should maintain audit trails, approval responsibilities, drift monitoring, incident procedures, and documented retirement criteria.

Illustrative Case: Predicting Customer Loan Delinquency

Background

A regional bank wants to identify accounts likely to become 60 days delinquent within the next three months. The aim is to offer early assistance, not to automate irreversible denial decisions.

Problem and analysis

The data warehouse contains monthly account snapshots, repayment history, income bands, utilization, product type, customer tenure, and prior support contacts. Analysts discover that a “collection action completed” field is recorded after delinquency and must be excluded because it leaks the target. Only information available at the snapshot date is retained. Delinquency is 4% of observations, so accuracy alone is rejected as the principal metric.

The team uses chronological training, validation, and test periods to reflect deployment. Missing numerical values are imputed within training folds, categorical variables are encoded through a pipeline, and the minority class receives a training weight. Candidate models include a pruned tree, logistic regression, random forest, and gradient boosting. Logistic regression provides a transparent baseline; boosting obtains higher recall at a specified precision, while the tree offers easily communicated rules.

Approach and solution

The bank chooses a calibrated boosting model for prioritizing outreach, supplemented by a short rule-based explanation and human review. A threshold is selected using the cost of unnecessary contact, the cost of missed support opportunities, and staff capacity. Performance is reported by month and by relevant customer groups. The model is not used as the sole basis for refusing credit. Customers can request review, and support staff are instructed not to treat a model score as proof of future behavior.

Outcome and learning points

In a pilot, the model helps staff focus on a smaller group while identifying a substantial share of future delinquencies. Monitoring reveals that an economic shock changes repayment patterns, causing calibration drift. The bank responds by reviewing thresholds and retraining under governance controls rather than silently changing the model.

The case demonstrates that a classifier is part of a decision system. Success depends on leakage prevention, temporal validation, suitable metrics, calibration, human processes, fairness review, and ongoing monitoring—not just the algorithm with the highest test score.

Contemporary Developments and Best Practices

Modern classification systems increasingly combine structured warehouse data with text, images, graphs, and streaming events. Automated machine-learning tools can accelerate model comparison, but they do not replace problem definition, leakage checks, subgroup analysis, or accountability. Explainable boosting, monotonic constraints, calibrated ensembles, conformal prediction, and fairness-aware learning are useful developments, but each introduces assumptions and operational costs.

Recommended practices are:

  • Define the target and prediction horizon before selecting features.
  • Use a leakage-resistant, reproducible preprocessing pipeline.
  • Establish a simple baseline before complex models.
  • Use metrics aligned with error costs and class prevalence.
  • Tune and preprocess within validation folds.
  • Examine calibration, subgroup performance, and temporal stability.
  • Prefer the least complex model that meets the operational requirement.
  • Document data, assumptions, limitations, approvals, and model changes.
  • Monitor drift, missingness, latency, outcomes, and fairness after deployment.
  • Provide human oversight and recourse for consequential decisions.

Chapter Summary

Classification assigns observations to known categories using labeled data. A sound workflow defines the decision and prediction horizon, prevents leakage, separates training from validation and testing, and evaluates both discrimination and calibration. Decision trees partition data through impurity reduction; rule-based models express explicit IF–THEN logic; Naive Bayes applies Bayes’ theorem with a conditional-independence assumption; logistic regression models log odds and supports regularization; k-NN classifies by local similarity; and ensembles combine models to improve robustness or accuracy.

Overfitting is controlled through pruning, regularization, cross-validation, appropriate feature design, and careful model complexity. Class imbalance requires metrics and thresholds that reflect the actual decision rather than relying on accuracy. Interpretability includes transparent model structure, faithful explanations, documentation, fairness analysis, privacy protection, and human governance. In professional practice, model quality includes technical performance, reliability, maintainability, social impact, and suitability for the decision context.

Key Terms

Classification: Supervised assignment of observations to predefined classes.

Predictor: An input variable used to make a prediction.

Target or class label: The outcome a classifier is trained to predict.

Confusion matrix: A table of true and false positive and negative predictions.

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

Recall: The proportion of actual positives correctly identified.

Specificity: The proportion of actual negatives correctly identified.

Calibration: Agreement between predicted probabilities and observed frequencies.

Decision tree: A recursive sequence of feature-based tests leading to predictions.

Entropy: An impurity measure based on class uncertainty.

Information gain: Reduction in weighted entropy produced by a split.

Rule-based classifier: A classifier expressed through ordered or competing IF–THEN rules.

Naive Bayes: A probabilistic classifier using Bayes’ theorem and conditional independence.

Logistic regression: A model for the probability of a binary outcome through log odds.

Regularization: A penalty or constraint used to limit model complexity.

Nearest neighbor: A method that predicts from the classes of nearby training examples.

Ensemble: A combination of multiple predictive models.

Overfitting: Learning noise or idiosyncrasies that do not generalize.

Data leakage: Use of information unavailable at prediction time or improperly shared across evaluation splits.

Class imbalance: Unequal representation of outcome classes.

Review Questions

Short Answer Questions

1. Distinguish classification from regression and clustering.

2. Define precision, recall, and specificity.

3. Why is scaling important for k-nearest-neighbor classification?

4. State the conditional-independence assumption of Naive Bayes.

5. What is data leakage, and why does it produce optimistic evaluation?

Long Answer Questions

1. Explain the construction, splitting criteria, pruning, advantages, and limitations of decision trees.

2. Compare logistic regression, Naive Bayes, and random forests in terms of assumptions, interpretability, and practical use.

3. Explain overfitting and describe at least five methods for improving generalization.

4. Discuss how class imbalance affects evaluation and how threshold, sampling, and cost-sensitive methods address it.

5. Explain why interpretability, fairness, privacy, and monitoring are essential parts of a deployed classification system.

Analytical / Application Questions

1. A fraud dataset contains 2,000 transactions, of which 40 are fraudulent. A model identifies 30 fraudulent transactions, misses 10, and incorrectly flags 96 legitimate transactions. Calculate precision, recall, specificity, and accuracy. Which metric would you emphasize and why?

2. Design a validation strategy for a classifier predicting hospital readmission using monthly records collected over three years. Explain how you would prevent temporal leakage and assess subgroup performance.

3. A bank can contact only 5% of customers each week. Explain how you would use calibrated probabilities, validation data, expected costs, and fairness monitoring to select and govern the operational threshold.

Multiple Choice Questions with Answers

Question 1

Which measure is the proportion of predicted positive cases that are truly positive?

A. Recall

B. Precision

C. Specificity

D. Accuracy

Correct Answer: B. Precision

Question 2

What does information gain measure when selecting a decision-tree split?

A. Reduction in weighted impurity

B. Number of features in the dataset

C. Increase in training-set size

D. Distance between neighboring observations

Correct Answer: A. Reduction in weighted impurity

Question 3

Which assumption is central to the basic Naive Bayes classifier?

A. All classes have equal prior probability

B. Predictors are conditionally independent given the class

C. The target is continuous

D. Features must have zero variance

Correct Answer: B. Predictors are conditionally independent given the class

Question 4

In binary logistic regression, a coefficient describes a change in which quantity for a one-unit predictor increase, holding other variables constant?

A. Raw class frequency

B. Log odds of the positive class

C. Euclidean distance

D. Tree depth

Correct Answer: B. Log odds of the positive class

Question 5

Why can accuracy be misleading for a highly imbalanced classification problem?

A. Accuracy cannot be calculated from a confusion matrix

B. The majority-class prediction may achieve high accuracy while missing the minority class

C. Accuracy always equals recall

D. Accuracy applies only to regression

Correct Answer: B. The majority-class prediction may achieve high accuracy while missing the minority class

Question 6

Which practice helps prevent preprocessing leakage during cross-validation?

A. Fit imputation and scaling separately within each training fold

B. Use the final test set to select features

C. Oversample before splitting all data

D. Fit preprocessing on the complete dataset before validation

Correct Answer: A. Fit imputation and scaling separately within each training fold

Question 7

What is a principal characteristic of bagging?

A. Sequentially correcting previous errors only

B. Combining models trained on bootstrap samples

C. Using no training data

D. Forcing every model to use one feature

Correct Answer: B. Combining models trained on bootstrap samples

Question 8

If false negatives are much more costly than false positives, which response is generally appropriate?

A. Choose a threshold without considering costs

B. Consider a lower decision threshold, subject to validation and capacity

C. Evaluate only accuracy

D. Remove all minority examples

Correct Answer: B. Consider a lower decision threshold, subject to validation and capacity

Question 9

What is a common effect of increasing k in k-nearest-neighbor classification?

A. A smoother, less flexible decision boundary

B. Guaranteed zero test error

C. Removal of the need for feature scaling

D. Automatic conversion into logistic regression

Correct Answer: A. A smoother, less flexible decision boundary

Question 10

Which statement about model interpretability is most accurate?

A. Feature importance is always causal evidence

B. A complex model is automatically fair if accurate

C. Interpretability includes faithful explanations and documentation of limitations

D. Removing sensitive attributes guarantees fairness

Correct Answer: C. Interpretability includes faithful explanations and documentation of limitations

Data Mining and Data Warehousing
Chapter 8 of 15