Machine Learning for Business

Chapter 9
Unsupervised Learning and Pattern Discovery

Bachelors Program in Business Analytics
Machine Learning for Business   •   Bachelor

Unsupervised Learning and Pattern Discovery

Introduction

Most business data are generated without a reliable target variable. A retailer may know what customers purchased but not which customers belong to a strategically meaningful segment. A bank may observe transaction behavior without labels identifying every fraudulent transaction. A manufacturer may record thousands of sensor readings without knowing in advance which combinations signal an emerging failure. Unsupervised learning addresses these situations by discovering structure, similarity, co-occurrence, and unusual behavior in data without a predefined response variable.

The purpose of unsupervised learning is not simply to produce mathematically neat groups or patterns. A pattern is valuable when it is sufficiently stable, statistically credible, interpretable, and useful for managerial action. This chapter examines four major families of unsupervised methods:

  • clustering for segmentation and organization;
  • dimensionality reduction for representation, visualization, and noise management;
  • association analysis for market-basket and co-occurrence discovery; and
  • anomaly detection for fraud, operational exceptions, and risk monitoring.

The chapter also considers validation, ethical risks, implementation choices, and the translation of discovered patterns into business decisions.

Learning Objectives

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

  1. Explain the role and assumptions of unsupervised learning in business analytics.
  2. Select and apply appropriate clustering methods for segmentation.
  3. Interpret dimensionality-reduction techniques without confusing visualization with proof of structure.
  4. Calculate and evaluate support, confidence, and lift for association rules.
  5. Distinguish anomalies from ordinary variation and select suitable detection methods.
  6. Assess pattern stability, usefulness, fairness, and actionability.
  7. Translate unsupervised-learning results into responsible managerial interventions.

1. The Nature of Unsupervised Learning

In supervised learning, a model estimates a target variable from predictors. In unsupervised learning, the data consist primarily of an observation matrix X ∈ Rn×p, where n is the number of observations and p is the number of measured features. There is no required target y supplied during model fitting.

Unsupervised learning can answer questions such as:

  • Which customers have similar purchasing behavior?
  • Which products are frequently purchased together?
  • Can many correlated performance indicators be represented by fewer dimensions?
  • Which transactions, machines, or employees behave unusually?

The absence of labels does not mean the analysis is assumption-free. Results depend on feature definitions, scaling, distance measures, sampling, missing-value treatment, algorithm settings, and the business purpose. A clustering algorithm will always produce some output—even when no commercially meaningful segments exist.

Important terminology

A feature is a measured variable used to describe an observation. An observation is a unit such as a customer, transaction, product, machine, or store. A cluster is a group formed because its members are more similar to one another than to members of other groups according to a chosen criterion. A prototype is a representative point, such as a cluster centroid or medoid. A pattern is a repeated or systematic relationship in data. An anomaly is an observation or event that deviates materially from an expected pattern.

2. Preparing Data for Pattern Discovery

Data preparation often determines the result more strongly than the algorithm.

2.1 Selecting the analytical unit

The unit of analysis must match the decision. Customer segmentation may use one row per customer over a six-month period. Fraud detection may use one row per transaction. Mixing transaction-level and customer-level observations can create misleading similarities.

2.2 Scaling numerical variables

Distance-based methods are sensitive to measurement scales. Suppose annual income is measured in dollars and purchase frequency is measured as a count. Income may dominate Euclidean distance unless variables are standardized. A common z-score transformation is:

zij = (xij - μj) / σj

where xij is the value of feature j for observation i, μj is the sample mean of feature j, and σj is its sample standard deviation. This transformation is appropriate when relative deviations from the mean are meaningful and extreme outliers do not make the mean and standard deviation unrepresentative. Robust alternatives use the median and interquartile range.

Categorical variables require appropriate encodings and distance measures. One-hot encoding can make a category contribute disproportionately when many levels exist. Mixed-data methods, such as Gower distance, may be more appropriate when numerical, ordinal, and categorical features are combined.

2.3 Missing values and outliers

Imputation should reflect the data-generating process. Median imputation may be reasonable for skewed numerical variables, but it reduces variation. A missingness indicator can preserve information when missingness itself is meaningful. Outliers should not be removed automatically: in fraud analytics, the unusual cases may be the objective of the analysis.

