Supervised learning
Learning from labeled examples: inputs paired with the answers you want.
What you'll learn
- Describe supervised learning as learning a mapping from inputs to known labels.
- Split a dataset into train/validation/test and explain why each split exists.
- Train a simple classifier in code and interpret basic accuracy.
In plain English
Supervised learning is learning with answer keys. You show the model many examples where both the input and the correct output are known, and it adjusts itself to predict outputs on new inputs.
Examples include spam detection (email → spam or not), house price prediction (features → price), and image tagging (photo → cat or dog).
The model never sees test labels during training. That hidden set tells you whether it learned general patterns or just memorized.
How training works
Pick a model family (linear, tree, neural net). Feed a batch of inputs, compare predictions to labels, compute a loss (error score), and update parameters to reduce loss.
Repeat for many epochs over the training set. Tune hyperparameters on a validation set. Report final metrics on a test set touched only once.
Classification predicts discrete categories; regression predicts continuous numbers. The same supervised loop applies to both.
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
# Toy emails: [link_count, has_free_word]
X = [[0, 0], [1, 0], [5, 1], [3, 1], [0, 0], [4, 1]]
y = ["ham", "ham", "spam", "spam", "ham", "spam"]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=42
)
model = LogisticRegression()
model.fit(X_train, y_train)
preds = model.predict(X_test)
print("accuracy:", accuracy_score(y_test, preds))Going deeper
Class imbalance (rare fraud, rare disease) breaks naive accuracy. Use precision, recall, ROC curves, or cost-sensitive metrics aligned with business harm.
Label noise and ambiguous classes cap achievable performance. Sometimes improving annotation guidelines beats swapping model architectures.
Supervised fine-tuning of large pretrained models is how many LLM products specialize—same principle, bigger networks and different loss on tokens.
Common misconceptions
- High training accuracy means the model is ready.
- Perfect training scores can mean overfitting. You need held-out validation and tests on fresh data.
- Supervised learning needs no human work.
- Labels are human effort or expensive heuristics. Quality and coverage of labels define the ceiling.
- One algorithm wins for every problem.
- Different data shapes favor different models. Start simple, measure, then increase complexity.
Key facts
- Supervised learning uses labeled input–output pairs to train predictors.
- Models must be evaluated on data not used during training.
- Classification and regression are the two main supervised task types.
- Loss functions quantify prediction error; optimization reduces that error.
- Fine-tuning large models is supervised learning on specialized labels or targets.
Sources used
These free resources informed this page. ANN writes original explainers; we do not copy course text behind paywalls.
Also explore AI companies, Live Feed, and Weekly Brief.
