← Back to Predictive Analytics

Framing the Problem

Chapter 1 — Regression, Classification, or Clustering?

Before any algorithm, the most consequential choice is what kind of question you're asking. Get the framing wrong and no amount of tuning will save you. Three framings cover most cases.

The Three Framings

Clustering in Action — Segmenting the Customer Base

Clustering is the framing that surprises people, because there is no target column. K-Means groups customers by similarity across chosen features — here, lifetime sales, order count, and average discount — and the groups emerge from the data. The scatter below colours each customer by its assigned cluster: a high-value frequent group separates cleanly from occasional, low-value buyers.

Python · scikit-learn

from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans

feats = cust[["total_sales", "orders", "avg_discount"]]
X = StandardScaler().fit_transform(feats)          # scale first — K-Means uses distance
cust["cluster"] = KMeans(n_clusters=3, n_init=10, random_state=42).fit_predict(X)
Scatter of customers by order count and lifetime sales, coloured into three K-Means clusters that separate high-value frequent buyers from occasional ones

K-Means finds three natural customer segments with no labels — separating frequent high-value buyers from occasional, low-value ones.

Picking the Framing

Ask what the answer looks like. A dollar amount → regression. A yes/no or category → classification. "Are there natural groups here?" with no predefined answer → clustering. The same dataset can support all three: predict a customer's spend (regression), flag who will churn (classification), or discover segments (clustering). Each of the next chapters takes one of these and runs it end to end.

Next: The Train/Test Split & Overfitting →

← Back to Predictive Analytics