2.4 Leakage and time

Features must be available at the time of the intended decision. Using a post-event variable in a segmentation or anomaly system creates operational leakage. Time-dependent data also require chronological validation; randomly mixing future and past observations can make patterns appear more stable than they are.

3. Clustering for Segmentation

Clustering seeks a partition or hierarchy of observations based on similarity. No single clustering method is universally best. The appropriate method depends on whether groups are expected to be spherical, nested, overlapping, irregular, or contaminated by noise.

3.1 Distance and similarity

For two observations represented by vectors x and y, Euclidean distance is:

d(x,y) = √(∑j=1p(xj - yj)2)

It is suitable for continuous, appropriately scaled variables when straight-line separation is meaningful. Manhattan distance is:

d1(x,y) = ∑j=1p|xj - yj|

It can be less sensitive to a single large coordinate difference. The choice of distance should be justified by the data type and managerial interpretation, not selected mechanically.

3.2 K-means clustering

K-means partitions observations into k clusters by minimizing within-cluster squared Euclidean distance. Its objective is:

J = ∑r=1k ∑xi ∈ Cr ||xi - μr||2

Here, Cr is cluster r, μr is its centroid, and ||xi - μr||2 is squared Euclidean distance. The algorithm alternates between assigning each observation to its nearest centroid and recomputing each centroid as the mean of assigned observations until assignments or the objective stabilize.

K-means is efficient and easy to explain, but it assumes that the mean is meaningful, clusters are reasonably compact, and the selected value of k is appropriate. It is sensitive to initialization, scaling, outliers, and elongated or non-spherical clusters. Multiple random starts should be used.

3.3 Hierarchical clustering

Agglomerative hierarchical clustering begins with each observation as its own cluster and repeatedly merges clusters. The resulting dendrogram allows analysts to examine solutions at different levels. Linkage rules define the distance between clusters:

  • single linkage uses the closest pair and can create chaining;
  • complete linkage uses the farthest pair and tends to create compact groups;
  • average linkage uses average pairwise distance; and
  • Ward’s method merges groups with the smallest increase in within-cluster variance, generally for numerical data.

Hierarchical methods are useful when nested structures matter, but they can be computationally expensive and early merges cannot be undone.

3.4 Density-based clustering

Density-based methods, such as DBSCAN, identify dense regions separated by lower-density areas and can label isolated observations as noise. They can detect irregular shapes and do not require a preselected number of clusters. However, results depend on neighborhood parameters and may be difficult when clusters have very different densities.

3.5 Choosing the number of clusters

The number of clusters should combine statistical evidence and business reasoning. The within-cluster sum of squares often decreases as k increases, so an “elbow” is only a heuristic. The silhouette coefficient for observation i is:

si = (bi - ai) / max(ai,bi)

where ai is the average distance from observation i to observations in its own cluster, and bi is the smallest average distance from i to observations in another cluster. Values approach 1 when an observation is well separated, are near 0 at boundaries, and may be negative when assignment is questionable. The overall silhouette score is the average of si. It is a diagnostic, not proof that the resulting segments are useful.

Worked example: interpreting a small segmentation

Suppose standardized customer data produce three clusters. Their profiles are:

ClusterRelative spendPurchase frequencyDiscount useInterpretation
AHighHighLowPremium loyal customers
BMediumHighHighPromotion-responsive regulars
CLowLowHighInfrequent value seekers

The labels are interpretations, not outputs of the algorithm. A responsible analyst should examine cluster size, profitability, geographic distribution, stability across samples, and whether a different action can actually be taken for each group. If clusters A and B receive the same marketing treatment, the distinction may have little value even if their numerical profiles differ.

4. Dimensionality Reduction

Business datasets may contain hundreds of correlated variables. Dimensionality reduction creates a lower-dimensional representation that preserves selected properties of the original data. It can support visualization, noise reduction, faster modeling, and feature interpretation.

4.1 Principal component analysis

Principal component analysis (PCA) transforms centered—and often standardized—variables into orthogonal components. The first component is the direction that maximizes variance, the second maximizes remaining variance subject to being orthogonal to the first, and so forth.

