Foundations — Regression vs Classification, Loss Functions and Evaluation
The supervised and unsupervised learning settings, regression vs classification, the training/validation/test workflow, empirical risk minimisation and common loss functions, and how models are evaluated — MSE, MAE, R², the confusion matrix, accuracy, precision, recall, F1, specificity, ROC curves and AUC — including the pitfalls of imbalanced data.
The learning problem
Supervised learning: given labelled examples , learn a function with for new inputs.
| Task | Target | Examples | Typical models |
|---|---|---|---|
| Regression | continuous number | price, temperature, demand | linear/ridge regression, k-NN regression, trees, neural networks |
| Classification | discrete class | spam/ham, digit 0–9, disease yes/no | logistic regression, k-NN, naive Bayes, LDA, SVM, trees, neural networks |
Unsupervised learning: only inputs ; discover structure — clustering (k-means, hierarchical), dimensionality reduction (PCA), density estimation, anomaly detection.
Other settings: semi-supervised (few labels), self-supervised, reinforcement learning (rewards from actions).
Models, parameters and hyperparameters
- Parameters are learned from data (regression weights, network weights).
- Hyperparameters are set before training (k in k-NN, in ridge, tree depth, learning rate) and chosen by validation — see cross-validation.
- Parametric models have a fixed number of parameters (linear regression); non-parametric ones grow with the data (k-NN, decision trees).
- Discriminative models learn or a decision boundary directly (logistic regression, SVM); generative models learn and and use Bayes' theorem (naive Bayes, LDA).
Training, validation and test
Empirical risk minimisation: choose parameters minimising the average training loss , often plus a regularisation penalty. The real goal is low generalisation error on unseen data; a model that fits the training data too closely overfits.
Loss functions
| Loss | Formula | Used by |
|---|---|---|
| Squared (L2) | linear and ridge regression | |
| Absolute (L1) | robust regression (median-like) | |
| 0–1 | the error rate itself (not optimised directly) | |
| Log loss (cross-entropy) | logistic regression, neural networks | |
| Hinge | , | SVM |
Regression metrics
is a perfect fit; means no better than predicting ; on test data it can be negative. Adding features never lowers training ; adjusted penalises extra features.
Classification metrics
Confusion matrix (binary):
| predicted + | predicted − | |
|---|---|---|
| actual + | TP | FN |
| actual − | FP | TN |
| Metric | Formula | Question it answers |
|---|---|---|
| Accuracy | how often correct overall? | |
| Precision | when it says "positive", how often right? | |
| Recall / sensitivity / TPR | how many positives does it find? | |
| Specificity / TNR | how many negatives does it clear? | |
| False-positive rate | ||
| F1 score | harmonic mean of precision and recall |
ROC curve: plot TPR against FPR as the threshold varies; AUC = probability a random positive is scored above a random negative (0.5 = chance, 1 = perfect). It is threshold-independent and insensitive to class balance; on heavily imbalanced data the precision–recall curve is more informative.
Multi-class: compute per-class precision/recall and average them — macro (unweighted mean over classes) or micro (pool all TP/FP/FN; equals accuracy for single-label problems).
Quick revision
Practice questions
GATE-style questions: 3 one-mark and 7 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.
Predicting the selling price of a house from its area, location and age is
A classifier on a test set has TP = 40, FP = 10, FN = 20 and TN = 30. Its precision is ______.
For the same classifier (TP = 40, FP = 10, FN = 20, TN = 30), the recall is ______ (round to two decimals).
For the same classifier (TP = 40, FP = 10, FN = 20, TN = 30), the F1 score is ______ (round to two decimals).
For the same classifier (TP = 40, FP = 10, FN = 20, TN = 30), the accuracy is ______.
In a fraud-detection data set, 99% of transactions are legitimate. A model that labels every transaction legitimate has
Which of the following are typically unsupervised learning tasks?
One or more options are correct.
A regression model predicts for three points whose true values are . The mean squared error is ______ (round to two decimals).
The area under the ROC curve (AUC) of a classifier that assigns scores completely at random is about
A regression model has residual sum of squares 20 on a test set whose total sum of squares about the mean is 100. Its coefficient of determination is ______.