Machine learning in one page
Supervised, unsupervised and reinforcement learning, what features and labels are, and how to tell whether learning happened at all.
The three families
| Family | You have | You want | Example |
|---|---|---|---|
| Supervised | Inputs + correct answers | Predict answers for new inputs | Spam classification |
| Unsupervised | Inputs only | Structure — groups, outliers, compression | Customer segmentation |
| Reinforcement | An environment and rewards | A policy that maximises reward | Game playing, robot control |
Most business problems are supervised. Decide early whether you are predicting a category (classification) or a number (regression) — that single choice determines your model family, your loss and your metrics.
💡
Reinforcement learning is powerful but data-hungry and hard to make safe. If you can phrase the problem as supervised learning with logged outcomes, do that instead.
Features beat algorithms
import pandas as pd
from sklearn.model_selection import train_test_split
df = pd.read_csv("churn.csv")
X = df.drop(columns=["churned", "customer_id"]) # id is not a feature
y = df["churned"]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42, stratify=y) # stratify keeps class balance- Drop identifiers: an id encodes nothing generalisable and invites leakage.
- Encode categories deliberately: one-hot for few values, target/ordinal encoding only with care.
- Scale for distance- and gradient-based models (logistic regression, SVM, neural nets); tree ensembles do not need it.
- Handle missing values explicitly — mean/median, a sentinel, or a model that supports NaN.
- Derive features the domain suggests: ratios, recency, counts, rolling averages.
⚠️
A model cannot beat a good feature set. If your features barely relate to the label, switching algorithms just cycles through different flavours of guessing.
Start with a baseline you must beat
from sklearn.dummy import DummyClassifier
from sklearn.metrics import accuracy_score
base = DummyClassifier(strategy="most_frequent").fit(X_train, y_train)
accuracy_score(y_test, base.predict(X_test)) # the number to beatThe dummy classifier predicts the most frequent class (or the mean, for regression). Any model that does not clearly beat it is not learning anything useful, no matter how sophisticated it looks.
FAQ
How do I choose an algorithm?
Start with a simple, interpretable model on strong features — logistic regression or a small gradient-boosted tree. Move to more complex models only when the simple one is clearly the bottleneck.
Do I need deep learning?
For tables, almost never. Boosted trees match or beat neural networks on tabular data with far less tuning. Deep learning shines on images, audio, text and sequences.
Related
Evaluation and overfitting The model lifecycle
Last refreshed 2026-09-18.