If the covariance matrix is S, PCA finds eigenvectors vl and eigenvalues λl satisfying:

S vl = λl vl

The component score for observation xi is commonly:

til = xiT vl

where xi is centered before calculation and vl is a unit-length eigenvector. The proportion of variance explained by component l is:

EVl = λl / ∑m=1p λm

PCA is appropriate for linear structure and numerical variables. It is not automatically meaningful for categorical data, nonlinear manifolds, or variables whose business meaning is lost through combination. Component loadings should be inspected; a component explaining much variance may not be actionable.

4.2 Nonlinear visualization

Methods such as t-distributed stochastic neighbor embedding (t-SNE) and Uniform Manifold Approximation and Projection (UMAP) can reveal local neighborhoods in two or three dimensions. Their maps are useful exploratory tools, but apparent islands can depend on hyperparameters, random initialization, and preprocessing. Distances between widely separated groups should not automatically be interpreted as quantitative business differences. A two-dimensional visualization is not evidence by itself that true clusters exist.

4.3 Reduction and clustering

Reducing dimensions before clustering may remove noise and improve computational performance, but it can also remove low-variance features that are important for a business decision. Analysts should compare clustering on the original prepared features with clustering on reduced representations and assess whether the resulting segments are more stable and actionable.

5. Association Analysis and Market-Basket Discovery

Association analysis identifies items or events that occur together. A transaction database can be represented by item sets. Let A and B be item sets, and let N be the number of transactions.

5.1 Support

Support measures how often an item set appears:

support(A) = count(A) / N

It is a proportion between 0 and 1. High support indicates prevalence, but rare products may still be strategically important.

5.2 Confidence

For the rule A → B, confidence is:

confidence(A → B) = support(A ∪ B) / support(A)

It estimates the proportion of transactions containing A that also contain B. Confidence is directional and can be misleading when B is already very common.

5.3 Lift

Lift compares the observed co-occurrence with what would be expected under independence:

lift(A → B) = support(A ∪ B) / [support(A) × support(B)]

Lift greater than 1 indicates positive association, lift equal to 1 is consistent with independence, and lift below 1 indicates negative association under this interpretation. The independence comparison is descriptive; it does not establish causality.

Worked example: market basket rules

In 1,000 transactions, 200 contain coffee, 150 contain pastries, and 90 contain both.

  • Support of coffee: 200/1000 = 0.20, or 20%.
  • Support of coffee and pastries: 90/1000 = 0.09, or 9%.
  • Confidence of coffee → pastries: 0.09/0.20 = 0.45, or 45%.
  • Lift: 0.09/(0.20×0.15) = 3.0.

Thus, 45% of coffee transactions also contain pastries, and the pair occurs three times as often as would be expected if purchases were independent. The result may justify testing a bundle or product placement. It does not prove that selling coffee causes pastry purchases. Time of day, store location, promotions, and customer purpose may explain the association.

5.4 Mining and evaluation

Apriori uses the downward-closure principle: if an item set is infrequent, every larger item set containing it must also be infrequent. This reduces the search space when a minimum support threshold is applied. FP-Growth is another efficient approach that compresses transactions into a prefix structure.

Rules should be screened for minimum support, confidence, lift, statistical reliability, redundancy, and business plausibility. Thousands of candidate rules create a multiple-comparisons problem: some apparently strong associations will occur by chance. Validation on a later period is essential.

6. Anomaly Detection

Anomaly detection identifies observations that differ from an expected baseline. The baseline may be global, local, temporal, or conditional. An unusual transaction is not necessarily fraudulent; it may represent a legitimate customer, a new product, or a system change.

6.1 Types of anomalies

  • Point anomaly: one observation is unusual relative to the overall population.
  • Contextual anomaly: an observation is unusual in a particular context, such as a high transaction at 3 a.m.
  • Collective anomaly: a sequence or group is unusual even if individual observations are not.

6.2 Common methods

A univariate z-score can flag unusually high or low values:

zi = (xi - μ) / σ

A threshold such as an absolute z-score above 3 is only a heuristic and assumes that the mean and standard deviation provide a suitable baseline. In skewed or heavy-tailed data, robust quantiles are preferable.

