∑GATE DA Atlas

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.

Section 610 practice questions

The learning problem

Supervised learning: given labelled examples {(xi,yi)}i=1n\{(\mathbf x_i, y_i)\}_{i=1}^n, learn a function ff with f(x)≈yf(\mathbf x) \approx y for new inputs.

TaskTarget yyExamplesTypical models
Regressioncontinuous numberprice, temperature, demandlinear/ridge regression, k-NN regression, trees, neural networks
Classificationdiscrete classspam/ham, digit 0–9, disease yes/nologistic regression, k-NN, naive Bayes, LDA, SVM, trees, neural networks

Unsupervised learning: only inputs {xi}\{\mathbf x_i\}; 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, λ\lambda 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 P(y∣x)P(y \mid \mathbf x) or a decision boundary directly (logistic regression, SVM); generative models learn P(x∣y)P(\mathbf x \mid y) and P(y)P(y) and use Bayes' theorem (naive Bayes, LDA).

Training, validation and test

training (fit parameters) 60–80% validation test tune hyperparameters,select models touch once:final estimate
Never tune on the test set — its error would no longer be an unbiased estimate.

Empirical risk minimisation: choose parameters minimising the average training loss 1n∑iL(yi,f(xi))\frac1n\sum_i L(y_i, f(\mathbf x_i)), 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

LossFormulaUsed by
Squared (L2)(y−y^)2(y - \hat y)^2linear and ridge regression
Absolute (L1)∣y−y^∣\lvert y - \hat y\rvertrobust regression (median-like)
0–11[y≠y^]\mathbb 1[y \ne \hat y]the error rate itself (not optimised directly)
Log loss (cross-entropy)−[ylog⁡p+(1−y)log⁡(1−p)]-[y\log p + (1-y)\log(1-p)]logistic regression, neural networks
Hingemax⁡(0,1−y f(x))\max(0, 1 - y\,f(\mathbf x)), y∈{±1}y \in \{\pm1\}SVM

Regression metrics

MSE=1n∑(yi−y^i)2,RMSE=MSE,MAE=1n∑∣yi−y^i∣,\text{MSE} = \frac1n\sum(y_i - \hat y_i)^2, \quad \text{RMSE} = \sqrt{\text{MSE}}, \quad \text{MAE} = \frac1n\sum\lvert y_i - \hat y_i\rvert, R2=1−SSresSStot=1−∑(yi−y^i)2∑(yi−yˉ)2.R^2 = 1 - \frac{SS_{res}}{SS_{tot}} = 1 - \frac{\sum(y_i - \hat y_i)^2}{\sum(y_i - \bar y)^2}.

R2=1R^2 = 1 is a perfect fit; R2=0R^2 = 0 means no better than predicting yˉ\bar y; on test data it can be negative. Adding features never lowers training R2R^2; adjusted R2=1−(1−R2)n−1n−p−1R^2 = 1 - (1 - R^2)\frac{n-1}{n-p-1} penalises extra features.

Classification metrics

Confusion matrix (binary):

predicted +predicted −
actual +TPFN
actual −FPTN
MetricFormulaQuestion it answers
AccuracyTP+TNN\frac{TP + TN}{N}how often correct overall?
PrecisionTPTP+FP\frac{TP}{TP + FP}when it says "positive", how often right?
Recall / sensitivity / TPRTPTP+FN\frac{TP}{TP + FN}how many positives does it find?
Specificity / TNRTNTN+FP\frac{TN}{TN + FP}how many negatives does it clear?
False-positive rateFPFP+TN=1−specificity\frac{FP}{FP + TN} = 1 - \text{specificity}
F1 score2PRP+R=2TP2TP+FP+FN\frac{2PR}{P + R} = \frac{2TP}{2TP + FP + FN}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.

Q1MCQ1 mark

Predicting the selling price of a house from its area, location and age is

Q2NAT2 marks

A classifier on a test set has TP = 40, FP = 10, FN = 20 and TN = 30. Its precision is ______.

Q3NAT2 marks

For the same classifier (TP = 40, FP = 10, FN = 20, TN = 30), the recall is ______ (round to two decimals).

Q4NAT2 marks

For the same classifier (TP = 40, FP = 10, FN = 20, TN = 30), the F1 score is ______ (round to two decimals).

Q5NAT1 mark

For the same classifier (TP = 40, FP = 10, FN = 20, TN = 30), the accuracy is ______.

Q6MCQ2 marks

In a fraud-detection data set, 99% of transactions are legitimate. A model that labels every transaction legitimate has

Q7MSQ2 marks

Which of the following are typically unsupervised learning tasks?

One or more options are correct.

Q8NAT2 marks

A regression model predicts 3,5,23, 5, 2 for three points whose true values are 2,5,42, 5, 4. The mean squared error is ______ (round to two decimals).

Q9MCQ1 mark

The area under the ROC curve (AUC) of a classifier that assigns scores completely at random is about

Q10NAT2 marks

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 R2R^2 is ______.