Classifiers, Regressors & Clusters: The 3 Shapes of ML

Almost every ML problem is one of three shapes. Learn to recognise each — with a runnable example for all three.

Machine learning looks sprawling until you notice almost everything is one of three problems: predict a category (classification), predict a number (regression), or find structure (clustering). Master these and you can frame most real problems.

1. Classification — which category?

python
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split

X, y = load_iris(return_X_y=True)
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.2, random_state=0)

clf = RandomForestClassifier(n_estimators=100)
clf.fit(Xtr, ytr)
print("accuracy:", clf.score(Xte, yte))

Use it for spam detection, churn prediction, image labels, credit risk — anything with a finite set of labels.

2. Regression — how much?

python
from sklearn.datasets import load_diabetes
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error

X, y = load_diabetes(return_X_y=True)
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.2, random_state=0)

reg = LinearRegression().fit(Xtr, ytr)
pred = reg.predict(Xte)
print("MAE:", mean_absolute_error(yte, pred))

Use it for pricing, forecasting, sensor readings, energy use — any continuous quantity.

3. Clustering — what groups exist?

python
from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans

X, _ = make_blobs(n_samples=300, centers=3, random_state=0)
km = KMeans(n_clusters=3, n_init=10).fit(X)
print("cluster labels:", km.labels_[:10])
print("inertia (lower is tighter):", km.inertia_)

Use it for customer segmentation, anomaly detection, topic grouping — finding structure when you have no labels.

How to pick the right one

python
# a quick checklist to ask yourself:
# 1. Do I have labels for past examples?
#      yes -> supervised (classification or regression)
#      no  -> unsupervised (clustering)
# 2. Is the thing I predict a category or a number?
#      category -> classification
#      number   -> regression
Always split your data, and hold out a test set the model never saw. A model that scores 99% on its own training data is usually just memorising.

Three shapes, one library, a lifetime of problems. The hard part is never the algorithm — it's framing the question and cleaning the data.

Your move

Want us to build this for you?

We turn tutorials like these into production systems every day. Tell us what you need.

Start a project →