Distance-based methods identify observations far from their neighbors. Local Outlier Factor compares local density with the density around neighboring observations. Isolation Forest separates observations through randomized partitioning; unusual observations tend to require fewer partitions to isolate. Autoencoders learn to reconstruct typical patterns, with high reconstruction error used as an anomaly signal. Such models require careful training data and monitoring for concept drift.

6.3 Thresholds and operational decisions

Anomaly scores must be converted into actions. A bank may rank alerts for review rather than automatically reject all high-scoring transactions. Threshold selection should consider investigation capacity, false-positive costs, false-negative costs, customer friction, and regulatory obligations. Precision, recall, and review yield should be monitored when labels become available:

precision = TP / (TP + FP)
recall = TP / (TP + FN)

Here, TP is true positives, FP false positives, and FN false negatives. Precision answers how many flagged cases are genuinely positive; recall answers how many actual positives were identified. These metrics require reliable labels and should be interpreted with the base rate of the event.

7. Evaluating Patterns: Stability, Usefulness, and Actionability

A pattern-discovery project should be evaluated on several dimensions.

Statistical and structural validity

The method must be appropriate for the data, and results should not be artifacts of scaling, initialization, missing-value treatment, or one unusual sample. Refit models on bootstrap samples, time windows, or organizational units. For clusters, compare assignments using measures such as adjusted Rand index when a reference partition is available. For association rules, validate support and lift in a holdout period. For anomalies, investigate whether flagged cases remain unusual after controlling for seasonality and exposure.

Stability

A stable pattern produces broadly similar results under reasonable perturbations. Stability does not guarantee usefulness, but instability warns against operationalizing the result. Analysts should document random seeds, preprocessing decisions, feature versions, parameter settings, and data periods.

Usefulness and actionability

A useful pattern changes a decision, reduces cost, improves service, increases revenue, or reduces risk. Actionability requires an available intervention, an owner, a time frame, and a measurable outcome. Segments with attractive names but no differentiated treatment are descriptive rather than operational.

Causal caution

Unsupervised methods describe associations and structure. They do not establish that an intervention will cause an outcome. A cluster associated with churn may contain customers who are difficult to retain, but targeting them with a discount may be unprofitable. Controlled experiments, quasi-experimental designs, or careful operational pilots are needed to evaluate interventions.

8. Applied Case: Illustrative Retail Discovery Project

Background

A fictional omnichannel retailer has transaction data, customer-service interactions, product categories, discount use, and delivery records. Management wants to improve retention and identify suspicious orders without treating every unusual order as fraud.

Problem

The retailer has three related problems: customer segments are based on simple demographics; cross-selling decisions rely on intuition; and fraud investigators receive too many low-value alerts.

Analysis and approach

The analytics team creates one customer-level table using six months of behavior: order frequency, average basket value, category diversity, return rate, discount share, and service contacts. Monetary variables are transformed to reduce skew, then standardized. K-means solutions from two through six clusters are compared using silhouette scores, bootstrap stability, profitability, and the feasibility of differentiated campaigns.

The selected four-segment solution identifies premium loyal customers, promotion-responsive regulars, occasional convenience shoppers, and high-return customers. The final label is not treated as a moral judgment; it is a behavioral description and is reviewed for possible socioeconomic or geographic proxy effects.

For market-basket analysis, rules are generated separately by channel and season. A rule that appears strong overall but disappears in the online channel is not used for a universal recommendation. Product managers test a limited bundle against a control group rather than assuming that lift implies incremental sales.

For fraud discovery, the team combines transaction amount, velocity, device changes, delivery distance, and historical account behavior. An Isolation Forest produces a ranking, while business rules identify known high-risk conditions. Investigators review the highest-ranked cases. Confirmed outcomes are fed back into evaluation, and thresholds are adjusted to match available investigation capacity.

Outcome

The segmentation produces differentiated communication plans, but only the premium and promotion-responsive groups receive distinct initial treatments because the other groups do not yet justify separate interventions. Basket rules support a controlled bundle experiment. Fraud alerts decline after removing a seasonal delivery anomaly that had been misclassified as suspicious, while confirmed high-risk cases remain visible.

