Skip to content
GATEiit

GATE DA · Machine Learning

Regression and classification problems

The supervised learning framework: inputs, labels, loss and generalisation; how regression (real-valued output) differs from classification (class label); and the error measures GATE asks you to compute.

Before you start

This topic comes before: Bias–variance trade-off, Cross-validation: leave-one-out (LOO) and k-fold, Decision trees, k-nearest neighbour and naive Bayes classifier, Logistic regression, Simple linear regression, multiple linear regression and ridge regression, Support vector machine

Concept notes

1. The supervised learning set-up

In supervised learning you are given a training set of labelled pairs {(xi,yi)}i=1n, where xi∈Rd is a feature vector and yi is the label (target). You choose a hypothesis f from a model family (lines, trees, networks) so that f(x)≈y on new data drawn from the same distribution.

The type of y decides the problem:

Regression Classification
Output y real number, e.g. price, temperature one of K classes, e.g. spam / not spam
Typical loss squared error (y−y^)2 0–1 loss, cross-entropy, hinge
Output of model a number a class, often via scores or P(y∣x)
Syllabus methods linear, multiple, ridge regression; kNN and tree regression logistic regression, kNN, naive Bayes, LDA, SVM, trees, MLP

A classification problem with K=2 is binary; K>2 is multiclass. Predicting an ordered count or score with a real-valued model is still regression.

Learning means minimising the average training loss (empirical risk) 1n∑iL(yi,f(xi)), but the goal is low loss on unseen data, called the test or generalisation error.

2. Measuring a regression model

For predictions y^i and residuals ei=yi−y^i:

  • Mean squared error: MSE=1n∑ei2. Penalises large errors heavily. RMSE =MSE is in the units of y.
  • Mean absolute error: MAE=1n∑∣ei∣. Less sensitive to outliers.
  • Coefficient of determination: R2=1−SSresSStot, where SSres=∑ei2 and SStot=∑(yi−yˉ)2.

Reading R2:

  • R2=1: perfect fit. R2=0: no better than always predicting yˉ.
  • On training data with an intercept, least squares gives 0≤R2≤1. On test data R2 can be negative (worse than the mean).
  • Adding a feature to a least-squares model never lowers the training R2, so a higher training R2 alone does not mean a better model.

Squared error is the default regression loss because it is differentiable and gives a closed-form least-squares solution; its minimiser over constants is the mean, while the minimiser of absolute error is the median.

3. Measuring a classifier: the confusion matrix

For a binary classifier, count the four outcomes on the evaluation set:

  • TP (true positive), FN (false negative: a missed positive), FP (false positive: a false alarm), TN (true negative).

From these:

  • Accuracy =TP+TNTP+TN+FP+FN; error rate =1− accuracy.
  • Precision =TPTP+FP: of the predicted positives, how many are real.
  • Recall (sensitivity, true positive rate) =TPTP+FN: of the real positives, how many were found.
  • Specificity =TNTN+FP.
  • F1 score =2PRP+R, the harmonic mean of precision and recall.

When accuracy misleads: with imbalanced classes (say 95% negatives), a model that always says "negative" has 95% accuracy but recall 0. Use precision, recall or F1 there. Precision matters when false alarms are costly (spam filter); recall matters when misses are costly (disease screening). Raising the decision threshold usually raises precision and lowers recall.

Predicted PositiveNegative Actual PositiveNegative TPcorrect hit FNmissed positive FPfalse alarm TNcorrect reject
Binary confusion matrix: rows are actual classes, columns are predicted classes

4. Decision boundaries and multiclass strategies

A classifier splits the feature space into regions, one per class; the surface between regions is the decision boundary.

  • Linear classifiers (logistic regression, LDA, linear SVM, perceptron) use a hyperplane w⊤x+b=0 and predict by the sign of w⊤x+b.
  • Non-linear boundaries come from kNN, decision trees, kernel SVMs, MLPs, and from linear models on transformed features (e.g. x12,x1x2).

Parametric vs non-parametric: a parametric model has a fixed number of parameters (linear regression has d+1). A non-parametric model such as kNN keeps the training data and grows with n.

Binary methods for K classes:

  • One-vs-rest: train K classifiers, class k vs the rest; predict the class with the highest score.
  • One-vs-one: train (K2)=K(K−1)2 classifiers, one per pair; predict by majority vote.

Some models are multiclass by nature: softmax regression, naive Bayes, LDA, kNN, decision trees.

A discriminative model learns P(y∣x) or the boundary directly (logistic regression, SVM). A generative model learns P(x∣y) and P(y) and applies Bayes' theorem (naive Bayes, LDA).

5. Training error, test error and overfitting

Training error is an optimistic estimate: the model has seen those points. To estimate generalisation, keep a test set that is never used for fitting or for choosing settings; use a validation set (or cross-validation) for choosing hyperparameters such as k in kNN, tree depth or the ridge penalty λ.

  • Underfitting: the model is too simple; both training and test error are high (high bias).
  • Overfitting: the model fits noise; training error is low but test error is high (high variance).

As model complexity grows, training error keeps falling, while test error first falls and then rises. The best model sits near the bottom of the test error curve.

Practical checks:

  • A 1-nearest-neighbour classifier or a fully grown tree has zero training error on distinct points; that says nothing about test error.
  • More training data usually reduces overfitting.
  • Regularisation (penalising large weights, pruning trees) trades a little bias for less variance.

These ideas are developed in the bias–variance and cross-validation topics.

Formulas to remember

Mean squared error
MSE=1n∑i=1n(yi−y^i)2
Coefficient of determination
R2=1−∑i(yi−y^i)2∑i(yi−yˉ)2
Accuracy
Accuracy=TP+TNTP+TN+FP+FN
Precision and recall
P=TPTP+FP,R=TPTP+FN
F1 scoreHarmonic mean of precision P and recall R
F1=2PRP+R
One-vs-one classifier countK classes; one-vs-rest needs only K
(K2)=K(K−1)2

Common mistakes

  • Using accuracy on a heavily imbalanced dataset; a trivial majority-class model can score high.
  • Swapping precision and recall: precision divides by predicted positives (TP + FP), recall by actual positives (TP + FN).
  • Treating a numeric target such as a score or price as classification just because it takes integer values.
  • Reading a low training error as proof of a good model; only held-out data estimates generalisation.
  • Forgetting that test-set R2 can be negative; the bound 0≤R2≤1 holds only for least squares on its own training data.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Metrics from a confusion matrix

numerical

A disease test is evaluated on 200 people: TP = 40, FP = 10, FN = 20, TN = 130. Find accuracy, precision, recall and F1.

  1. Step 1: Find accuracy.

    Try it on paper first.

Example 2: MSE, MAE and R-squared

numerical

True values y=(3,5,7,9) and predictions y^=(2,5,8,10). Find MSE, MAE and R2.

  1. Step 1: Write the residuals.

    Try it on paper first.

Example 3: Regression or classification?

conceptual

Classify each task: (a) predict tomorrow's rainfall in mm; (b) decide whether a loan applicant will default; (c) recognise a handwritten digit 0–9; (d) predict a student's GATE score out of 100.

  1. Step 1: Ask: is the target a real quantity or a category?

    Try it on paper first.

Example 4: Why accuracy can mislead

conceptual

In a fraud dataset, 2% of transactions are fraud. Model M always predicts 'not fraud'. Comment on its accuracy, precision and recall for the fraud class.

  1. Step 1: Find its accuracy.

    Try it on paper first.

Previous year questions

4 official GATE DA questions on this topic, newest first.

Practise these 4 PYQs →

Topic test

10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.