Overview of Regression and Classification Concepts — Beginner-Friendly Notes
1. Both Are Supervised — The Split
- Regression: predict continuous number — e.g., price, temperature, GPA.
- Classification: predict discrete label — e.g., spam/ham, disease yes/no, cat/dog.
Same pipeline, different and loss function.
2. Linear Regression — The Simplest Regression
Model: (for vector , ).
Loss: Mean Squared Error — minimise it → find best (closed-form or gradient descent).
Intuition: fits best line/plane through points. Assumption: linear relation; fails on curves (need polynomial/features or other models).
Output: continuous; evaluation via , , .
3. k-NN (k-Nearest Neighbours) — Simple Classification & Regression
Idea: "Tell me who your neighbours are, I'll tell you who you are."
- Store all training points.
- For new , find k closest training points (distance = Euclidean usually).
- Classification: vote among neighbours' labels (majority).
- Regression: average neighbours' .
Pros: no training, intuitive, works for both tasks.
Cons: slow at prediction (scans all data), sensitive to scaling and , curses with high dimensions.
Pick : odd to avoid ties; small → noisy, flexible; large → smooth, biased. Use validation.
4. Decision Trees — Tree of Rules
Idea: recursively split data on feature thresholds to make leaves as pure as possible.
Is income > 50k?
No → Is student? → leaf: No / Yes
Yes → leaf: Yes
Splitting criterion: information gain (entropy drop) or Gini impurity — pick split that most separates classes.
For regression: leaf predicts mean of its points; split minimises variance (MSE).
Pros: interpretable, handles mixed types, non-linear.
Cons: overfits easily → needs pruning or ensemble.
5. Small Comparison Table (exam favourite)
| k-NN | Decision Tree | Linear Regression | |
|---|---|---|---|
| Type | non-parametric, instance-based | non-parametric, rule-based | parametric |
| Training | none (lazy) | builds tree | fits weights |
| Handles non-linear | yes (with enough data) | yes | no (linear only) |
| Interpretability | low | high | medium (weights) |
| Use when | small data, baseline | explainable rules needed | linear trend suspected |
6. Choosing (beginner heuristic)
- Continuous + linear trend → linear regression.
- Need simple explainable classifier → decision tree.
- Need simple strong baseline + small data → k-NN.
7. One-Line Summary
Regression predicts continuous (e.g., linear regression with MSE) while classification predicts discrete labels via instance voting (k-NN) or recursive splitting (decision trees), each trading simplicity, interpretability and capacity for non-linear patterns.
8. Quick Self-Check
- Predict price from area — regression or classification?
- Why does k-NN struggle if features are on very different scales?