Learning points

  1. The business unit and time window must be defined before modeling.
  2. A statistically distinct segment may not justify a separate action.
  3. Association is a hypothesis for testing, not evidence of causation.
  4. Anomaly detection requires contextual baselines and human review.
  5. Operational feedback is necessary to evaluate whether discovery improves decisions.

9. Ethical, Governance, and Implementation Considerations

Unsupervised systems can reproduce historical inequities even without using protected attributes. Proxy variables such as location, device type, language, or purchasing patterns may encode sensitive information. Segments can become discriminatory if they determine access to prices, credit, service quality, or investigation intensity.

Organizations should document purpose, data provenance, feature definitions, retention periods, access controls, and model limitations. Individuals should not be denied important services solely because an opaque anomaly score is high. High-impact decisions require meaningful review, an appeal route where appropriate, and audit trails. Privacy principles include data minimization, purpose limitation, security, and proportionality.

Implementation should include a data pipeline, reproducible feature engineering, model versioning, monitoring, alert management, and a retirement process. Drift monitoring is particularly important: customer behavior, fraud tactics, product catalogs, and economic conditions change. A cluster model trained before a major pricing change may no longer represent current behavior.

10. Contemporary Developments and Best Practices

Modern pattern discovery increasingly combines unsupervised representations with supervised outcomes. Representation learning can summarize text, images, transactions, or event sequences before clustering or anomaly detection. Graph methods discover relationships among customers, accounts, products, suppliers, and devices. Streaming systems support near-real-time anomaly scoring, but they require careful handling of delayed labels and changing baselines.

Best practice is to:

  1. start with a clearly defined decision rather than an algorithm;
  2. select an analytical unit and time window that match the decision;
  3. prepare and scale features transparently;
  4. compare more than one plausible method;
  5. assess stability under sampling, time, and parameter changes;
  6. validate patterns on future or holdout data;
  7. distinguish descriptive association from causal evidence;
  8. involve domain experts in interpretation;
  9. quantify operational costs and benefits; and
  10. monitor fairness, drift, performance, and unintended consequences after deployment.

Chapter Summary

Unsupervised learning discovers structure when a target label is unavailable or incomplete. Clustering supports segmentation, but distance measures, scaling, algorithm assumptions, and the number of clusters must be justified. K-means is efficient for compact numerical groups; hierarchical methods reveal nested structure; and density-based methods can identify irregular groups and noise.

Dimensionality reduction, especially PCA, represents correlated variables using fewer dimensions. It can improve visualization and efficiency, but reduced dimensions must be interpreted carefully. Association analysis uses support, confidence, and lift to identify co-occurring items; these measures describe relationships and do not prove causation. Anomaly detection identifies unusual points, contexts, or sequences, and should be connected to calibrated operational decisions rather than automatic punishment.

The quality of pattern discovery depends on more than model fit. Analysts must evaluate stability, validation performance, interpretability, actionability, fairness, privacy, and managerial impact. Responsible projects convert patterns into controlled interventions, measure outcomes, and monitor drift over time.

Key Terms

Unsupervised learning: Learning from data without a predefined target label.

Clustering: Grouping observations according to a similarity criterion.

Centroid: The mean vector representing a cluster in methods such as k-means.

Distance measure: A rule for quantifying dissimilarity between observations.

K-means: A partitioning method that minimizes within-cluster squared distance.

Hierarchical clustering: Clustering that creates a nested sequence of groups.

Density-based clustering: Clustering based on dense regions separated by sparse regions.

Silhouette coefficient: A measure of within-cluster cohesion and between-cluster separation.

Dimensionality reduction: Representing data using fewer variables or dimensions.

PCA: A linear method that creates orthogonal directions ordered by explained variance.

Loading: The contribution of an original variable to a principal component.

Association rule: A directional co-occurrence statement such as A → B.

Support: The proportion of transactions containing an item set.

Confidence: The conditional proportion of A transactions that also contain B.

Lift: Observed co-occurrence divided by co-occurrence expected under independence.

Anomaly: An observation or event that deviates from an expected pattern.

Point anomaly: An individually unusual observation.

Concept drift: Change in the data-generating process over time.

Actionability: The extent to which a pattern supports a feasible decision or intervention.

Review Questions

Short Answer Questions

  1. Why can scaling change the result of a distance-based clustering method?
  2. What does a silhouette coefficient near zero suggest?
  3. Distinguish support from confidence in association analysis.
  4. Why is an unusual transaction not necessarily fraudulent?
  5. What is concept drift, and why does it matter for anomaly detection?

Long Answer Questions

  1. Compare k-means, hierarchical, and density-based clustering, including their assumptions and business applications.
  2. Explain PCA and discuss situations in which dimensionality reduction may harm interpretation.
  3. Explain support, confidence, and lift using a business example, and discuss why association does not establish causation.
  4. Develop a validation framework for a customer-segmentation project.
  5. Discuss the ethical and governance risks of using unsupervised models in pricing, fraud investigation, or service allocation.

Analytical / Application Questions

  1. A retailer obtains a high-lift rule for two products, but the rule occurs in only five transactions. How should the analyst evaluate and communicate this result?
  2. A fraud model flags many transactions from a region immediately after a new delivery service launches. Propose an investigation to determine whether the alerts represent fraud, operational change, or model drift.
  3. A four-cluster solution has a slightly lower silhouette score than a three-cluster solution but supports clearly different profitable interventions. What additional evidence should management require before selecting the four-cluster solution?

Multiple Choice Questions with Answers

Question 1

Which statement best describes unsupervised learning?

A. It estimates a known target using labeled examples.

B. It discovers structure without a predefined target label.

C. It guarantees causal explanations for observed relationships.

D. It requires every observation to have a confirmed class.

Correct Answer: B. It discovers structure without a predefined target label.

Question 2

What is a principal purpose of standardizing numerical features before distance-based clustering?

A. To make all variables categorical

B. To remove every outlier automatically

C. To prevent measurement units from dominating distance

D. To guarantee the optimal number of clusters

Correct Answer: C. To prevent measurement units from dominating distance

Question 3

In k-means clustering, what does the centroid represent?

A. The median distance between all observations

B. The mean vector of observations assigned to a cluster

C. The most anomalous observation in a cluster

D. The number of variables in the dataset

Correct Answer: B. The mean vector of observations assigned to a cluster

Question 4

A silhouette coefficient close to 1 generally indicates that an observation is:

A. Well matched to its cluster and separated from other clusters

B. Equally close to every cluster

C. Definitely an anomaly

D. Assigned to a cluster with no observations

Correct Answer: A. Well matched to its cluster and separated from other clusters

Question 5

In the chapter’s market-basket example, what is the lift of coffee → pastries?

A. 0.45

B. 0.90

C. 2.00

D. 3.00

Correct Answer: D. 3.00

Question 6

A lift value greater than 1 indicates that:

A. The consequent appears in every transaction

B. The observed co-occurrence exceeds the independence expectation

C. The rule proves that A causes B

D. The support of the antecedent is zero

Correct Answer: B. The observed co-occurrence exceeds the independence expectation

Question 7

Which is a contextual anomaly?

A. A transaction that is high relative to all transactions and also high for its time and location

B. A normal daytime transaction during a routine shopping period

C. A transaction that is unusual specifically because it occurs at 3 a.m.

D. A duplicated row created by a database error

Correct Answer: C. A transaction that is unusual specifically because it occurs at 3 a.m.

Question 8

What does precision measure in anomaly classification when labels are available?

A. The proportion of flagged cases that are truly positive

B. The proportion of actual positives that were identified

C. The total number of observations in the dataset

D. The average distance between cluster centroids

Correct Answer: A. The proportion of flagged cases that are truly positive

Question 9

Why should association rules be validated on a later or holdout period?

A. To increase the number of item categories automatically

B. To determine whether observed relationships generalize beyond the discovery sample

C. To ensure that every rule has confidence of exactly 1

D. To convert unsupervised learning into supervised learning

Correct Answer: B. To determine whether observed relationships generalize beyond the discovery sample

Question 10

Which consideration most directly concerns actionability?

A. Whether a pattern has a colorful visualization

B. Whether a feasible intervention, owner, and outcome measure exist

C. Whether the algorithm uses the newest programming language

D. Whether the dataset contains exactly four clusters

Correct Answer: B. Whether a feasible intervention, owner, and outcome measure exist

Machine Learning for Business
Chapter 9 of 15