GATE Data Science & AIGATE DA
Module 8 · Machine learning

Machine learning, from a straight line to a neural network

Machine learning carried 15 marks in 2024, 12 in 2025 and 14 in 2026: about one mark in six of the subject paper. The questions are friendlier than they look: fit a line, count a model’s parameters, find the support vectors, compute an information gain, run one round of k-means. This module starts from what “learning from data” even means, builds each method from a small Data Premier League example, and then works through every DA machine-learning question asked so far.

You need: vectors, dot products and eigenvalues from linear algebra, Bayes’ theorem from probability, mean and variance from statistics, and derivatives from calculus. Each chapter recalls the exact piece it uses.

The route

    What does it mean for a computer to “learn”? This part starts from zero: the words every machine-learning question uses (feature, label, training set, loss), how to judge a classifier with a confusion matrix, and then the first real method, linear regression, which fits a straight line by making the squared errors as small as possible. Both chapters carry a past GATE DA question, and every later chapter of this module builds on them.

    You need: nothing from this module. Mean and covariance from statistics, derivatives from calculus and solving a small linear system from linear algebra help in Chapter 1.2; each is recalled where it is used.

    What machine learning is: learning a rule from examples

    Machine learning is a way of building a prediction rule from examples: instead of writing the rule by hand, you show the computer many past cases with their answers and let it find a rule that fits them.

    Every machine-learning question in GATE DA (about one mark in six of the subject paper) uses this chapter’s vocabulary, and 2026 Q47 asked directly for accuracy, precision and recall from a classifier’s mistakes.

    It’s like how a new team analyst learns to read a pitch: nobody hands them a rulebook; they watch hundreds of matches, note what the pitch looked like and what happened, and slowly form their own rule.

    Where it shows up in GATE DA

    The words (feature, label, supervised, training and test set) appear in every machine-learning question; the evaluation measures are asked directly.

    2026 Q47 · accuracy, precision, recall2026 Q12 · test set and LOOCV splits2024 Q18 · kinds of model (PCA, naive Bayes, logistic)
    Heat: every year as vocabulary; metrics asked in 2026

    A problem with no obvious rule

    The Hyderabad Hyperplanes’ physio wants to know, before each match, which players are likely to pick up an injury. Nobody can write down an exact rule for that. Too many things matter: how many overs a bowler sent down last week, how much they slept on the flight, their age, the heat.

    What the physio does have is a record of past seasons: for every player before every match, those numbers, and whether the player was actually injured. Machine learning turns that record into a rule.

    The difference from ordinary programming is the direction of travel. In ordinary programming a person writes the rule and the computer applies it to data. In machine learning the computer is given data together with the answers, and produces the rule.

    The words, one at a time

    Here is a slice of the physio’s record. Each row is one player before one match.

    Overs bowled last weekHours of sleepAgeInjured?
    226.031yes
    88.024no
    157.527no
    255.534yes
    Vocabulary
    example
    One row: one case the model can learn from (here, one player before one match). Also called a data point or an instance. The number of examples is written $n$.
    feature
    One measured input column, such as “hours of sleep”. The features of one example form a vector $\x = (x_1, \ldots, x_d)$ with $d$ entries; for the first row, $\x = (22, 6.0, 31)$ and $d = 3$.
    label
    The answer we want to predict, written $y$. Here $y$ is “injured?”, and for the first row $y = $ yes.
    dataset
    The collection of examples with their labels: $(\x_1, y_1), \ldots, (\x_n, y_n)$.
    model
    The rule being learned: a function $f$ that takes a feature vector and returns a prediction $\hat y = f(\x)$ (read “y-hat”).
    parameter
    A number inside the model that learning adjusts. In the rule "flag a player if $0.1 \times \text{overs} - 0.5 \times \text{sleep} \gt 0$", the 0.1 and the 0.5 are parameters.
    training
    Choosing the parameters so that the model’s predictions match the known labels as well as possible.

    Supervised learning: every training example comes with its label, and the model learns to predict the label from the features. Two kinds, by what the label is:

    • Regression: the label is a number (a team’s final total, a player’s auction price).
    • Classification: the label is one of a few categories, called classes (injured or not; which of the five teams wins).

    Unsupervised learning: there are no labels at all, only features. The goal is to find structure, for example groups of similar fans (clustering, Part 6) or the few directions along which the data varies most (PCA, Part 6).

    Training data and test data

    Suppose a model simply memorised the record: “player 7 before match 12: injured”. It would be perfect on the record and useless next season, because next season’s cases are new. What we care about is performance on examples the model has not seen. That ability is called generalisation.

    So before training, the data is split in two. The training set is used to choose the parameters. The test set is locked away and used only once, at the end, to estimate how the model will do on new cases. A student who has seen the exact exam paper in advance can score full marks without understanding anything; the test set is the paper they have not seen.

    Part 2 builds on this: why a model can fit its training data too well (overfitting) and how cross-validation chooses settings without touching the test set.

    Loss: a number for “how wrong”

    To train, the computer needs a single number that says how bad a prediction is. That number is the loss. Training means choosing the parameters that make the average loss over the training set as small as possible.

    A loss function $\ell(y, \hat y)$ measures the cost of predicting $\hat y$ when the truth is $y$. Two common ones:

    • Squared loss (regression): $\ell(y, \hat y) = (y - \hat y)^2$. Predicting a total of 170 when the team made 180 costs $10^2 = 100$.
    • 0–1 loss (classification): $\ell = 0$ if $\hat y = y$ and $1$ otherwise. It simply counts mistakes.

    The training error is the average loss over the training set, $\frac1n\sum_{i=1}^n \ell(y_i, f(\x_i))$. The same average over the test set is the test error.

    Judging a classifier: the confusion matrix

    Say the physio’s model flags players as “at risk” (the positive class) or “fine” (the negative class). Each prediction lands in one of four boxes, and counting them gives the confusion matrix.

    Predicted positivePredicted negative
    Actually positiveTP true positive: injured, and flaggedFN false negative: injured, but missed
    Actually negativeFP false positive: fine, but flaggedTN true negative: fine, not flagged

    $$\text{accuracy} = \frac{TP + TN}{TP + FP + FN + TN},\qquad \text{precision} = \frac{TP}{TP + FP},\qquad \text{recall} = \frac{TP}{TP + FN}.$$

    • Accuracy: what fraction of all predictions were right.
    • Precision: of the players we flagged, what fraction were really injured? (Read along the “predicted positive” column.)
    • Recall: of the players who were really injured, what fraction did we flag? (Read along the “actually positive” row.) Also called sensitivity or true positive rate.

    With more than one class of interest, each class gets its own precision and recall: treat that class as “positive” and every other class as “negative”.

    Careful: accuracy can flatter a useless model. If only 2% of matches are rain-delayed, a “model” that always answers “no delay” is 98% accurate and never catches a single delay: its recall is 0. When one class is rare, look at precision and recall.
    Try it

    The model gives each of 20 Hyderabad Hyperplanes players an injury-risk score, and flags everyone whose score is at or above the threshold. Move the threshold and watch the four counts change. Notice that lowering it raises recall (fewer injured players missed) but lets in more false alarms. Then switch to “rare injuries” and find a threshold with high accuracy but poor recall.

    GATE DA 2026 · Q47 · MSQ · 2 marks

    Consider that 20 stories of Author X and 10 stories of Author Y were kept together without mentioning the names of the authors. A classifier was then asked to predict the author (X or Y) of each of these stories. Let, out of X’s stories, 6 were classified as that of Y. On the other hand, out of Y’s stories, 2 were classified as that of X.

    Considering X and Y as two classes, which of the following statements is/are true?

    1. Accuracy of the classifier is 11/15.
    2. Precision of Class X is higher than the Precision of Class Y.
    3. Recall of Class X is higher than the Recall of Class Y.
    4. Accuracy of the classifier is 14/15.
    1. Fill the confusion matrix. X’s 20 stories: 6 called Y, so 14 called X. Y’s 10 stories: 2 called X, so 8 called Y.

      Every question about these measures starts with the four counts. Rows are the truth, columns the prediction.

    2. Accuracy $= \dfrac{14 + 8}{30} = \dfrac{22}{30} = \dfrac{11}{15}$. So (A) is true and (D) is false.

      The correct predictions are the diagonal: X called X, and Y called Y.

    3. Precision of X: the classifier said “X” $14 + 2 = 16$ times and was right 14 times, so $\tfrac{14}{16} = 0.875$. Precision of Y: it said “Y” $8 + 6 = 14$ times and was right 8 times, so $\tfrac{8}{14} \approx 0.571$. (B) is true.

      Precision divides by how often a class was predicted, so read down the column.

    4. Recall of X $= \tfrac{14}{20} = 0.7$; recall of Y $= \tfrac{8}{10} = 0.8$. X’s recall is lower, so (C) is false. Answer: (A) and (B).

      Recall divides by how many truly belong to the class, so read along the row. Official key: A; B.

    The Hyderabad Hyperplanes’ injury model is checked on 100 player-matches: 12 true positives, 8 false positives, 4 false negatives and 76 true negatives. Find its precision and its recall.

    Precision divides TP by everything that was flagged; recall divides TP by everything that was really injured.

    Precision $= \frac{12}{12 + 8} = 0.6$. Recall $= \frac{12}{12 + 4} = 0.75$. (Accuracy would be $\frac{12 + 76}{100} = 0.88$, which sounds better than either.)

    Which of these is an unsupervised learning task?

    1. Predicting a team’s final total from its score after 10 overs, using last season’s matches.
    2. Splitting ticket buyers into groups with similar buying habits, with no group names given in advance.
    3. Deciding whether a delivery was a no-ball, from clips that umpires have already marked.
    4. Predicting a player’s auction price from past auctions.

    Ask of each task: does the training data come with the answer we want to predict?

    (B) has no labels: nobody says which group a buyer belongs to, so the method must discover the groups (clustering). (A) and (D) are supervised regression (the label is a number); (C) is supervised classification (the umpires supplied the labels).

    Of 1000 DPL matches, 20 were rain-delayed. A lazy model predicts “no delay” for every match. Taking “delayed” as the positive class, find its accuracy and its recall.

    It gets every non-delayed match right and every delayed match wrong. How many delays does it catch?

    Correct predictions: the 980 non-delayed matches, so accuracy $= 980/1000 = 0.98$. It flags nothing, so TP = 0 and recall $= 0/20 = 0$. High accuracy, no use at all.

    Which statements about training and test sets are true? (Select all that apply.)

    1. The test set should not be used to choose the model’s parameters.
    2. A training error of zero guarantees a small test error.
    3. The test error estimates how the model will do on new, unseen examples.
    4. The training and test examples should come from the same kind of data (for example, the same league and era).

    Think of the student who memorised last year’s paper.

    (A) If the test set helps choose parameters, it is no longer unseen and its error becomes optimistic. (C) That is its whole purpose. (D) A test on a different kind of data says little about the cases you care about. (B) is false: a model can memorise its training set (zero training error) and still do badly on new examples; that is overfitting, Part 2.

    A model predicts upsets (the weaker team winning) in 200 DPL matches; 50 of them were actual upsets. On these matches its recall for “upset” is 0.8 and its precision is 0.5. What is its accuracy?

    Recall gives TP. Precision then tells you how many matches were flagged in total, hence FP. The rest of the 150 non-upsets are TN.

    Recall $= TP/50 = 0.8$, so $TP = 40$ and $FN = 10$.

    Precision $= TP/(TP + FP) = 0.5$, so $40$ is half of everything flagged: 80 flagged, $FP = 40$.

    Non-upsets: $150$, of which 40 were wrongly flagged, so $TN = 110$.

    Accuracy $= \frac{40 + 110}{200} =$ 0.75.

    A tempting slip is to average precision and recall (0.65), or to take $TP/200 = 0.2$; neither is accuracy, which counts every correct prediction, including true negatives.

    A classifier gives each example a score and predicts “positive” when the score is at least a threshold $t$. Which statements are always true? (Select all that apply.)

    1. Lowering $t$ can never decrease recall.
    2. Lowering $t$ can never increase precision.
    3. Setting $t$ below every score gives recall 1.
    4. If 1% of examples are positive, any classifier with 99% accuracy has recall at least 0.5.

    Recall’s denominator (actual positives) never changes with $t$. For precision, try three examples whose scores, from highest to lowest, are negative, positive, positive.

    (A) True. Lowering $t$ only adds flagged examples, so TP can only stay the same or grow, while TP + FN (the number of actual positives) is fixed.

    (C) True. Every example is flagged, so FN = 0 and recall $= TP/TP = 1$.

    (B) False. With scores ordered negative, positive, positive (highest first), a high $t$ flags only the negative: precision 0. Lowering $t$ to include the next one gives precision $\tfrac12$. Precision can go either way.

    (D) False. Predicting “negative” for everything is 99% accurate with recall 0.

    A batter’s scores in four innings are 2, 3, 4 and 11. You must predict every innings with one constant $c$. Which pair gives, in order, the $c$ that minimises the total squared loss $\sum (y_i - c)^2$ and a $c$ that minimises the total absolute loss $\sum |y_i - c|$?

    1. 5 and 5
    2. 5 and 3.5
    3. 3.5 and 5
    4. 4 and 4

    Differentiate $\sum (y_i - c)^2$ and set it to zero. For the absolute loss, ask what happens to the total when $c$ moves a little to the right: how many points get nearer, and how many get farther?

    Squared loss: $\frac{d}{dc}\sum (y_i - c)^2 = -2\sum (y_i - c) = 0$ gives $c = \bar y = \frac{20}{4} = 5$, the mean. Total loss $9 + 4 + 1 + 36 = 50$.

    Absolute loss: moving $c$ right by a small step lowers the loss by that step for each point above $c$ and raises it for each point below. The total stops falling once half the points are on each side, so any $c$ between the two middle values 3 and 4 is best (total 10). That is the median; 3.5 is one such value. Answer (B).

    (A) assumes both losses share a minimiser; the outlier 11 drags the mean but not the median. (C) swaps them. (D) has a valid absolute-loss minimiser (4), but under squared loss 4 costs $4 + 1 + 0 + 49 = 54 \gt 50$.

    • Name the positive class before computing precision or recall.
    • Write the four counts (TP, FP, FN, TN) first; every measure is a ratio of them.
    • Keep the test set untouched until the very end.
    • Swapping precision and recall: precision divides by what was predicted positive, recall by what is positive.
    • Trusting accuracy when one class is rare.
    • Calling a task “unsupervised” just because the labels are numbers. Numeric labels mean regression, which is still supervised.
    1. Supervised learning learns a model ŷ = f(x) from examples with labels (regression for numbers, classification for categories); unsupervised learning has no labels.
    2. Train on the training set by minimising average loss; judge on an unseen test set.
    3. Accuracy = (TP + TN)/all, precision = TP/(TP + FP), recall = TP/(TP + FN).

    A model predicts rain delays and is right on 95% of matches. Only 5% of matches are actually delayed. Is it a good model?

    Yes: 95% is excellent
    What would a model that never predicts a delay score here?
    Can’t tell yet: always saying “no delay” also scores 95%
    With a rare class, accuracy alone hides whether the model catches any delays. Check its recall and precision.
    No: 95% accuracy always means poor recall
    It might catch every delay. Accuracy alone can’t say either way.
    Yes, as long as the test set was used for training
    Training on the test set makes the 95% less trustworthy, not more.

    A dataset of past matches has columns “toss won”, “home ground”, “score at 10 overs” and “won the match”. A model predicts the result before the match ends. Which column is the label?

    score at 10 overs
    That’s something the model is given, so it’s a feature.
    home ground
    Known before the match: a feature.
    won the match
    It’s the answer the model learns to predict. The other three are features.
    All four together
    The label is the one thing being predicted.

    Recall answers which question?

    Of everything the model flagged, how much was really positive?
    That one divides by what was predicted positive. Which measure is that?
    Of all predictions, how many were right?
    That counts both classes’ correct predictions.
    Of the real negatives, how many were left unflagged?
    That is about negatives. Recall is about positives.
    Of the real positives, how many did the model catch?
    Recall $= TP/(TP + FN)$: the denominator is every actual positive.

    Linear regression: the best straight line

    Linear regression predicts a number as a weighted sum of the features, and chooses the weights that make the sum of squared prediction errors on the training data as small as possible.

    GATE DA 2025 Q34 asked for the least-squares slope of a line through the origin, and the closed form $\mathbf{w} = (X\T X)^{-1}X\T\y$ met here is the starting point of ridge regression (2026 Q37 and Q55, Part 2).

    It’s like a stiff rod held by springs, one hanging from each data point: the rod settles where the springs’ total pull balances, and with springs whose energy grows with the square of their stretch, that resting place is the least-squares line.

    Where it shows up in GATE DA

    A direct computation (the slope of a fitted line), and the base that ridge regression changes.

    2025 Q34 · y = wx by least squares2026 Q37 · ridge regression (Part 2)2026 Q55 · ridge weights (Part 2)Sample Q12 · ridge (Part 2)
    Heat: most years, directly or through ridge

    The question

    The Bengaluru Backprops’ analyst wants to predict how many runs a batter will score from how many balls they face. Four innings from last season:

    Balls faced $x$10203040
    Runs $y$18244252

    Plot them and they lie roughly along a line. No single line passes through all four, so we need a way to say which line is best.

    A line is $\hat y = wx + b$: $w$ is the slope (extra runs per extra ball faced) and $b$ is the intercept (the prediction at $x = 0$). In machine-learning language, $w$ is a weight and $b$ a bias; both are the model’s parameters.

    For each innings, the gap between what happened and what the line predicts, $y_i - \hat y_i$, is the residual. Some residuals are positive, some negative. Squaring them makes every gap count as a cost and punishes big misses heavily. The least-squares line is the one with the smallest total of squared residuals.

    Given data $(x_1, y_1), \ldots, (x_n, y_n)$, choose $w$ and $b$ to minimise the sum of squared errors $$\text{SSE}(w, b) = \sum_{i=1}^n \big(y_i - (wx_i + b)\big)^2.$$ This is the squared loss of Chapter 1.1, added up over the training set. Dividing by $n$ gives the mean squared error (MSE); the same $w, b$ minimise both.

    Try it

    Move the slope and intercept sliders to make the total of squared residuals (the vertical gaps, drawn dashed) as small as you can, then press “Best fit” to see how close you came. Drag a point (or select the plot and use the arrow keys; keys 1–4 pick a point) and watch the best line follow it. Switch to “through the origin” to see what forcing $b = 0$ costs.

    Finding the best line with calculus

    SSE is a smooth bowl-shaped function of $w$ and $b$, so its lowest point is where both partial derivatives are zero (recall from Calculus 2.2 that an interior minimum has zero gradient).

    Setting $\partial\,\text{SSE}/\partial b = -2\sum (y_i - wx_i - b) = 0$ gives $\sum y_i = w\sum x_i + nb$, that is, $\bar y = w\bar x + b$. So the best line always passes through the point of means $(\bar x, \bar y)$.

    Setting $\partial\,\text{SSE}/\partial w = -2\sum x_i (y_i - wx_i - b) = 0$ and substituting $b = \bar y - w\bar x$ gives the slope below.

    $$w = \frac{\sum_i (x_i - \bar x)(y_i - \bar y)}{\sum_i (x_i - \bar x)^2} = \frac{\operatorname{Cov}(x, y)}{\operatorname{Var}(x)},\qquad b = \bar y - w\,\bar x.$$ (The sample covariance and variance from Statistics; their $\tfrac1{n-1}$ factors cancel.)

    Through the origin. If the model is forced to be $\hat y = wx$ (no intercept), only $\frac{d}{dw}\sum (y_i - wx_i)^2 = -2\sum x_i(y_i - wx_i) = 0$ remains, so $$w = \frac{\sum_i x_i y_i}{\sum_i x_i^2}.$$

    Fit $\hat y = wx + b$ to the four Backprops innings above, then fit $\hat y = wx$ through the origin, and compare the two SSEs.

    1. Means: $\bar x = 25$, $\bar y = \frac{18 + 24 + 42 + 52}{4} = 34$. Deviations: $x_i - \bar x = -15, -5, 5, 15$ and $y_i - \bar y = -16, -10, 8, 18$.

      Centring first keeps the numbers small and is exactly what the slope formula asks for.

    2. $\sum (x_i - \bar x)(y_i - \bar y) = 240 + 50 + 40 + 270 = 600$ and $\sum (x_i - \bar x)^2 = 225 + 25 + 25 + 225 = 500$. So $w = \frac{600}{500} = 1.2$.

      Each extra ball faced is worth 1.2 runs on this line: a strike rate of 120.

    3. $b = \bar y - w\bar x = 34 - 1.2 \times 25 = 4$. The line is $\hat y = 1.2x + 4$, with predictions 16, 28, 40, 52 and residuals $2, -4, 2, 0$. SSE $= 4 + 16 + 4 + 0 = 24$.

      The residuals add to zero, as they must when the fit has an intercept (that was the $\partial/\partial b = 0$ equation).

    4. Through the origin: $\sum x_i y_i = 180 + 480 + 1260 + 2080 = 4000$ and $\sum x_i^2 = 100 + 400 + 900 + 1600 = 3000$, so $w = \frac{4000}{3000} \approx 1.333$. Its SSE is about 34.67, larger than 24.

      Removing $b$ removes a parameter, so the best fit can only get worse (or stay equal). The slope steepens to make up for the missing intercept.

    GATE DA 2025 · Q34 · NAT · 1 mark

    Given data $\{(-1, 1), (2, -5), (3, 5)\}$ of the form $(x, y)$, we fit a model $y = wx$ using linear least-squares regression. The optimal value of $w$ is ______ (Round off to three decimal places)

    1. The model has no intercept, so use $w = \dfrac{\sum x_i y_i}{\sum x_i^2}$.

      "$y = wx$" is the signal: a line forced through the origin. The centred formula would be wrong here, because it fits an intercept too.

    2. $\sum x_i y_i = (-1)(1) + (2)(-5) + (3)(5) = -1 - 10 + 15 = 4$. $\sum x_i^2 = 1 + 4 + 9 = 14$.

      Watch the signs: two of the three products are negative.

    3. $w = \frac{4}{14} = \frac27 \approx$ 0.286.

      Official key: 0.285 to 0.287.

    More than one feature

    Runs probably depend on more than balls faced: the batting position, the pitch, the opposition. With $d$ features the model becomes $$\hat y = w_1x_1 + w_2x_2 + \cdots + w_dx_d + b = \mathbf{w}\T\x + b.$$ This is multiple linear regression. With two features it fits a flat plane to points in 3-D; with more, a flat “hyperplane” (the higher-dimensional version of a plane).

    To write all $n$ predictions at once, stack the examples as rows of a matrix. Put a column of ones first so that the intercept becomes just another weight: $$X = \begin{pmatrix} 1 & x_{11} & \cdots & x_{1d}\\ \vdots & \vdots & & \vdots\\ 1 & x_{n1} & \cdots & x_{nd}\end{pmatrix},\qquad \mathbf{w} = \begin{pmatrix} b\\ w_1\\ \vdots\\ w_d\end{pmatrix},\qquad \hat\y = X\mathbf{w}.$$ $X$ is the design matrix: $n$ rows (examples) and $d + 1$ columns. The SSE is $\norm{\y - X\mathbf{w}}^2$.

    The weights that minimise $\norm{\y - X\mathbf{w}}^2$ satisfy $$X\T X\,\mathbf{w} = X\T\y.$$ If the columns of $X$ are linearly independent, $X\T X$ is invertible and $$\mathbf{w} = (X\T X)^{-1}X\T\y.$$ For a model with no intercept, simply leave out the column of ones.

    Why. The gradient of $\norm{\y - X\mathbf{w}}^2$ with respect to $\mathbf{w}$ is $-2X\T(\y - X\mathbf{w})$; setting it to zero gives the normal equations. Read geometrically: the residual vector $\y - X\mathbf{w}$ is perpendicular to every column of $X$. The fitted values $X\mathbf{w}$ are the projection of $\y$ onto the column space of $X$ (recall projections from Linear algebra 3.2). The column of ones being perpendicular to the residuals is the statement “residuals add to zero”.

    With one feature and an intercept, the normal equations reduce to the formulas above. For the Backprops data: $X\T X = \begin{pmatrix}4 & 100\\ 100 & 3000\end{pmatrix}$ and $X\T\y = \begin{pmatrix}136\\ 4000\end{pmatrix}$. Solving gives $b = 4$, $w = 1.2$, the same line.

    When the columns are dependent (a feature repeated, a feature that is a fixed multiple of another, or fewer examples than weights), $X\T X$ is singular and infinitely many weight vectors fit equally well. Ridge regression (Part 2) fixes this by adding $\lambda I$.

    "Fit $y = wx$" (no intercept): $w = \sum xy / \sum x^2$. "Fit $y = wx + b$": $w = \sum (x - \bar x)(y - \bar y) / \sum (x - \bar x)^2$ and $b = \bar y - w\bar x$. With several features, write $X\T X$ and $X\T\y$ and solve the small system; for a $2\times2$ system, $\begin{pmatrix}a & b\\ c & d\end{pmatrix}^{-1} = \frac{1}{ad - bc}\begin{pmatrix}d & -b\\ -c & a\end{pmatrix}$.

    Fit the least-squares line $\hat y = wx + b$ to the points $(1, 3)$, $(2, 5)$, $(3, 4)$, $(4, 8)$.

    $\bar x = 2.5$ and $\bar y = 5$. Multiply the deviations pairwise and add.

    Deviations: $x - \bar x = -1.5, -0.5, 0.5, 1.5$ and $y - \bar y = -2, 0, -1, 3$.

    $\sum (x - \bar x)(y - \bar y) = 3 + 0 - 0.5 + 4.5 = 7$ and $\sum (x - \bar x)^2 = 2.25 + 0.25 + 0.25 + 2.25 = 5$, so $w = 1.4$.

    $b = 5 - 1.4 \times 2.5 = 1.5$.

    The Backprops’ fitted line is $\hat y = 1.2x + 4$ (runs from balls faced). Predict the runs for a batter who faces 35 balls, and find the residual for an innings of 42 runs off 30 balls.

    A residual is actual minus predicted.

    Prediction: $1.2 \times 35 + 4 = 46$. For 30 balls the line predicts $1.2 \times 30 + 4 = 40$, so the residual is $42 - 40 = 2$.

    A multiple linear regression with an intercept uses 3 features and is trained on 50 matches. What is the size of $X\T X$ in the normal equations?

    1. $3\times3$
    2. $4\times4$
    3. $50\times50$
    4. $50\times4$

    First find the size of $X$ itself, remembering the column of ones.

    $X$ is $50\times4$ (one row per match; a column of ones plus 3 feature columns). Then $X\T X$ is $(4\times50)(50\times4) = 4\times4$: one row and column per weight. (A) forgets the intercept; (C) is $XX\T$; (D) is $X$ itself.

    A least-squares line $\hat y = wx + b$ (with intercept) is fitted to $n \ge 3$ points whose $x$ values are not all equal. Which statements are always true? (Select all that apply.)

    1. The residuals add up to zero.
    2. The line passes through $(\bar x, \bar y)$.
    3. At least one residual is zero.
    4. Fitting $x$ from $y$ instead gives slope exactly $1/w$.

    (A) and (B) both come from setting $\partial\,\text{SSE}/\partial b = 0$. For (C) and (D), test the four Backprops points or a small example.

    (A) and (B) are the equation $\sum (y_i - wx_i - b) = 0$, written two ways.

    (C) is false: for $(1, 3), (2, 5), (3, 4), (4, 8)$ the line $1.4x + 1.5$ predicts 2.9, 4.3, 5.7, 7.1, and no residual is zero. (The Backprops fit had one zero residual by chance.)

    (D) is false: the two slopes are $\frac{\text{Cov}}{\text{Var}(x)}$ and $\frac{\text{Cov}}{\text{Var}(y)}$, whose product is $r^2$ (the squared correlation), which equals 1 only if the points lie exactly on a line.

    A model with two features and no intercept, $\hat y = w_1x_1 + w_2x_2$, is fitted by least squares to four examples: $(x_1, x_2; y) = (1, 0; 1)$, $(0, 1; 2)$, $(1, 1; 3)$, $(1, 2; 6)$. Find $w_2$ and the SSE of the fitted model. (Round off to two decimal places.)

    Build $X$ ($4\times2$, no column of ones), then $X\T X$ and $X\T\y$, and solve the $2\times2$ system.

    $X\T X = \begin{pmatrix}1+0+1+1 & 0+0+1+2\\ 3 & 0+1+1+4\end{pmatrix} = \begin{pmatrix}3 & 3\\ 3 & 6\end{pmatrix}$ and $X\T\y = \begin{pmatrix}1 + 3 + 6\\ 2 + 3 + 12\end{pmatrix} = \begin{pmatrix}10\\ 17\end{pmatrix}$.

    Determinant $18 - 9 = 9$. So $w_1 = \frac{6\cdot10 - 3\cdot17}{9} = 1$ and $w_2 = \frac{3\cdot17 - 3\cdot10}{9} = \frac{21}{9} = \frac73 \approx$ 2.33.

    Predictions: $1$, $\tfrac73$, $\tfrac{10}{3}$, $\tfrac{17}{3}$. Residuals: $0$, $-\tfrac13$, $-\tfrac13$, $\tfrac13$. SSE $= 3\times\tfrac19 = \tfrac13 \approx$ 0.33.

    Check: the residual vector $(0, -\tfrac13, -\tfrac13, \tfrac13)$ is perpendicular to both columns of $X$, $(1, 0, 1, 1)$ and $(0, 1, 1, 2)$, as the normal equations promise. The residuals do not add to zero, because there is no intercept column.

    The Backprops’ line $\hat y = 1.2x + 4$ was fitted with $x$ in balls faced. The analyst now measures $x$ in overs ($x' = x/6$) and, because of a scoring-rule change, adds 10 to every $y$. Refitting by least squares on the converted data gives $\hat y = w'x' + b'$ with

    1. $w' = 0.2$, $b' = 14$
    2. $w' = 7.2$, $b' = 14$
    3. $w' = 7.2$, $b' = 4$
    4. $w' = 1.2$, $b' = 14$

    Rewrite the old fitted line in terms of $x'$. Is the result still the best line for the new data? Look at the slope formula: what do dividing every $x$ by 6 and adding 10 to every $y$ do to the deviations?

    Dividing $x$ by 6 divides every $x - \bar x$ by 6, so $\text{Cov}$ is divided by 6 and $\text{Var}(x)$ by 36: the slope is multiplied by 6, $w' = 7.2$ (runs per over, not per ball).

    Adding 10 to every $y$ leaves the deviations $y - \bar y$ unchanged (so the slope is unaffected) and raises $\bar y$ by 10. With $\bar x' = 25/6$: $b' = (34 + 10) - 7.2 \times \frac{25}{6} = 44 - 30 = 14$. Answer (B).

    Equivalently, $1.2x + 4 + 10 = 1.2(6x') + 14 = 7.2x' + 14$, and since the converted data are just a relabelling, the best line is relabelled the same way.

    (A) divides the slope by 6 instead of multiplying; (C) forgets the shift in $y$; (D) ignores the change of units.

    For a linear regression with an intercept (design matrix $X$ with a column of ones), in which situations is $X\T X$ certainly singular, so that $(X\T X)^{-1}X\T\y$ cannot be used? (Select all that apply.)

    1. Two feature columns are identical (the same statistic entered twice).
    2. There are 5 features and only 4 training examples.
    3. One feature takes the same value in every example.
    4. The features are measured in very different units (balls and seconds).

    $X\T X$ is invertible exactly when the columns of $X$ are linearly independent. For each option, find a column that is a combination of others, or show why none need be.

    $X\T X$ is invertible exactly when $X$ has independent columns (rank equal to the number of columns; see Linear algebra 2.2).

    (A) Two equal columns are dependent. (B) $X$ is $4\times6$, so its rank is at most 4, less than 6 columns. (C) A constant column is a multiple of the column of ones. All three make $X\T X$ singular.

    (D) Units rescale columns but do not make them dependent, so $X\T X$ can still be invertible (rescaling can make it badly conditioned numerically, which is a different issue).

    • Check whether the model has an intercept before choosing a formula.
    • Centre the data ($x - \bar x$, $y - \bar y$) when computing a slope by hand.
    • Sanity-check: with an intercept, residuals add to zero and the line passes through the means.
    • Using $\sum xy/\sum x^2$ when the model has an intercept, or the centred formula for "$y = wx$".
    • Measuring residuals perpendicular to the line; least squares uses vertical gaps.
    • Forgetting the column of ones in $X$, which drops the intercept from the normal equations.
    1. Least squares picks the weights that minimise the sum of squared residuals Σ(yᵢ − ŷᵢ)².
    2. One feature: w = Σ(x − x̄)(y − ȳ)/Σ(x − x̄)², b = ȳ − w x̄; through the origin, w = Σxy/Σx².
    3. Many features: solve the normal equations XᵀX w = Xᵀy, so w = (XᵀX)⁻¹Xᵀy when the columns of X are independent.

    Three points: $(0, 0)$, $(1, 1)$ and $(2, 5)$. Without computing, how steep is the least-squares line $\hat y = wx + b$?

    Slope less than 1
    The last point sits far above the trend of the first two. Which way does it pull the line?
    Slope exactly 1, through the first two points
    That line misses $(2, 5)$ by 3, and squared errors punish that heavily.
    Slope well above 1
    The point $(2, 5)$ pulls the right end up. Computing: $\bar x = 1$, $\bar y = 2$, slope $= \frac{5}{2} = 2.5$.
    Slope 0, because the residuals must add to zero
    Residuals adding to zero fixes the line’s height at the means, not its slope.

    For the model $y = wx$ (no intercept), least squares gives $w = $

    $\sum x_iy_i / \sum x_i^2$
    From $\frac{d}{dw}\sum (y_i - wx_i)^2 = 0$.
    $\bar y / \bar x$
    Only right in special cases. Differentiate the SSE with respect to $w$.
    $\sum (x_i - \bar x)(y_i - \bar y) / \sum (x_i - \bar x)^2$
    That is the slope when an intercept is also fitted.
    $\sum y_i / \sum x_i$
    Try it on $(1, 1), (2, 5)$: does it minimise the SSE?

    The formula $\mathbf{w} = (X\T X)^{-1}X\T\y$ can be used exactly when

    $X$ is square
    $X$ is $n\times(d+1)$ and is usually tall, not square.
    every residual is zero
    The formula gives the best fit even when residuals are not zero.
    $\y$ has no zero entries
    The entries of $\y$ don’t affect whether the inverse exists.
    the columns of $X$ are linearly independent
    Then $X\T X$ is invertible. If they are dependent, many weight vectors fit equally well.

    A classifier flags 40 players as at risk; 30 of them really were injured. Overall, 50 players were injured. Its precision and recall are

    0.6 and 0.75
    Precision divides by what was flagged; recall by what was really injured. Which number goes with which?
    0.75 and 0.6
    Precision $= 30/40$; recall $= 30/50$.
    0.75 and 0.75
    Recall’s denominator is the 50 injured players.
    0.3 and 0.5
    These aren’t ratios of the counts given.

    Fit $y = wx$ by least squares to $(1, 2)$ and $(2, 3)$. Then $w = $

    1.5
    That fits only the second point (3/2). Least squares balances both.
    1
    That’s the slope of the line through both points, which has an intercept.
    2
    That fits only the first point.
    1.6
    $\sum xy/\sum x^2 = (2 + 6)/(1 + 4) = 8/5$.

    Predicting tomorrow’s attendance at a DPL ground from past attendance records is

    supervised regression
    Past records give the answer (a number) for each example.
    supervised classification
    Is attendance a category or a number?
    unsupervised learning
    The past records include the answer we want to predict.
    not machine learning
    Learning a rule from past examples with answers is exactly machine learning.

    A least-squares line with intercept is fitted to data with $\bar x = 10$, $\bar y = 50$ and slope $w = 3$. The intercept is

    50
    That is $\bar y$. The line passes through $(\bar x, \bar y)$, not $(0, \bar y)$.
    20
    $b = \bar y - w\bar x = 50 - 30$.
    80
    Subtract $w\bar x$, don’t add it.
    Can’t tell without the data
    The means and the slope are enough.

    Least squares makes the training SSE as small as possible. To report how well the line will predict next season, you should give

    the training SSE, since it was minimised
    It was minimised on those very points, so it tends to look better than reality.
    the slope $w$
    The slope describes the line, not how well it predicts.
    the error on a held-out test set
    Unseen examples estimate performance on new cases.
    the number of residuals that are zero
    A few exact hits say little about typical error.

    A model is only useful if it works on data it has never seen. This part is about that gap between the training data and the real world: why a model that fits its training data perfectly can still predict badly (overfitting, and the bias–variance trade-off), how a penalty on large weights fixes it (ridge regression), and how to choose settings such as the penalty strength honestly (cross-validation). GATE DA has asked about each of these: ridge in 2026 and the sample paper, cross-validation in 2026 and the sample paper.

    You need: Part 1 (features, labels, training and test sets, squared-error loss, least-squares linear regression and the normal equations). Mean and variance from Statistics; matrix inverse from Linear algebra.

    Overfitting and the bias–variance trade-off

    A model overfits when it learns the noise in its training data along with the pattern, so it scores brilliantly on the data it has seen and badly on new data; the bias–variance trade-off explains why there is a “just right” level of complexity in between.

    GATE asks this as reasoning, not arithmetic: what happens to bias and variance when you regularise (sample paper Q12, 2026 Q37), and which model is over- or underfitting. It is also the reason ridge regression and cross-validation exist, the next two chapters.

    It’s like a student preparing for an exam by memorising last year’s answer key word for word: full marks on last year’s paper, lost on this year’s. A student who only learns “the answer is usually B” does badly on both. The one who learns the method does well on both.

    Where it shows up in GATE DA

    Conceptual MCQs about bias, variance and regularisation; also behind every “which model generalises better” option.

    Sample Q12 · bias and variance as λ grows2026 Q37 · what ridge’s regulariser does2026 Q12 · model selection by LOOCV
    Heat: most years, usually 1–2 marks, often folded into a ridge question

    Recall from Part 1: a feature is an input we measure (say, the stage of the innings), a label is the value we want to predict (runs scored in that over), the training set is the labelled data the model learns from, and the test set is held back to see how the model does on data it never saw. The loss we use here is squared error, and its average over a data set is the mean squared error (MSE).

    The Kalinga Kernels’ analyst wants to predict runs per over from how far into the innings the over is. Plot twelve past overs and the pattern is a dip in the middle overs and a surge at the death. They now have to choose how flexible the prediction curve should be.

    • A straight line (a degree-1 polynomial, 2 parameters) can’t bend, so it misses the dip and the surge. It is wrong on the training data and wrong on new data in the same systematic way. That is underfitting.
    • A degree-11 polynomial (12 parameters for 12 points) can pass through every training point exactly: training error zero. But to do that it swings wildly between the points, chasing the random ups and downs of those particular twelve overs. On next season’s overs it is far off. That is overfitting.
    • Somewhere between, a degree-3 or degree-4 curve follows the real shape and ignores the noise.

    A parameter is a number the model learns from data (a polynomial’s coefficients). A model’s complexity or capacity is, roughly, how many different shapes it can take; more parameters usually means more capacity. The polynomial’s degree is a hyperparameter: a setting we choose before training, not something least squares learns.

    The training error is the average loss on the training set; the test error (or generalisation error) is the expected loss on new data from the same source, estimated by the average loss on a held-out test set. A model generalises well when its test error is low. The difference, test error minus training error, is the generalisation gap.

    • Underfitting: training error high, test error high, small gap. The model is too simple.
    • Overfitting: training error low, test error much higher, large gap. The model is too flexible for the amount of data.

    Two facts about least-squares polynomials are worth knowing exactly. First, raising the degree can never increase the training error, because the degree-$d$ curves include every degree-$(d-1)$ curve (set the top coefficient to 0), and least squares picks the best one available. Second, with $n$ training points at distinct $x$ values, degree $n-1$ interpolates them: training error exactly 0. The test error does not behave like this. It first falls and then rises, a U shape.

    Try it

    Twelve overs (black dots) come from the dashed green curve plus random noise. Slide the degree from 0 to 11 and watch the small chart: training error (blue) only ever goes down, test error (red, measured on 200 fresh overs) falls and then shoots up. Then switch to “30 training sets”: each faint blue curve is the same degree fitted to a different random sample of twelve overs, and the red curve is their average. At low degree the curves agree with each other but miss the green curve (bias); at high degree their average is close to green but individual curves scatter wildly (variance).

    Bias and variance, in plain words

    Imagine training the same kind of model many times, each time on a fresh random training set of the same size, and then asking every one of those models for its prediction at the same input $x$.

    • The bias is how far the average of those predictions is from the truth. It measures systematic error: the model is too rigid to represent the real pattern, so it is wrong in the same direction whatever data it sees.
    • The variance is how much the predictions spread around their own average. It measures instability: the model is so flexible that a different sample of data gives a noticeably different curve.
    • The noise is the randomness in the labels themselves (two overs at the same stage don’t score the same). No model can remove it, so it is called irreducible error.
    Picture it: four archers. Tight group in the bull’s-eye: low bias, low variance. Tight group off to one side: high bias, low variance (a sight that’s misaligned). Arrows scattered all round the bull’s-eye: low bias, high variance (a shaky hand). Scattered and off to one side: both high.

    Let the label be $y = f(x) + \eps$, with $f$ the true function and $\eps$ noise of mean 0 and variance $\sigma^2$. Let $\hat f(x)$ be the prediction of a model trained on a random training set $D$. Then the expected squared error at $x$, averaging over both the training set and the noise, is $$E\big[(y - \hat f(x))^2\big] = \underbrace{\big(E[\hat f(x)] - f(x)\big)^2}_{\text{bias}^2} + \underbrace{E\Big[\big(\hat f(x) - E[\hat f(x)]\big)^2\Big]}_{\text{variance}} + \underbrace{\sigma^2}_{\text{noise}}.$$

    As complexity grows, bias² usually falls and variance usually rises, so their sum has a minimum in between: the bias–variance trade-off.

    Change you makeBiasVariance
    More flexible model (higher degree, more features, deeper tree, smaller k in k-NN)downup
    Stronger regularisation (larger λ in ridge, next chapter)updown
    More training data, same modelunchangeddown
    Less noisy labelsunchangeddown (and the noise term falls)

    Training error high → high bias (underfitting): use a more flexible model or better features; more data alone won’t help. Training error low but test error much higher → high variance (overfitting): get more data, simplify, or regularise. Regularisation always moves you towards “bias up, variance down”.

    The Haryana Heuristics’ analyst trains the same model on four independent training sets and asks each version to predict runs for one particular over, whose true expected value is $f(x) = 5$. The four predictions are 6, 7, 8 and 7. The label noise has variance $\sigma^2 = 1$. Find the bias², the variance and the expected squared error at this $x$.

    1. Average prediction: $E[\hat f(x)] = \frac{6 + 7 + 8 + 7}{4} = 7$.

      Bias is about the average over training sets, so average first.

    2. Bias² $= (7 - 5)^2 = 4$.

      The model is, on average, 2 runs too high: a systematic error.

    3. Variance $= \frac{(6-7)^2 + (7-7)^2 + (8-7)^2 + (7-7)^2}{4} = \frac{2}{4} = 0.5$.

      Spread of the predictions around their own average, not around the truth. (We divide by 4 because these four are treated as the whole population of training sets.)

    4. Expected squared error $= 4 + 0.5 + 1 =$ 5.5.

      The decomposition adds the three parts. Here bias dominates, so this model underfits: a more flexible model would help more than extra data.

    At a fixed input the truth is $f(x) = 10$ and the noise variance is $\sigma^2 = 3$. Five models trained on five independent training sets predict 9, 11, 13, 7 and 15. Find the bias², the variance (divide by 5) and the expected squared error.

    Average the predictions first. Variance is the spread around that average, not around 10.

    Mean prediction $= 55/5 = 11$, so bias² $= (11 - 10)^2 = 1$.

    Deviations from 11: $-2, 0, 2, -4, 4$; squares $4, 0, 4, 16, 16$, sum 40, so variance $= 40/5 = 8$.

    Expected error $= 1 + 8 + 3 = 12$.

    A model has training MSE 0.02 and test MSE 4.7. Which single change is most likely to reduce the test error?

    1. Add more polynomial features
    2. Add a ridge penalty, or collect more training data
    3. Train for longer to push the training MSE to 0
    4. Report the training MSE instead

    A tiny training error with a large test error is the signature of one of the two failure modes. Which one, and which way should complexity move?

    Low training error, high test error: overfitting, which is high variance. Regularisation and more data both reduce variance, so (B). (A) and (C) make the model fit the training data even more closely, which increases variance. (D) hides the problem instead of fixing it.

    A least-squares polynomial is fitted to 8 training points with distinct $x$ values. What is the smallest degree that is guaranteed to give zero training error, and how many parameters does that polynomial have?

    Through any 2 points with different $x$ there is a line; through any 3, a parabola.

    Through $n$ points with distinct $x$ there is exactly one polynomial of degree $n - 1$, so degree 7, with $7 + 1 =$ 8 coefficients: as many parameters as data points, which is the extreme of overfitting.

    Which changes typically reduce the variance of a regression model? (Select all that apply.)

    (A) Training on more data   (B) Raising the polynomial degree   (C) Increasing the ridge penalty λ   (D) Adding many extra irrelevant features

    Variance is sensitivity to the particular training sample. What makes a fitted curve less jumpy from sample to sample?

    (A) More data averages out the noise, so different samples give more similar fits. (C) A larger penalty pulls weights towards 0, making the model stiffer. (B) and (D) add flexibility, which increases variance. Answer: A and C.

    The Bengaluru Backprops want to estimate their true average runs per over, $\mu = 2$ (in suitable units; the analyst doesn’t know it). They have $n = 4$ independent overs, each with variance $\sigma^2 = 4$, and consider the “shrunk” estimator $c\,\bar y$, where $\bar y$ is the sample mean and $0 \le c \le 1$. Using MSE $= \text{bias}^2 + \text{variance}$, find the value of $c$ that minimises the MSE, and that minimum MSE.

    $E[c\bar y] = c\mu$ and $\operatorname{Var}(c\bar y) = c^2\sigma^2/n$. Write MSE as a quadratic in $c$ and set its derivative to 0.

    Bias $= c\mu - \mu = (c-1)\mu$, so bias² $= (1-c)^2\mu^2 = 4(1-c)^2$. Variance $= c^2\sigma^2/n = c^2 \cdot 4/4 = c^2$.

    MSE$(c) = 4(1-c)^2 + c^2$. Derivative: $-8(1-c) + 2c = 0 \Rightarrow 10c = 8 \Rightarrow c =$ 0.8. In general $c^* = \dfrac{\mu^2}{\mu^2 + \sigma^2/n}$.

    MSE$(0.8) = 4(0.04) + 0.64 =$ 0.8, against MSE$(1) = 1$ for the unbiased sample mean.

    The tempting answer is $c = 1$ because it has zero bias. Accepting a little bias (0.16) buys a larger cut in variance (from 1 to 0.64). That is exactly what ridge regression does to the weights of a linear model.

    The Nagpur Neural Nets’ analyst fits a linear model on larger and larger training sets. The training MSE rises from 2.1 to 6.0 and the test MSE falls from 9.0 to 6.3; both settle near 6, while the noise variance is known to be about 1. Which plan is most likely to lower the test error?

    1. Collect ten times more data with the same model
    2. Increase the ridge penalty
    3. Use a more flexible model, for example add squared and interaction features
    4. Remove features to make the model simpler

    Both curves have already met, far above the noise floor. Is the remaining error variance or bias?

    When training and test errors converge, the variance (the gap) has nearly vanished. The common level, about 6, is far above the irreducible noise of about 1, so the remaining error is mostly bias²: the model is too simple. The remedy is more capacity: (C).

    (A) is the tempting answer, but more data only shrinks variance, and the curves are already flat. (B) and (D) make the model stiffer, increasing bias further.

    Least-squares polynomials of degree $0, 1, \dots, 9$ are fitted to the same 10 training points with distinct $x$ values. Which statements are true? (Select all that apply.)

    (A) The training MSE never increases as the degree increases.
    (B) The test MSE never increases as the degree increases.
    (C) The degree-9 fit has training MSE exactly 0.
    (D) Over repeated training samples, the spread of the fitted value at a fixed $x$ typically grows with the degree.

    For (A), ask whether a degree-$d$ polynomial can imitate a degree-$(d-1)$ one. For (B), think of the U shape.

    (A) True: the degree-$d$ family contains the degree-$(d-1)$ family, and least squares picks the best member, so the minimum can only go down or stay put.

    (B) False: test error is U-shaped; beyond the sweet spot it rises.

    (C) True: 10 distinct points determine a unique degree-9 interpolating polynomial.

    (D) True: that spread is the variance, which grows with flexibility.

    Answer: A, C, D. The trap is (B): it confuses fitting the training data with predicting new data.

    • Judge a model by its error on data it didn’t train on.
    • Diagnose before fixing: high training error means bias; a large train–test gap means variance.
    • Remember the noise floor: no model’s expected test error goes below σ².
    • Choosing the degree (or any hyperparameter) that minimises training error: that always picks the most complex model.
    • Thinking more data cures underfitting. It cures variance, not bias.
    • Computing variance around the true value instead of around the average prediction.
    1. Training error falls as complexity grows; test error is U-shaped. Overfitting = low training error, high test error.
    2. Expected test error = bias² + variance + noise σ². Bias is systematic miss; variance is sensitivity to the training sample.
    3. More flexibility: bias down, variance up. More regularisation: bias up, variance down. More data: variance down.

    A model scores 99% accuracy on its training data but 60% on new data. What is most likely going on?

    Underfitting: the model is too simple
    An underfit model does badly on the training data too. Look at the training score.
    The test data must be mislabelled
    Possible, but the large gap between the two scores has a much more common explanation.
    Overfitting: it has memorised the training data, noise included
    Excellent on seen data, poor on unseen data: a big generalisation gap, the sign of high variance.
    The model needs to be trained for longer
    It already fits the training data almost perfectly; more training would widen the gap.

    In the decomposition $E[(y-\hat f)^2] = \text{bias}^2 + \text{variance} + \sigma^2$, which term can no model reduce?

    $\sigma^2$, the noise
    It is randomness in the labels themselves, present whatever model you use.
    bias²
    A more flexible model can reduce bias.
    variance
    More data or regularisation reduce variance.
    none of them can be reduced
    Bias and variance respond to the choice of model and data. One term doesn’t.

    As the polynomial degree increases from 1 to 15 on a fixed training set of 16 points, the training error

    first falls, then rises
    That is the test error’s shape. Can a higher degree ever fit the training points worse?
    rises steadily
    A higher-degree family includes all lower-degree curves.
    stays constant
    Extra coefficients give least squares more freedom to fit.
    never increases, reaching 0 at degree 15
    Nested models: the minimum can only go down, and 16 distinct points are interpolated exactly at degree 15.

    Ridge regression: least squares with a brake on the weights

    Ridge regression is least squares plus a penalty $\lambda\norm{\w}^2$ on the size of the weights, which shrinks them towards zero and trades a little bias for a big drop in variance.

    Three GATE questions so far: 2026 Q37 (what the regulariser does, 2 marks), 2026 Q55 (compute a regularised loss, 2 marks) and sample Q12 (bias and variance as λ grows). The closed form $(X^\top X + \lambda I)^{-1}X^\top \y$ is fair game for a NAT.

    It’s like a coach who lets a batter adjust their technique only at a cost: small, well-justified changes get made, but wild swings to suit one bad session don’t.

    Where it shows up in GATE DA

    A conceptual MCQ and a one-instance loss computation, both in 2026; the sample paper’s bias–variance question.

    2026 Q37 · statements about ridge2026 Q55 · regularised loss for one instanceSample Q12 · bias and variance as λ grows
    Heat: rising, 2 questions in 2026

    Recall from Part 1: linear regression predicts $\hat y = \w^\top \x$ (a weighted sum of the features, often with an intercept) and least squares chooses $\w$ to minimise the sum of squared errors $\norm{\y - X\w}^2$, giving the normal equations $\w = (X^\top X)^{-1}X^\top \y$. Here $X$ is the data matrix, one row per training example and one column per feature.

    The Hyderabad Hyperplanes’ analyst has 12 matches and 9 features (powers of the innings stage, as in the last chapter). Least squares fits those 12 matches very closely, but look at the weights: values in the hundreds, of opposite signs, cancelling each other. Huge weights are the fingerprint of overfitting: a tiny change in one input makes the prediction swing a lot. Worse, when there are more features than examples (or two features are nearly copies of each other), $X^\top X$ is singular, its inverse doesn’t exist, and least squares has no unique answer at all.

    The fix is to charge the model for large weights. Minimise “error + λ × size of the weights”. Now a weight is allowed to be large only if it reduces the error by enough to pay for itself.

    For a penalty strength $\lambda \ge 0$ (the regularisation coefficient, a hyperparameter), ridge regression chooses $$\hat\w_\lambda = \argmin_{\w}\ \underbrace{\norm{\y - X\w}^2}_{\text{fit to data}} + \underbrace{\lambda\norm{\w}^2}_{\text{penalty}}, \qquad \norm{\w}^2 = w_1^2 + \dots + w_d^2.$$ $\norm{\w}$ is the L2 norm (ordinary length) of the weight vector, so the penalty is the squared L2 norm. The penalty is also called the regulariser; adding one is called regularisation. The intercept is normally left out of the penalty.

    Setting the gradient $-2X^\top(\y - X\w) + 2\lambda\w$ to $\0$ gives $(X^\top X + \lambda I)\w = X^\top\y$, so $$\hat\w_\lambda = (X^\top X + \lambda I)^{-1}X^\top \y.$$ For every $\lambda \gt 0$ the matrix $X^\top X + \lambda I$ is invertible (its eigenvalues are those of $X^\top X$, which are $\ge 0$, plus $\lambda$), even when there are more features than examples. With one feature and no intercept this is $\hat w = \dfrac{\sum x_i y_i}{\sum x_i^2 + \lambda}$: the least-squares slope with a bigger denominator.

    Recall from Linear algebra that adding $\lambda I$ to a symmetric matrix adds $\lambda$ to every eigenvalue: that is why the ridge matrix can always be inverted. And when the features are orthonormal ($X^\top X = I$), the formula collapses to $\hat\w_\lambda = \dfrac{1}{1+\lambda}\,\hat\w_{\text{LS}}$: every least-squares weight is shrunk by the same factor. That is why ridge is called a shrinkage method.

    What λ does

    • $\lambda = 0$: ordinary least squares. Lowest training error, highest variance.
    • λ larger: weights pulled towards 0, curve smoother; training error goes up (never down), variance goes down, bias goes up.
    • $\lambda \to \infty$: all penalised weights go to 0 and the model predicts a constant (the mean of $y$, if the intercept is unpenalised). Maximum bias, zero variance.

    So λ slides you along the bias–variance curve of the last chapter, and the best λ is somewhere in the middle. Choosing it is the job of cross-validation (next chapter), never of the test set.

    Try it

    The same twelve overs as before, now fitted with a degree-9 polynomial (10 weights). With λ near 0 the curve wiggles through the points and the bars (the nine non-intercept weights) are enormous. Drag λ up and watch the bars collapse and the curve calm down. Keep an eye on the two errors: training MSE only rises, while test MSE first falls and then rises again once λ is so large that the curve goes flat.

    Ridge = L2 penalty $\lambda\sum w_j^2$: shrinks all weights smoothly, rarely makes any exactly 0, has a closed form. Lasso = L1 penalty $\lambda\sum |w_j|$: can set weights exactly to 0 (feature selection), no closed form in general. Both: bias up, variance down as λ grows. Neither cares about the sign of a weight, only its size.

    Careful: the penalty depends on the units of each feature. Measure a feature in centimetres instead of metres and its weight becomes 100 times smaller, so it is penalised far less. Standardise features (subtract the mean, divide by the standard deviation) before using ridge.
    GATE DA 2026 · Q55 · NAT · 2 marks

    Consider that Linear Ridge Regression is being used to learn a prediction function $y_{pred} = w^T x$, where $w, x \in \R^2$ and Mean Absolute Error (MAE) is used to measure the prediction error. A weight of 0.20 is associated with the regularizer.

    At an intermediate step of the training process, assume that the parameter $w = [-3.00,\ 4.00]^T$. In the next step, for the input $x = [1.00,\ 2.00]^T$, the predicted value of $y$ is noted. Let the relation between $x = [x_1,\ x_2]^T$ and the true value of $y$ be $y_{true} = x_1 + x_2$.

    The value of the overall regularized loss function for this instance is _______ . (Rounded off to two decimal places)

    1. Prediction: $y_{pred} = w^\top x = (-3)(1) + (4)(2) = 5$.

      A linear model is a dot product of weights and features.

    2. Truth: $y_{true} = 1 + 2 = 3$.

      Read straight from the given relation.

    3. Data loss (MAE for one instance): $|5 - 3| = 2$.

      The question says the prediction error is measured by mean absolute error; for a single instance the mean is just that one absolute error. The data term need not be squared error: “ridge” refers to the penalty.

    4. Ridge penalty: $\lambda\norm{w}^2 = 0.20 \times \big((-3)^2 + 4^2\big) = 0.20 \times 25 = 5$.

      Ridge uses the squared L2 norm. Using the unsquared norm, $0.2 \times 5 = 1$, gives 3, outside the key; using L1, $0.2 \times 7$, is lasso.

    5. Total: $2 + 5 =$ 7.00. Official key: 6.90 to 7.10.

      Regularised loss = data loss + penalty. The penalty here is larger than the error itself, a sign these weights are big.

    The Kalinga Kernels fit runs ($y$) against one standardised feature ($x$), with no intercept, on three overs: $x = (1, 2, 3)$, $y = (2, 3, 5)$. Compare the least-squares slope with the ridge slope for $\lambda = 1$.

    1. $\sum x_i y_i = 2 + 6 + 15 = 23$ and $\sum x_i^2 = 1 + 4 + 9 = 14$.

      With one feature, $X^\top X$ and $X^\top \y$ are just these two sums.

    2. Least squares: $\hat w = 23/14 \approx 1.643$.

      The normal equation from Part 1 with a 1×1 matrix.

    3. Ridge: $\hat w = \dfrac{23}{14 + 1} = \dfrac{23}{15} \approx$ 1.533.

      $\lambda$ is added to the denominator, so the slope moves towards 0. A larger λ shrinks it more; it never flips its sign.

    With no intercept, data matrix $X = \begin{bmatrix}1 & 1\\ 1 & -1\end{bmatrix}$ and labels $\y = (3, 1)$, compute the ridge solution for $\lambda = 2$.

    Compute $X^\top X$ first; it is a multiple of $I$, so adding $\lambda I$ and inverting is easy.

    $X^\top X = \begin{bmatrix}2 & 0\\ 0 & 2\end{bmatrix}$ and $X^\top\y = (3 + 1,\ 3 - 1) = (4, 2)$.

    $X^\top X + 2I = 4I$, so $\hat\w = \tfrac14(4, 2) = (1, 0.5)$.

    Least squares would give $\tfrac12(4, 2) = (2, 1)$: ridge halved both weights, because $X^\top X$ is diagonal and the shrink factor is $\frac{2}{2 + \lambda} = \frac12$.

    One feature, no intercept: $\sum x_i^2 = 30$ and $\sum x_i y_i = 120$. The ridge slope with penalty λ is half of the least-squares slope. Find λ, then give the ridge slope when λ is doubled. (Round off to two decimal places.)

    Least squares gives $120/30$. Ridge gives $120/(30 + \lambda)$.

    Least squares: $120/30 = 4$. Half of it is 2, so $120/(30 + \lambda) = 2$ and $\lambda = 30$.

    So λ = 30. Doubling λ to 60: $\hat w = 120/90 \approx$ 1.33. Note that doubling λ did not halve the slope again: the shrink factor is $\frac{30}{30 + \lambda}$, not linear in λ.

    GATE DA 2024 sample paper · Q12 · MCQ · 1 mark

    Increasing the regularisation coefficient value in ridge regression will typically

    i) Increase the bias of the resulting model.
    ii) Decrease the bias of the resulting model.
    iii) Increase the variance of the resulting model.
    iv) Decrease the variance of the resulting model.

    Which of the following statements are correct?

    1. i and iii only
    2. i and iv only
    3. ii and iii only
    4. ii and iv only

    A larger λ pushes the weights towards 0. Is that model more rigid or more flexible?

    A larger coefficient shrinks the weights harder, making the model stiffer: it can follow the true pattern less well (bias up, i) and reacts less to the particular sample (variance down, iv). Answer (B). (Sample paper, no official key; this is our answer.)

    GATE DA 2026 · Q37 · MCQ · 2 marks

    Which of the following statements is true for Ridge Regression?

    1. The regularizer in the objective function of Ridge Regression is used to guard against scenarios where the model works well for the test data, but poorly for the training data.
    2. The regularizer of Ridge Regression uses $L1$ norm.
    3. Ridge Regression aims to reduce the number of parameters that have negative values.
    4. The regularizer of Ridge Regression may increase the bias of the model, but it helps in reducing the variance in predictions.

    Check each option against the definition: which norm, which failure mode (good on training, poor on test, or the reverse?), and does the sign of a weight matter?

    (A) has the failure mode backwards: regularisation guards against working well on training data but poorly on test data (overfitting). (B) Ridge uses the squared L2 norm; L1 is lasso. (C) The penalty $w_j^2$ is the same for $w_j$ and $-w_j$, so signs are irrelevant. (D) is the bias–variance trade-off: correct. Official key: D.

    No intercept. Training data: $\x_1 = (1, 0)$, $y_1 = 1$; $\x_2 = (0, 1)$, $y_2 = 1$; $\x_3 = (1, 1)$, $y_3 = 2$. With $\lambda = 1$, find the ridge weight $w_1$ and the value of the ridge objective $J(\w) = \norm{\y - X\w}^2 + \lambda\norm{\w}^2$ at the solution.

    Build $X^\top X$ and $X^\top \y$, add $\lambda I$, and solve the 2×2 system. Symmetry suggests $w_1 = w_2$.

    $X^\top X = \begin{bmatrix}2 & 1\\ 1 & 2\end{bmatrix}$, $X^\top \y = (1 + 2,\ 1 + 2) = (3, 3)$.

    $(X^\top X + I)\w = \begin{bmatrix}3 & 1\\ 1 & 3\end{bmatrix}\w = (3, 3)$. By symmetry $w_1 = w_2 = w$ with $4w = 3$, so $w_1 =$ 0.75.

    Predictions: 0.75, 0.75, 1.5; residuals 0.25, 0.25, 0.5; squared error $0.0625 + 0.0625 + 0.25 = 0.375$. Penalty $1 \times (0.75^2 + 0.75^2) = 1.125$. So $J =$ 1.5.

    Least squares gives $\w = (1, 1)$, a perfect fit, but under the ridge objective it scores $0 + 1\times(1 + 1) = 2$; ridge finds a lower total, 1.5, by accepting some error. A common slip is forgetting $\lambda I$ and getting $w_1 = 1$.

    A ridge model with an unpenalised intercept is trained on the Bengaluru Backprops’ data, whose labels have mean 160. As $\lambda \to \infty$, the model’s prediction for any input tends to

    1. 160, the mean of the training labels
    2. 0
    3. the least-squares prediction
    4. it does not converge, because the weights blow up

    Which parameters feel the penalty? Once they are forced to 0, what is the best constant prediction under squared error?

    An infinite penalty drives every penalised weight to 0, leaving $\hat y = b$ for every input. The intercept $b$ is free, so least squares chooses the constant that minimises $\sum (y_i - b)^2$, which is the mean: (A).

    (B) would be right only if the intercept were penalised too (or the labels centred at 0). (C) is the $\lambda = 0$ end. (D) reverses the effect of the penalty.

    Which statements about ridge regression with $\lambda \gt 0$ are true? (Select all that apply.)

    (A) $X^\top X + \lambda I$ is invertible even when there are more features than training examples.
    (B) For a large enough λ, ridge sets some weights exactly to 0 while keeping others non-zero.
    (C) Multiplying one feature’s values by 10 (and refitting) can change the model’s predictions.
    (D) As λ increases, the training error never decreases.

    (A): eigenvalues. (B): that’s the other penalty. (C): what happens to that feature’s weight, and to its penalty? (D): ridge at a smaller λ is free to choose any weights.

    (A) True: $X^\top X$ has eigenvalues $\ge 0$; adding $\lambda I$ makes them all $\ge \lambda \gt 0$.

    (B) False: ridge shrinks smoothly; exact zeros (sparsity) are a feature of the L1 penalty (lasso).

    (C) True: least squares would simply divide that weight by 10, giving the same predictions, but ridge penalises the smaller weight less, so the balance shifts and predictions change. Hence “standardise first”.

    (D) True: a larger λ puts more weight on the penalty, so the optimum trades away training fit; the training error is non-decreasing in λ.

    Answer: A, C, D.

    • Standardise features before ridge, and leave the intercept unpenalised.
    • Remember the penalty is $\lambda\sum w_j^2$, squared L2, and it ignores signs.
    • Choose λ by cross-validation on the training data.
    • Saying ridge “reduces bias”: it increases bias and reduces variance.
    • Mixing up ridge (L2, shrinks) with lasso (L1, zeros out weights).
    • Forgetting to add $\lambda I$ (not $\lambda$ to every entry) to $X^\top X$.
    1. Ridge minimises ‖y − Xw‖² + λ‖w‖²; closed form w = (XᵀX + λI)⁻¹Xᵀy, invertible for any λ > 0.
    2. λ shrinks the weights towards 0: training error up, bias up, variance down. λ = 0 is least squares; λ → ∞ predicts a constant.
    3. Regularised loss = data loss + λ × (sum of squared weights). Ridge is L2; lasso is L1 and can zero out weights.

    A model’s weights are all in the hundreds and of alternating signs, and it predicts new data badly. Adding a penalty on the sum of squared weights will most likely

    make the weights even larger
    The penalty charges for large weights. Which way will the optimiser push them?
    shrink the weights and improve predictions on new data
    Huge cancelling weights are a sign of overfitting; shrinking them cuts variance.
    set exactly half of the weights to zero
    The squared penalty shrinks smoothly; exact zeros come from an L1 penalty.
    lower the training error
    The penalty competes with the fit, so training error can only stay the same or rise.

    With $X^\top X = \begin{bmatrix}4 & 0\\ 0 & 1\end{bmatrix}$ and $\lambda = 1$, the ridge weights equal the least-squares weights multiplied by

    $\tfrac12$ for both
    The shrink factor depends on each diagonal entry: $\frac{s}{s+\lambda}$.
    $\tfrac15$ and $\tfrac12$
    Close: the factor is $\frac{s}{s+\lambda}$, not $\frac{1}{s+\lambda}$.
    1 for both
    That would be $\lambda = 0$.
    $\tfrac45$ and $\tfrac12$
    With diagonal $X^\top X$, $w_j^{\text{ridge}} = \frac{s_j}{s_j + \lambda} w_j^{\text{LS}}$: $\frac{4}{5}$ and $\frac{1}{2}$. Directions with little data are shrunk most.

    Which is the ridge penalty for $\w = (2, -1, 0)$ with $\lambda = 0.5$?

    0.5
    That is λ times the sum of the weights, which lets signs cancel.
    1.5
    That is the L1 (lasso) penalty, $0.5 \times 3$.
    2.5
    $0.5 \times (4 + 1 + 0) = 2.5$.
    1.118
    That uses the unsquared norm $\sqrt5$.

    Cross-validation: choosing settings without peeking at the test set

    Cross-validation estimates how well a model will do on new data by repeatedly hiding part of the training data, training on the rest, and testing on the hidden part.

    GATE asks you to count the splits (2026 Q12: LOOCV on 900 samples) and to pick the right design for imbalanced data (sample Q11: stratified CV with area under the ROC curve). It is also how λ in ridge and the degree in polynomial regression are chosen.

    It’s like a coach picking a batting order by trying each candidate order in practice matches against different sets of their own bowlers, rather than testing it in the final and then claiming they knew all along.

    Where it shows up in GATE DA

    Counting folds and training-set sizes; matching the evaluation design to the data.

    2026 Q12 · number of LOOCV splitsSample Q11 · imbalanced data: stratified CV and AUC
    Heat: most years, 1 mark

    Last chapter left a problem. Ridge needs a value of λ; polynomial regression needs a degree. These are hyperparameters: settings fixed before training, which least squares does not learn. How do we choose them?

    • Not by training error: it always prefers the most flexible setting (λ = 0, highest degree).
    • Not by test error either. The test set is our one honest estimate of performance on new data. If we try twenty values of λ and keep the one with the lowest test error, that test error is now optimistic, because we picked it for being low. The test set has quietly become part of training. This is called data leakage.

    The answer is to carve a validation set out of the training data: train on the rest, measure error on the validation part, and choose the hyperparameter with the lowest validation error. The test set stays locked away until the very end.

    • Hold-out validation: split the training data once, for example 80% train / 20% validation. Cheap, but the estimate depends on which points happened to land in the validation part, and 20% of the data is never used for training.
    • k-fold cross-validation: split the training data into $k$ roughly equal parts called folds. For each $i = 1, \dots, k$: train on the other $k - 1$ folds, compute the error on fold $i$. The CV estimate is the average of the $k$ errors. Every point is used for validation exactly once and for training $k - 1$ times. Each model trains on about $\frac{k-1}{k}n$ points; common choices are $k = 5$ or $10$.
    • Leave-one-out cross-validation (LOOCV): $k$-fold with $k = n$. Each fold is a single point, so there are $n$ splits, $n$ models, each trained on $n - 1$ points.
    • Stratified k-fold: the folds are formed so that each has (roughly) the same class proportions as the whole data set. Essential when one class is rare.
    1. Set the test set aside. Split the remaining training data into $k$ folds.
    2. For each candidate value (each λ, or each degree): train $k$ times, each time leaving one fold out, and average the $k$ validation errors.
    3. Pick the candidate with the lowest average CV error.
    4. Retrain with that value on all the training data.
    5. Evaluate once on the test set and report that number.

    Cost: (number of candidates) × $k$ training runs, plus one final refit.

    Try it

    Twenty training samples, four of them positive (dots). Each row is one round of cross-validation: the red squares are that round’s validation fold, the blue ones are used for training. With plain k-fold, press “Reshuffle data” a few times and look at the readout: some folds can end up with no positive example at all, so recall on that fold is undefined. Switch to “Stratified k-fold” and every fold gets its share of positives. “Leave-one-out” makes 20 rounds of one sample each.

    Try it

    Thirty overs, polynomials of degree 0 to 9. The red curve is the k-fold CV error for each degree, computed from the training data only; the green curve is the true error on 200 fresh overs, which a real analyst wouldn’t have. Notice that the degree with the lowest CV error (circled) usually lands at or near the degree that is truly best, while training error (dashed) would always pick degree 9. Compare k = 2 with LOOCV: with k = 2 each model trains on only 15 points, so the CV errors run higher.

    Choosing k

    Small $k$ (say 2) is cheap, but each model trains on only half the data, so it is weaker than the final model and the CV error overestimates the true error (pessimistic bias). Large $k$ (up to LOOCV) trains on almost all the data, so that bias is small, but it costs $n$ fits, and the $n$ training sets overlap almost completely, which makes the estimate noisy. $k = 5$ or $10$ is the usual compromise. LOOCV has one more property: it involves no random split, so running it twice gives the same answer.

    Imbalanced classes

    Suppose only 5% of a data set is positive (say, matches decided by a super over). A classifier that always says “negative” scores 95% accuracy while being useless. Two fixes, which together answer sample Q11: stratify the folds so each one has about 5% positives, and use a measure that isn’t fooled by the majority class, such as the area under the ROC curve (AUC). The ROC curve plots the true-positive rate against the false-positive rate as the classifier’s threshold varies; AUC is the probability that a random positive is scored above a random negative, so always-negative scores only 0.5.

    With $n$ samples available for training/validation: $k$-fold makes $k$ splits, each training on $n - n/k$ points and validating on $n/k$. LOOCV makes $n$ splits, training on $n - 1$. Always subtract the test set first: CV runs only on what is left.

    GATE DA 2026 · Q12 · MCQ · 1 mark

    Consider that you are training a classifier for a 10-class classification problem. Each input is represented as a 512-dimensional vector. There are 1000 samples, out of which first 100 will be used for testing. Let Leave-One-Out-Cross-Validation (LOOCV) be used for selection of the classifier model before testing. Which of the following options is the correct number of validation splits that will be generated?

    1. 10
    2. 512
    3. 900
    4. 1000
    1. Remove the test set: $1000 - 100 = 900$ samples remain for model selection.

      The test samples must not be touched during model selection, so cross-validation only sees the other 900.

    2. LOOCV is $k$-fold with $k = n$: each split leaves out exactly one of the $n = 900$ samples.

      One split per sample, each sample being the validation set once.

    3. Number of splits $= 900$: answer (C). Official key: C.

      The distractors use other numbers in the question: 10 is the number of classes, 512 the input dimension, 1000 includes the test set. None of them changes the count of samples.

    The Nagpur Neural Nets have 1200 labelled matches after setting the test set aside. They compare 4 values of λ with 6-fold CV. How large is each training and validation split, and how many models are trained in total, including the final refit?

    1. Fold size $= 1200/6 = 200$, so each round validates on 200 and trains on $1200 - 200 = 1000$.

      One fold is held out, the other five are used for training.

    2. Per λ: 6 models. For 4 values: $4 \times 6 = 24$.

      Each candidate needs its own full round of $k$ fits.

    3. Plus one refit of the winner on all 1200: 25 models.

      The CV models were only for choosing λ; the deployed model uses every training example.

    A 5-fold cross-validation gives validation errors 0.20, 0.25, 0.15, 0.30 and 0.10 on five equal-sized folds. What is the CV estimate of the error?

    Equal-sized folds, so a plain average.

    $(0.20 + 0.25 + 0.15 + 0.30 + 0.10)/5 = 1.00/5 = 0.20$.

    LOOCV is run on a training set of 50 matches. How many models are trained, and on how many points is each trained?

    Each split leaves out exactly one point.

    One model per left-out point: 50 models, each trained on $50 - 1 = 49$ points.

    A data set of 200 overs has 40 overs with a wicket (positive) and 160 without. Stratified 5-fold CV is used. How many positives are in each validation fold, and how many in each training split?

    Stratification keeps the 20% positive rate in every fold of 40.

    Each fold has $200/5 = 40$ overs, 20% positive: $8$ positives. Each training split is the other four folds: $40 - 8 = 32$ positives (out of 160 overs).

    GATE DA 2024 sample paper · Q11 · MCQ · 1 mark

    A binary classification dataset contains only 5% of positive instances. Which one of the following experimental design and performance measures is most suited for measuring the generalizability of a classifier trained on this dataset?

    1. fixed training and test sets, accuracy
    2. fixed training and test sets, area under the ROC curve
    3. stratified cross-validation, accuracy
    4. stratified cross-validation, area under the ROC curve

    Two separate choices: a design that uses the data well and keeps the 5% in every fold, and a measure that a “always negative” classifier can’t game.

    Accuracy is misleading at 5% positives: always predicting negative gives 95%. AUC is unaffected by that. Stratified cross-validation uses all the data for evaluation and keeps the 5% rate in each fold, giving a more reliable estimate of generalisation than one fixed split. Answer (D). (Sample paper, no official key; this is our answer.)

    The “model” predicts every label as the mean of its training labels. Training labels: $y = (2, 4, 6, 8)$. Compute the LOOCV mean squared error. (Round off to two decimal places.)

    Leave out each point in turn, predict it by the mean of the other three, square the error, then average the four squared errors. Shortcut: for the mean predictor the left-out error is $\frac{n}{n-1}(y_i - \bar y)$.

    Leave out 2: mean of (4, 6, 8) is 6, error $(2 - 6)^2 = 16$.

    Leave out 4: mean of (2, 6, 8) is $16/3$, error $(4 - 16/3)^2 = 16/9$.

    Leave out 6: mean of (2, 4, 8) is $14/3$, error $(6 - 14/3)^2 = 16/9$.

    Leave out 8: mean of (2, 4, 6) is 4, error 16.

    Average: $\frac{16 + 16/9 + 16/9 + 16}{4} = \frac{320/9}{4} = \frac{80}{9} \approx$ 8.89.

    Check with the shortcut: $\bar y = 5$, residuals $-3, -1, 1, 3$, scaled by $\frac43$: $-4, -\frac43, \frac43, 4$, squares averaging $80/9$. The tempting wrong answer is the training MSE, $(9 + 1 + 1 + 9)/4 = 5$, which is smaller because each point helped compute its own prediction.

    The Hyderabad Hyperplanes have 300 matches and 5,000 candidate features. Which procedure gives an honest estimate of how their final model will do on next season’s matches?

    1. Use all 300 matches to pick the 20 features most correlated with the label, then run 10-fold CV on those 20 features and report the CV error.
    2. Set 60 matches aside as a test set. On the other 240, choose λ (and do any feature selection inside each training fold) by 10-fold CV, refit on all 240, and report the error on the 60.
    3. Split 240/60, try 50 values of λ, and report the lowest of the 50 test errors.
    4. Train on all 300 matches and report the training error, since it uses the most data.

    For each option, ask: did the number that gets reported ever influence a choice that was made?

    (B) keeps the 60 test matches completely unused until the single final evaluation, and does every data-driven choice inside the training folds. Answer (B).

    (A) is the classic trap: the features were chosen using the labels of every match, including the ones later used for validation, so the CV error is badly optimistic (with 5,000 features, some correlate with the label by pure chance). (C) picks λ by test error, so the reported minimum is biased downwards. (D) reports training error, which says nothing about overfitting.

    A data set of $n$ examples is used for cross-validation. Which statements are true? (Select all that apply.)

    (A) LOOCV trains $n$ models.
    (B) Repeating LOOCV on the same data gives exactly the same estimate.
    (C) In 10-fold CV, each model is trained on 90% of the data.
    (D) Increasing $k$ in $k$-fold CV makes each training set smaller.

    Each fold has $n/k$ points and the training set is everything else.

    (A) True: one model per left-out example.

    (B) True: there is only one way to leave out one point at a time, so there is no randomness in the splits (assuming a deterministic training algorithm).

    (C) True: one tenth is held out.

    (D) False: the training set has $n - n/k$ points, which grows with $k$. More folds means smaller validation folds and larger training sets.

    Answer: A, B, C.

    • Lock the test set away first; run CV only on the rest.
    • Do every data-driven step (scaling, feature selection, choosing λ) inside the training folds.
    • Stratify the folds and use a measure such as AUC, precision or recall when one class is rare.
    • Counting the test samples in the number of LOOCV splits.
    • Choosing a hyperparameter by its test error, then reporting that same test error.
    • Forgetting the final refit on all the training data after choosing the hyperparameter.
    1. Validation data (hold-out or k-fold) chooses hyperparameters; the test set is used once, at the end.
    2. k-fold: k models, each trained on (k−1)/k of the data, error averaged. LOOCV: k = n, so n splits of n − 1 training points each.
    3. For rare classes, use stratified folds and a measure such as AUC, not plain accuracy.

    An analyst tries 30 values of λ and keeps the one with the lowest error on the test set, then reports that error. The reported error is most likely

    an unbiased estimate of future error
    Ask whether the test set influenced a choice. If so, can it still be impartial?
    too optimistic
    The minimum of 30 noisy test errors is lower than the true error of the chosen model: the test set has leaked into model selection.
    too pessimistic
    Taking a minimum pushes the reported number down, not up.
    exactly equal to the training error
    The test set is separate from training; the issue is how it was used.

    5-fold CV on 500 examples trains each model on how many examples?

    100
    That is the size of each validation fold.
    500
    One fold is always held out.
    400
    $500 - 500/5 = 400$.
    499
    That would be leave-one-out.

    Why use stratified folds?

    To make the folds different sizes
    Folds stay (roughly) equal in size; something else is matched.
    To reduce the number of models trained
    Stratified k-fold still trains k models.
    To make sure the test set is never used
    That is good practice, but it isn’t what stratification does.
    So each fold keeps the class proportions of the whole data set
    Without it, a rare class can be missing from some folds entirely.

    Training MSE 5.8, test MSE 6.0, noise variance about 1. The model is most likely

    overfitting
    Overfitting shows a large gap between training and test error. Is there one here?
    underfitting (high bias)
    Both errors are similar and far above the noise floor: the model is too simple.
    just right
    Errors near 6 against a noise floor of 1 leave a lot of reducible error.
    impossible to judge without more data
    The two errors and the noise level are enough to diagnose it.

    Increasing λ in ridge regression

    decreases bias and increases variance
    That is the effect of making the model more flexible. Is a heavier penalty more or less flexible?
    sets weights exactly to zero
    That is a property of the L1 penalty.
    increases bias and decreases variance
    Stronger shrinkage makes the model stiffer.
    leaves the training error unchanged
    The penalty trades away training fit.

    Least squares fails to give a unique answer when $X^\top X$ is singular. Ridge fixes this because

    $X^\top X + \lambda I$ has all eigenvalues at least $\lambda \gt 0$, so it is invertible
    Adding $\lambda I$ shifts every eigenvalue up by λ.
    it removes the singular features
    Ridge keeps every feature; it changes the matrix being inverted.
    it uses gradient descent instead of an inverse
    Ridge has a closed form; the change is inside it.
    it adds λ to every entry of $X^\top X$
    Only the diagonal gets λ.

    Of 600 samples, 150 are reserved for testing and LOOCV is run on the rest. How many validation splits are there?

    600
    The test samples are never used in cross-validation.
    150
    That is the test set itself.
    449
    That is the size of each LOOCV training set.
    450
    $600 - 150 = 450$, one split per remaining sample.

    The right way to choose λ for ridge regression is to

    pick the λ with the lowest training error
    That always picks λ = 0, plain least squares.
    pick the λ with the lowest test error
    Then the test error is no longer an honest estimate.
    pick the λ with the lowest cross-validation error on the training data
    Then refit on all the training data and evaluate once on the test set.
    always use λ = 1
    The best λ depends on the data, its scale and the noise.

    So far the module has predicted numbers. This part predicts categories: win or loss, spam or not, red or green. You’ll meet the three classic ways to draw a line between classes: logistic regression (learn the probability of a class directly), naive Bayes (count how each class tends to look, then apply Bayes’ theorem) and Fisher’s linear discriminant (find the one direction that pulls the classes apart). Between them they account for a GATE DA question or two every year.

    You need: features, labels and accuracy from Chapter 1.1; the score $w^\top x + b$ from linear regression in Chapter 1.2; the L2 penalty from Chapter 2.2 (briefly); Bayes’ theorem from Probability; dot products and eigenvectors from Linear algebra.

    Logistic regression and the perceptron: drawing a line between classes

    Logistic regression turns a straight-line score $w^\top x + b$ into a probability between 0 and 1, and classifies by which side of a line (or plane) a point falls on.

    GATE DA asked about the perceptron update in 2025 Q22 and about “discriminative versus generative” models in 2024 Q18. The same score-and-sign idea returns in SVMs and neural networks later in this module.

    It’s like a selector’s rule of thumb: add up points for good form and fitness, subtract points for injury, and pick the player if the total is above zero. The rule is a weighted sum; the line where the total is exactly zero is where the decision flips.

    Where it shows up in GATE DA

    The perceptron update rule, the sigmoid and log-odds, and recognising logistic regression as a discriminative model.

    2025 Q22 · perceptron update2024 Q18 · generative or discriminative?2025 Q53, 2024 Q17 · linear classifiers (SVM, Part 4)
    Heat: most years, 1 mark each

    First, what is a classifier?

    A classifier is a rule that takes the features of an example and returns a class label from a fixed, small list. Recall from Chapter 1.1 that a feature is a measured input (runs scored, wickets in hand) and a label is the answer we want to predict. In regression the label is a number; in classification it is a category. Tiny example: given the toss result and the pitch type, predict “Win” or “Loss” for the Kalinga Kernels.

    When there are just two features, every example is a point in the plane. A classifier then colours the whole plane: every location gets a predicted label. The curve where the colour changes is the decision boundary. Points on one side are predicted one class, points on the other side the other class.

    The simplest boundary is a straight line. A linear classifier computes a score $z = w^\top x + b = w_1x_1 + w_2x_2 + \dots + b$ (exactly the formula from linear regression) and predicts one class when $z \gt 0$ and the other when $z \le 0$. The numbers $w$ (the weights) and $b$ (the bias) are the model’s parameters: the values learned from data.

    The boundary is the set where $z = 0$. In two dimensions that’s a line; in three, a plane; in $d$ dimensions it is called a hyperplane (a flat surface one dimension lower than the space). Recall from Linear algebra that $w^\top x = 0$ means "$x$ is perpendicular to $w$": so $w$ points straight across the boundary, towards the side predicted positive.

    A DPL story

    The Hyderabad Hyperplanes’ analyst records two numbers at the halfway point of each chase: $x_1$, how far the team is ahead of the required run rate, and $x_2$, a wickets-in-hand score. Each past chase is labelled 1 (won) or 0 (lost). They want more than a yes/no verdict: they want “we’re 80% likely to win from here”. That’s what logistic regression adds.

    The sigmoid (logistic) function squashes any real number into $(0, 1)$: $$\sigma(z) = \frac{1}{1 + e^{-z}}.$$ It has $\sigma(0) = 0.5$, $\sigma(z) \to 1$ as $z \to \infty$, $\sigma(z) \to 0$ as $z \to -\infty$, and $\sigma(-z) = 1 - \sigma(z)$.

    The odds of an event with probability $p$ are $\frac{p}{1-p}$ (probability 0.8 means odds of 4 to 1). The log-odds (or logit) is $\ln\frac{p}{1-p}$; it is the inverse of the sigmoid: if $p = \sigma(z)$ then $\ln\frac{p}{1-p} = z$.

    For features $x$ and a label $y \in \{0, 1\}$, logistic regression models $$P(y = 1\mid x) = \sigma(w^\top x + b), \qquad\text{equivalently}\qquad \ln\frac{P(y=1\mid x)}{P(y=0\mid x)} = w^\top x + b.$$ In words: the log-odds is a linear function of the features. It predicts class 1 when $P(y=1\mid x) \ge 0.5$, which happens exactly when $w^\top x + b \ge 0$. So the decision boundary is the hyperplane $w^\top x + b = 0$, and logistic regression is a linear classifier.

    Despite the name, logistic regression is a classification method; “regression” survives because it fits a linear function (to the log-odds).

    Why not just run ordinary linear regression on 0/1 labels? Its predictions are not probabilities (they can be −0.3 or 1.4), and a few far-away but obvious examples drag the line and move the boundary. The sigmoid fixes both: it saturates, so an obvious example far from the boundary has probability near 0 or 1 and little pull.

    How is it trained? Cross-entropy loss

    A loss measures how bad one prediction is; training picks the parameters with the smallest average loss (recall Chapter 1.1). For a probability prediction $p = \sigma(w^\top x + b)$ the natural loss asks: how much probability did the model give to what actually happened? If $y = 1$, that’s $p$; if $y = 0$, it’s $1 - p$. Taking minus the logarithm turns “high probability is good” into “low loss is good”.

    For one example, $$\ell = -\big[\,y\ln p + (1-y)\ln(1-p)\,\big], \qquad p = \sigma(w^\top x + b).$$ If $y = 1$ this is $-\ln p$; if $y = 0$ it is $-\ln(1-p)$. Training minimises the average of $\ell$ over the training set. This is the same as maximising the likelihood of the labels (the probability the model assigns to the observed data), because $P(y\mid x) = p^y(1-p)^{1-y}$.

    The loss is convex in $(w, b)$ and its gradient is strikingly simple: $\dfrac{\partial \ell}{\partial w} = (p - y)\,x$ and $\dfrac{\partial \ell}{\partial b} = p - y$ (“prediction minus truth, times input”). There is no closed-form solution like the normal equations, so it is trained by gradient descent (Chapter 5.2).

    Careful: a confident wrong answer is punished hard. Predicting $p = 0.99$ for a match that was lost costs $-\ln 0.01 \approx 4.6$, while $p = 0.6$ for a match that was won costs only $-\ln 0.6 \approx 0.51$.
    Go deeper: where $(p - y)x$ comes from

    Write $z = w^\top x + b$ and $p = \sigma(z)$. First, $\sigma'(z) = \sigma(z)(1 - \sigma(z)) = p(1-p)$. Then $\dfrac{\partial \ell}{\partial p} = -\dfrac{y}{p} + \dfrac{1-y}{1-p} = \dfrac{p - y}{p(1-p)}$. The chain rule gives $\dfrac{\partial \ell}{\partial z} = \dfrac{p-y}{p(1-p)}\cdot p(1-p) = p - y$, and $\dfrac{\partial z}{\partial w} = x$. With more than two classes the sigmoid becomes the softmax $P(y = k\mid x) = e^{z_k}/\sum_j e^{z_j}$, one score $z_k = w_k^\top x + b_k$ per class, and the same “prediction minus truth” gradient appears.

    Try it

    Circles are chases the Hyperplanes won, squares are losses. Move the sliders to place the boundary (solid line); the arrow $w$ points to the “win” side and the shading shows the predicted probability. Then press Gradient step a few times and watch the loss fall. Notice two things: scaling up $w$ and $b$ together doesn’t move the line but makes the probabilities more extreme (the dashed $p = 0.1$ and $0.9$ lines close in), and the two mislabelled-looking points stop the loss from reaching zero. Tap a point to see its own loss.

    The perceptron: the original linear classifier

    Before logistic regression became standard, Rosenblatt’s perceptron (1958) learned a linear classifier with an even simpler rule. Labels are $y \in \{+1, -1\}$ and the prediction is $\operatorname{sign}(w^\top x + b)$. Go through the training points one at a time. If the current point is classified correctly, do nothing. If it’s wrong, nudge the weights towards it.

    1. Start with $w = 0$, $b = 0$.
    2. For each training example $(x_n, y_n)$ in turn: if $\operatorname{sign}(w^\top x_n + b) \ne y_n$ (a mistake), update $$w \leftarrow w + y_n x_n, \qquad b \leftarrow b + y_n.$$
    3. Repeat passes over the data until a full pass makes no mistake.

    Why it helps: after an update, the score on that same point changes by $y_n(\norm{x_n}^2 + 1)$, which has the sign of $y_n$. So a positive example’s score goes up and a negative example’s score goes down: the point moves towards the right side.

    Convergence theorem. If the data are linearly separable (some hyperplane puts every positive on one side and every negative on the other), the perceptron stops after finitely many updates. If they are not separable, it never settles.

    Try it

    Press Next point to let the perceptron look at one point at a time (numbers show the order). A green ring means it was classified correctly; a red ring means a mistake and an update, and the readout shows the score on that point jumping by $y(\norm{x}^2 + 1)$. Keep going until a full pass makes no mistakes. Notice that an update can fix one point and break another; it still gets there because the data are separable.

    GATE DA 2025 · Q22 · MCQ · 1 mark

    Consider designing a linear classifier $$y = \text{sign}(f(x; w, b)), \quad f(x; w, b) = w^\top x + b$$ on a dataset $D = \{(x_1, y_1), (x_2, y_2), \ldots, (x_N, y_N)\}$, $x_i \in \mathbb{R}^d, y_i \in \{+1, -1\}$, $i = 1, 2, \ldots, N$. Recall that the sign function outputs +1 if the argument is positive, and $-1$ if the argument is non-positive. The parameters $w$ and $b$ are updated as per the following training algorithm: $$w_{new} = w_{old} + y_n x_n, \quad b_{new} = b_{old} + y_n$$ whenever $\text{sign}(f(x_n; w_{old}, b_{old})) \ne y_n$. In other words, whenever the classifier wrongly predicts a sample $(x_n, y_n)$ from the dataset, $w_{old}$ gets updated to $w_{new}$, and likewise $b_{old}$ gets updated to $b_{new}$. Consider the case $(x_n, +1)$, $f(x_n; w_{old}, b_{old}) \lt 0$. Then

    1. $f(x_n; w_{new}, b_{new}) \gt f(x_n; w_{old}, b_{old})$
    2. $f(x_n; w_{new}, b_{new}) \lt f(x_n; w_{old}, b_{old})$
    3. $f(x_n; w_{new}, b_{new}) = f(x_n; w_{old}, b_{old})$
    4. $y_n f(x_n; w_{old}, b_{old}) \gt 1$
    1. Recognise the rule: this is the perceptron. Here $y_n = +1$ and $f \lt 0$, so the prediction is $-1$: a mistake, and the update happens with $y_n = +1$: $w_{new} = w_{old} + x_n$, $b_{new} = b_{old} + 1$.

      The update only fires on a mistake, so first confirm one occurred.

    2. Evaluate the new score on the same point: $f(x_n; w_{new}, b_{new}) = (w_{old} + x_n)^\top x_n + b_{old} + 1 = f(x_n; w_{old}, b_{old}) + \norm{x_n}^2 + 1$.

      Expand the dot product: $(w + x)^\top x = w^\top x + x^\top x$, and $x^\top x = \norm{x}^2$.

    3. Since $\norm{x_n}^2 + 1 \ge 1 \gt 0$, the new score is strictly larger: (A). (B) and (C) contradict this; (D) is false because $y_n f(x_n; w_{old}, b_{old}) = f \lt 0$.

      The update always moves the score towards the correct sign, although one update need not make it positive. Official key: A.

    Generative or discriminative?

    There are two broad ways to build a probabilistic classifier, and GATE likes to ask which is which.

    A discriminative model learns $P(y\mid x)$ (or just the boundary) directly: “given these features, how likely is each class?”. Examples: logistic regression, the perceptron, SVMs, neural network classifiers.

    A generative model learns how each class produces its data, $P(x\mid y)$, together with the class frequencies $P(y)$, and then classifies with Bayes’ theorem: $P(y\mid x) \propto P(x\mid y)P(y)$. Because it models $x$ itself, it could in principle generate new fake examples. Examples: naive Bayes (Chapter 3.2), Gaussian discriminant analysis (the probabilistic view of LDA in Chapter 3.3), hidden Markov models.

    Neither is a classifier “type” like PCA, which is dimensionality reduction: it uses no labels at all (Chapter 6.3).

    A logistic regression model for the Hyderabad Hyperplanes has $w = (0.5, -1)$ and $b = 0.5$. For a chase with $x = (3, 1)$, what probability of winning does it give? (Round off to two decimal places.)

    Compute the score $z = w^\top x + b$ first, then $\sigma(z) = 1/(1 + e^{-z})$.

    $z = 0.5\times3 + (-1)\times1 + 0.5 = 1$. Then $\sigma(1) = \dfrac{1}{1 + e^{-1}} = \dfrac{1}{1.3679} \approx$ 0.73.

    A model predicts $p = P(y = 1\mid x) = 0.9$ for a match that was actually lost ($y = 0$). What is the cross-entropy loss for this example, using natural logarithms? (Round off to two decimal places.)

    With $y = 0$ only the $(1-y)\ln(1-p)$ term survives.

    $\ell = -\ln(1 - 0.9) = -\ln 0.1 = \ln 10 \approx$ 2.30. Compare $-\ln 0.9 \approx 0.105$ had the match been won: confident mistakes are expensive.

    A logistic model has $w = (1, 2)$, $b = -3$. A coach only wants to call a chase “safe” when $P(y = 1\mid x) \ge 0.8$. The set of safe points is bounded by a straight line. Where does that line cross the $x_1$-axis (where $x_2 = 0$)? (Round off to two decimal places.)

    $\sigma(z) \ge 0.8$ exactly when the log-odds $z \ge \ln\frac{0.8}{0.2}$.

    $\sigma(z) = 0.8 \iff z = \ln\frac{0.8}{0.2} = \ln 4 \approx 1.386$. The boundary is $x_1 + 2x_2 - 3 = \ln 4$. With $x_2 = 0$: $x_1 = 3 + \ln 4 \approx$ 4.39.

    Changing the threshold shifts the line parallel to the usual $p = 0.5$ boundary ($x_1 + 2x_2 = 3$); the boundary stays linear.

    GATE DA 2024 · Q18 · MCQ · 1 mark

    Match the items in Column 1 with the items in Column 2 in the following table:

    Column 1Column 2
    (p) Principal Component Analysis(i) Discriminative Model
    (q) Naïve Bayes Classification(ii) Dimensionality Reduction
    (r) Logistic Regression(iii) Generative Model
    1. (p) − (iii), (q) − (i), (r) − (ii)
    2. (p) − (ii), (q) − (i), (r) − (iii)
    3. (p) − (ii), (q) − (iii), (r) − (i)
    4. (p) − (iii), (q) − (ii), (r) − (i)

    Which of the three models $P(x\mid y)$, which models $P(y\mid x)$ directly, and which uses no labels?

    PCA finds directions of maximum variance without labels: dimensionality reduction, (ii). Naive Bayes models $P(x\mid y)P(y)$ and applies Bayes’ theorem: generative, (iii). Logistic regression models $P(y\mid x)$ directly: discriminative, (i). So (C). Official key: C.

    A perceptron with labels $y \in \{+1, -1\}$ predicts $\operatorname{sign}(w^\top x + b)$, where sign gives $+1$ for a positive argument and $-1$ otherwise (so $\operatorname{sign}(0) = -1$). It starts at $w = (0, 0)$, $b = 0$ and visits the points below in the order 1, 2, 3, 4, 1, 2, 3, 4, …, applying $w \leftarrow w + yx$, $b \leftarrow b + y$ after each mistake. It stops after a complete pass with no mistakes.

    Points: 1: $x = (1, 0)$, $y = +1$; 2: $x = (0, 1)$, $y = +1$; 3: $x = (-1, 1)$, $y = -1$; 4: $x = (1, -2)$, $y = -1$.

    How many updates does it make in total?

    Track $(w, b)$ in a small table, one row per visit. Pay attention to any score that is exactly 0.

    Pass 1. Point 1: $f = 0$, predicts $-1$, wrong: $w = (1, 0)$, $b = 1$. Point 2: $f = 0 + 0 + 1 = 1$, correct. Point 3: $f = -1 + 0 + 1 = 0$, predicts $-1$, correct. Point 4: $f = 1 + 0 + 1 = 2$, predicts $+1$, wrong: $w = (0, 2)$, $b = 0$.

    Pass 2. Point 1: $f = 0$, predicts $-1$, wrong: $w = (1, 2)$, $b = 1$. Point 2: $f = 3$, correct. Point 3: $f = -1 + 2 + 1 = 2$, wrong: $w = (2, 1)$, $b = 0$. Point 4: $f = 2 - 2 + 0 = 0$, predicts $-1$, correct.

    Pass 3. Scores: $2, 1, -1, 0$ give predictions $+1, +1, -1, -1$, all correct, so it stops. Total updates: 4, ending at $w = (2, 1)$, $b = 0$.

    The trap is $\operatorname{sign}(0)$. Treating a zero score as “correct” for the positive points would skip the update at point 1 in pass 2 and give a different count; the question fixes $\operatorname{sign}(0) = -1$, exactly as GATE 2025 Q22 did.

    A logistic regression model $P(y = 1\mid x) = \sigma(w^\top x + b)$ has been trained. Which statements are correct? (Select all that apply.)

    1. The set of points with $P(y = 1\mid x) = 0.7$ is a hyperplane parallel to the decision boundary for threshold 0.5.
    2. Replacing $(w, b)$ by $(2w, 2b)$ moves the 0.5 decision boundary.
    3. Replacing $(w, b)$ by $(2w, 2b)$ leaves every predicted label unchanged but pushes every predicted probability further from 0.5.
    4. On a linearly separable training set, the unregularised cross-entropy loss is minimised at some finite $w$.

    $\sigma(z) = 0.7$ fixes the value of $z$. For (D), what happens to the loss on a correctly classified point as you scale $w$ and $b$ up?

    (A) True: $\sigma(z) = 0.7 \iff w^\top x + b = \ln\frac{0.7}{0.3}$, a hyperplane with the same normal $w$.

    (B) False: $2w^\top x + 2b = 0 \iff w^\top x + b = 0$, the same set.

    (C) True: the sign of every score is unchanged, but each $\lvert z\rvert$ doubles, so $\sigma(z)$ moves away from 0.5.

    (D) False: if some $(w, b)$ separates the data, scaling it by $c \to \infty$ sends every point’s loss to 0 without ever reaching it, so there is no finite minimiser. In practice an L2 penalty $\lambda\norm{w}^2$ (as in ridge regression, Chapter 2.2) is added to keep $w$ finite.

    Answer: A; C.

    Logistic regression starts at $w = (0, 0)$, $b = 0$. One step of gradient descent with learning rate $\eta = 0.5$ is taken on the cross-entropy loss of the single example $x = (2, 1)$, $y = 1$, updating both $w$ and $b$. What probability $P(y = 1\mid x)$ does the updated model give to this same $x$? (Round off to two decimal places.)

    Use the gradients $(p - y)x$ for $w$ and $p - y$ for $b$, evaluated at the starting point, where $p = \sigma(0)$. Gradient descent subtracts $\eta$ times the gradient.

    At the start $z = 0$, so $p = 0.5$ and $p - y = -0.5$.

    Gradients: $\nabla_w = -0.5\,(2, 1) = (-1, -0.5)$ and $\partial_b = -0.5$.

    Update: $w = (0, 0) - 0.5(-1, -0.5) = (0.5, 0.25)$ and $b = 0 - 0.5(-0.5) = 0.25$.

    New score: $z = 0.5\times2 + 0.25\times1 + 0.25 = 1.5$, so $p = \sigma(1.5) = \dfrac{1}{1 + e^{-1.5}} \approx$ 0.82.

    Tempting errors: forgetting to update $b$ gives $z = 1.25$ and 0.78; adding the gradient instead of subtracting it gives $z = -1.5$ and 0.18.

    • Read a linear classifier as “score, then sign”: $z = w^\top x + b$, boundary at $z = 0$, $w$ perpendicular to it.
    • Convert between probability, odds and log-odds fluently: $p = 0.8 \leftrightarrow$ odds 4 $\leftrightarrow$ log-odds $\ln 4$.
    • For a perceptron question, check the sign convention at 0 and trace updates in a table.
    • Thinking logistic regression predicts a number: it’s a classifier with a linear boundary.
    • Forgetting the bias update $b \leftarrow b + y$ in the perceptron.
    • Calling logistic regression generative: it models $P(y\mid x)$ directly, so it’s discriminative.
    1. A linear classifier predicts by the sign of w⊤x + b; its decision boundary w⊤x + b = 0 is a hyperplane with w perpendicular to it.
    2. Logistic regression: P(y = 1 | x) = σ(w⊤x + b), so the log-odds is linear; it is trained by minimising cross-entropy, whose gradient is (p − y)x.
    3. Perceptron: on a mistake, w ← w + yx, b ← b + y; the score on that point moves by y(‖x‖² + 1). Discriminative models learn P(y | x); generative ones learn P(x | y)P(y).

    Despite its name, logistic regression is mainly used to

    predict a number, such as runs scored
    That’s ordinary (linear) regression. Think about what the sigmoid’s output range $(0, 1)$ is used for.
    group unlabelled matches into clusters
    Logistic regression needs labels; clustering doesn’t use them.
    predict a class, together with a probability for it
    It outputs $P(y = 1\mid x)$ and classifies by thresholding it, usually at 0.5.
    reduce many features to a few
    That’s dimensionality reduction, such as PCA.

    A logistic regression model gives a match a score $w^\top x + b = 0$. Its predicted probability of a win is

    0.5
    $\sigma(0) = 1/(1 + 1) = 0.5$: the point lies exactly on the decision boundary.
    0
    A score of 0 is the log-odds, not the probability. Odds $e^0 = 1$ means even chances.
    1
    Only a very large positive score gives a probability near 1.
    $e^{-1}$
    Substitute $z = 0$ into $1/(1 + e^{-z})$.

    A perceptron misclassifies the point $(x, y = -1)$ and updates. On that same point, the score $w^\top x + b$

    increases by $\norm{x}^2 + 1$
    The update adds $y x$ with $y = -1$. Which way does that push the score?
    stays the same
    The weights changed, and the change is aligned with $x$.
    becomes exactly $-1$
    One update moves it by a fixed amount; it need not land on any particular value.
    decreases by $\norm{x}^2 + 1$
    New score $=$ old $+\,y(\norm{x}^2 + 1)$ with $y = -1$: it moves towards the correct, negative side.

    Naive Bayes: classify by counting

    Naive Bayes applies Bayes’ theorem to pick the most probable class, after assuming the features are independent of each other once the class is known.

    It has appeared in every GATE DA paper so far in some form: 2024 Q20 (counting its parameters), 2025 Q35 (misclassification probability) and the sample paper’s Q28; 2026 Q23 matched it to “classification”.

    It’s like a scout judging a new bowler from a checklist: “fast bowlers usually have a long run-up, usually are tall, usually bowl bouncers”. The scout scores each clue separately and multiplies the evidence, without worrying that tall bowlers also tend to have long run-ups.

    Where it shows up in GATE DA

    Counting parameters, computing a posterior or misclassification probability, and spotting it as a generative model.

    2024 Q20 · number of parameters2025 Q35 · misclassification probabilitySample Q28 · parameters, K classes2024 Q18 · generative model2026 Q23 · task matching
    Heat: every year, 1–2 marks

    The Kalinga Kernels’ analyst has a simple table of their last ten matches: did they win the toss, were they at home, was the pitch spin-friendly, and did they win. Tomorrow they’ve won the toss, are playing away, on a spin pitch. Should the analyst expect a win?

    Bayes’ theorem (recall Probability 2.2) says $$P(\text{Win}\mid x) = \frac{P(x\mid \text{Win})\,P(\text{Win})}{P(x)},$$ where $x$ is the whole feature vector (Won toss, Away, Spin). The prior $P(\text{Win})$ is easy: 6 wins out of 10. The trouble is the likelihood $P(x\mid\text{Win})$: the exact combination (Won, Away, Spin) appears among the wins only once, and with more features most combinations never appear at all. You can’t estimate a probability from zero or one example.

    The naive fix: pretend that, within each class, the features don’t influence each other. Then the probability of the whole combination is a product of one-feature probabilities, and each of those can be estimated from plenty of rows.

    Events $A$ and $B$ are conditionally independent given $C$ if $P(A \cap B\mid C) = P(A\mid C)\,P(B\mid C)$: once you know $C$, learning $B$ tells you nothing more about $A$.

    Tiny example: a player’s shoe size and reading score are related across all children (older children have both bigger feet and better reading), but given the child’s age they are roughly independent. Age “explains away” the link.

    Assume the features $x_1, \ldots, x_D$ are conditionally independent given the class $c$. Then $$P(x\mid c) = \prod_{j=1}^{D} P(x_j\mid c), \qquad\text{and the classifier predicts}\qquad \hat y = \argmax_c\; P(c)\prod_{j=1}^{D} P(x_j\mid c).$$ The denominator $P(x)$ is the same for every class, so it doesn’t affect which class wins; you only need it if you want the actual posterior probabilities, and then it’s the sum of the class scores (normalise so they add to 1).

    From training data the estimates are simple fractions: $P(c) = \frac{N_c}{N}$ and $P(x_j = v\mid c) = \frac{N_{c,v}}{N_c}$, where $N_c$ counts training rows of class $c$ and $N_{c,v}$ counts those rows whose feature $j$ equals $v$. These are the maximum-likelihood estimates.

    Careful: “naive” means features are independent given the class, not independent overall. Toss result and venue may well be correlated across all matches; naive Bayes only assumes the correlation disappears once you know whether the match was won.

    The zero-count problem and Laplace smoothing

    If a feature value never appears with a class in the training data, its estimate is $0/N_c = 0$, and that single zero wipes out the whole product, however strongly the other features point to that class. With small data, “never seen” usually means “rare”, not “impossible”.

    Add one imaginary example of every value to every class: $$\hat P(x_j = v\mid c) = \frac{N_{c,v} + 1}{N_c + V_j},$$ where $V_j$ is the number of possible values of feature $j$. The estimates still add to 1 over the $V_j$ values, and none is zero. (Priors are usually left as $N_c/N$.)

    Tiny example: 0 of 4 losses were on spin pitches, and pitch has 2 values, so the smoothed estimate is $\frac{0+1}{4+2} = \frac16$ instead of 0.

    Try it

    Choose tomorrow’s match conditions with the chips; the table shades every cell that agrees with the new match. The readout multiplies prior × three likelihoods for each class and normalises. Start with Won, Away, Spin: the Kernels have never lost on a spin pitch, so “Loss” scores exactly 0. Switch Laplace smoothing on and watch Loss get a small, sensible probability. Then try Lost, Away, Pace.

    Using the Kalinga Kernels table in the widget (10 matches: 6 wins, 4 losses), predict the result of a match with Toss = Won, Venue = Away, Pitch = Spin, first with raw counts and then with Laplace smoothing. Give $P(\text{Win}\mid x)$ in each case.

    1. Count. Among the 6 wins: Won toss 4, Away 2, Spin 3. Among the 4 losses: Won toss 2, Away 3, Spin 0. Priors: $P(\text{Win}) = \frac{6}{10}$, $P(\text{Loss}) = \frac{4}{10}$.

      Every estimate is a fraction of rows within one class, so count class by class.

    2. Raw scores. Win: $\frac{6}{10}\cdot\frac46\cdot\frac26\cdot\frac36 = \frac{1}{15} \approx 0.0667$. Loss: $\frac{4}{10}\cdot\frac24\cdot\frac34\cdot\frac04 = 0$. So $P(\text{Win}\mid x) = 1$.

      Naive Bayes multiplies one likelihood per feature. The single zero count for (Spin, Loss) forces a certainty the data can’t justify.

    3. Smoothed likelihoods (each feature has 2 values, so add 1 on top and 2 below). Win: $\frac{4+1}{6+2} = \frac58$, $\frac{2+1}{8} = \frac38$, $\frac{3+1}{8} = \frac12$. Loss: $\frac{2+1}{4+2} = \frac12$, $\frac{3+1}{6} = \frac23$, $\frac{0+1}{6} = \frac16$.

      Laplace smoothing uses $\frac{N_{c,v}+1}{N_c + V_j}$ with $V_j = 2$ here.

    4. Smoothed scores. Win: $0.6\cdot\frac58\cdot\frac38\cdot\frac12 = \frac{9}{128} \approx 0.0703$. Loss: $0.4\cdot\frac12\cdot\frac23\cdot\frac16 = \frac{1}{45} \approx 0.0222$.

      Same recipe: prior times the product of likelihoods.

    5. Normalise: $P(\text{Win}\mid x) = \frac{0.0703}{0.0703 + 0.0222} \approx$ 0.76. The prediction is still Win, but now with an honest 24% chance of a loss.

      The two scores are proportional to the posteriors; dividing by their sum is the $P(x)$ in Bayes’ theorem.

    A free parameter is a number the model must learn that isn’t forced by the others. A distribution over $V$ values has $V - 1$ free parameters, because they must add to 1.

    • Two classes, $K$ binary features (the 2024 Q20 setting): 1 for the prior $P(y = 1)$, plus one number $P(x_j = 1\mid y)$ for each feature and each class: $2K + 1$.
    • Without the naive assumption, each class needs a full table over all $2^K$ feature combinations: $2(2^K - 1) + 1 = 2^{K+1} - 1$, exponential in $K$. That’s the reason for the assumption.
    • $K$ classes, $D$ features with $V$ values each: free parameters $(K - 1) + K D (V - 1)$. If instead you count every table entry, ignoring the sum-to-1 constraints, you get $K + KDV$.

    Misclassification probability of the Bayes rule at a point $x$: compute both scores $P(c)P(x\mid c)$, normalise; the classifier picks the larger posterior and is wrong with probability equal to the smaller one, $1 - \max_c P(c\mid x)$.

    Parameter counts: decide first whether the options count free parameters or all table entries, then use the formulas above.

    Go deeper: naive Bayes is a linear classifier in disguise

    With binary features, take logs of the ratio of the two class scores: $\ln\frac{P(1)\prod_j P(x_j\mid 1)}{P(0)\prod_j P(x_j\mid 0)} = \ln\frac{P(1)}{P(0)} + \sum_j \ln\frac{P(x_j\mid 1)}{P(x_j\mid 0)}$. Each term is $a_j x_j + c_j$ for constants $a_j, c_j$ (because $x_j$ is 0 or 1), so the log-odds is linear in $x$: exactly the form logistic regression uses. The two models share a boundary shape but fit it differently: naive Bayes counts per class (generative), logistic regression tunes $w$ to the labels directly (discriminative). In practice, products of many small probabilities underflow, so implementations add logarithms instead of multiplying. For continuous features, Gaussian naive Bayes uses a normal density per feature and class.

    The Haryana Heuristics lost 20 matches last season and none of them was on a “flat” pitch. Pitch type takes 3 values (spin, pace, flat). With Laplace smoothing, what is the estimate of $P(\text{flat}\mid\text{Loss})$? (Round off to three decimal places.)

    Add 1 to the count and the number of possible values to the class total.

    $\dfrac{0 + 1}{20 + 3} = \dfrac{1}{23} \approx$ 0.043.

    GATE DA 2025 · Q35 · NAT · 1 mark

    The naive Bayes classifier is used to solve a two-class classification problem with class-labels $y_1, y_2$. Suppose the prior probabilities are $P(y_1) = \frac13$ and $P(y_2) = \frac23$. Assuming a discrete feature space with $$P(x\mid y_1) = \frac34 \quad\text{and}\quad P(x\mid y_2) = \frac14$$ for a specific feature vector $x$. The probability of misclassifying $x$ is ______ (Round off to two decimal places)

    Compute prior × likelihood for each class and normalise. The classifier picks the larger posterior.

    Scores: $\frac13\cdot\frac34 = \frac14$ and $\frac23\cdot\frac14 = \frac16$. Sum $= \frac{5}{12}$. Posteriors: $P(y_1\mid x) = \frac{1/4}{5/12} = 0.6$ and $P(y_2\mid x) = 0.4$.

    The classifier picks $y_1$, and is wrong whenever the true class is $y_2$: probability 0.4. Official key: 0.39 to 0.41.

    GATE DA 2024 · Q20 · MCQ · 1 mark

    Given a dataset with $K$ binary-valued attributes (where $K \gt 2$) for a two-class classification task, the number of parameters to be estimated for learning a naïve Bayes classifier is

    1. $2^K + 1$
    2. $2K + 1$
    3. $2^{K+1} + 1$
    4. $K^2 + 1$

    How many numbers describe one binary feature within one class? How many describe the two-class prior?

    Each binary attribute needs one number per class, $P(x_j = 1\mid y)$ (its complement is forced), giving $2K$. The prior needs one number, $P(y = 1)$. Total $2K + 1$: (B). Official key: B.

    The exponential options describe a model without the naive assumption, which needs a table over all $2^K$ combinations per class.

    GATE DA 2024 sample paper · Q28 · MCQ · 2 marks

    Given a $K$-class dataset containing $N$ points, where sample points are described using $D$ discrete features with each feature capable of taking $V$ values, how many parameters need to be estimated for Naïve Bayes Classifier?

    1. $V^D K$
    2. $K^{V^D}$
    3. $VDK + K$
    4. $K(V + D)$

    Here $K$ is the number of classes, not features. For each class, how many numbers describe each feature? How many numbers describe the prior?

    For each of the $K$ classes and each of the $D$ features, naive Bayes stores a distribution over $V$ values: $VDK$ numbers. The class prior adds $K$ numbers. Total $VDK + K$: (C). (Sample paper, no official key; this is our answer.)

    This option counts every table entry. Counting only free parameters would give $(K-1) + KD(V-1)$, which is not offered, so the intended answer is (C). (A) is the size of a full joint table per class, which is what naive Bayes avoids.

    The Haryana Heuristics’ last 8 matches, with Weather (Dry, Humid or Rainy) and Toss (Won or Lost):

    #WeatherTossResult
    1DryWonWin
    2HumidWonWin
    3DryLostWin
    4DryWonWin
    5HumidLostWin
    6RainyLostLoss
    7HumidLostLoss
    8DryLostLoss

    A naive Bayes classifier with Laplace smoothing on the likelihoods (priors unsmoothed) is used for a match with Weather = Rainy and Toss = Won. What is $P(\text{Win}\mid\text{Rainy}, \text{Won})$? (Round off to two decimal places.)

    Weather has 3 possible values and Toss has 2, so the denominators get $+3$ and $+2$ respectively. Without smoothing, check what happens to both classes.

    Counts: 5 wins (Rainy 0, Won 3) and 3 losses (Rainy 1, Won 0). Priors $\frac58$ and $\frac38$.

    Win: $\frac58\cdot\frac{0+1}{5+3}\cdot\frac{3+1}{5+2} = \frac58\cdot\frac18\cdot\frac47 = \frac{5}{112} \approx 0.0446$.

    Loss: $\frac38\cdot\frac{1+1}{3+3}\cdot\frac{0+1}{3+2} = \frac38\cdot\frac13\cdot\frac15 = \frac{1}{40} = 0.025$.

    $P(\text{Win}\mid x) = \dfrac{5/112}{5/112 + 1/40} = \dfrac{25}{39} \approx$ 0.64.

    Without smoothing both scores are 0 (no rainy wins, no toss-won losses), so the posterior is undefined: a vivid case for smoothing. Using $+2$ for Weather as if it were binary gives about 0.63, a common slip.

    Which statements about naive Bayes classifiers are correct? (Select all that apply.)

    1. It assumes the features are independent of each other across the whole dataset.
    2. If one feature is accidentally included twice (an exact copy), its evidence is counted twice, and this can change the predicted class.
    3. With Laplace smoothing, no estimated likelihood $P(x_j = v\mid c)$ is zero.
    4. With $D$ binary features and 2 classes, the number of free parameters grows exponentially in $D$.

    Re-read the assumption carefully: independent given what? For (B), what does the product look like when the same factor appears twice?

    (A) False: the assumption is conditional independence given the class.

    (B) True: a duplicated feature contributes its likelihood ratio squared. If, say, the duplicated feature favours class 1 by a factor of 2 and the others favour class 2 by a factor of 3, one copy gives class 2 and two copies ($2^2 = 4 \gt 3$) give class 1.

    (C) True: the numerator is at least 1.

    (D) False: it is $2D + 1$, linear in $D$. Exponential growth is what the naive assumption avoids.

    Answer: B; C.

    A naive Bayes classifier predicts which of 3 DPL teams will top the table. Each example has 4 binary features and 2 further features that each take 5 values. Counting free parameters (every probability distribution must sum to 1), how many parameters must be estimated?

    1. 36
    2. 38
    3. 57
    4. 1199

    Per class: a binary feature needs 1 number, a 5-valued feature needs 4. Then add the prior over 3 classes.

    Per class: $4\times1 + 2\times4 = 12$ free numbers. Three classes: 36. Prior over 3 classes: $3 - 1 = 2$. Total 38: (B).

    (A) forgets the prior. (C) counts every table entry: $3\times(4\times2 + 2\times5) + 3 = 57$. (D) is the full joint model without the naive assumption: $3\times(2^4\times5^2 - 1) + 2 = 1199$.

    • Count class by class: for each class, the prior and then one likelihood per feature.
    • Normalise only at the end, and only if a probability (not just a label) is asked for.
    • Use $V_j$, the number of values of that feature, in the Laplace denominator.
    • Forgetting the prior and comparing likelihoods alone (it can flip the decision).
    • Letting one zero count decide the answer; smooth it.
    • Mixing “free parameters” and “all table entries” when counting; read the options first.
    1. Naive Bayes predicts argmax over c of P(c) ∏ P(xⱼ | c), assuming features are conditionally independent given the class.
    2. Estimates are class-wise fractions; Laplace smoothing (count + 1)/(N_c + V) stops a single zero from wiping out a class.
    3. Parameters grow linearly: 2K + 1 free parameters for K binary features and two classes, against 2^(K+1) − 1 without the naive assumption.

    Naive Bayes is called “naive” because it assumes

    every class is equally likely
    Naive Bayes uses the class priors $P(c)$; they need not be equal.
    every feature follows a normal distribution
    That’s one variant (Gaussian naive Bayes), not the defining assumption.
    the classes can be separated by a straight line
    That’s linear separability, a different idea.
    the features are independent of each other once the class is known
    Conditional independence given the class lets $P(x\mid c)$ be a product of one-feature terms.

    The word “cashback” never appeared in any spam email in the training set. Without smoothing, a naive Bayes filter gives a new email containing “cashback” a spam probability of

    a small but positive number
    That’s what smoothing would give. Look at what one zero factor does to a product.
    exactly 0
    $P(\text{cashback}\mid\text{spam}) = 0$ makes the whole spam score 0, whatever else the email says.
    0.5
    Nothing in the model makes it fall back to even chances.
    the prior $P(\text{spam})$
    The prior is multiplied by the likelihoods, including the zero one.

    A naive Bayes classifier has 10 binary features and 2 classes. How many free parameters does it estimate?

    20
    That’s the likelihoods. The class prior also needs a number.
    2047
    That’s $2^{11} - 1$, the count without the naive assumption.
    21
    $2K + 1$ with $K = 10$: one number per feature per class, plus the prior.
    11
    Each class has its own likelihood for each feature.

    Linear discriminant analysis: the direction that separates classes best

    Fisher’s linear discriminant finds the direction $u$ such that, after projecting every point onto it, the two class means are as far apart as possible relative to the spread within each class.

    GATE DA 2024 Q22 asked for the eigenvalue equation $S_W^{-1}S_Bu = \lambda u$ that the best direction satisfies, and 2025 Q55 asked why the nearest-mean classifier is linear. 2026 Q23 listed LDA among classification and feature-extraction tools.

    It’s like photographing two flocks of birds from the side so that they look as separate as possible: you choose the camera angle where the flocks’ shadows overlap least, not just where their centres look farthest apart.

    Where it shows up in GATE DA

    The Fisher criterion and its eigen-equation, the two-class solution, and the nearest-mean classifier.

    2024 Q22 · $S_W^{-1}S_Bu^* = \lambda u^*$2025 Q55 · nearest-mean classifier is linear2026 Q23 · LDA for classification
    Heat: most years, 1–2 marks

    The Nagpur Neural Nets’ analyst has two numbers for each match (say, a batting index $x_1$ and a bowling index $x_2$) and wants to compress them into one score that best tells wins from losses. The simplest one-number summary of a point $x$ is its projection onto a direction $u$: $z = u^\top x$ (recall from Linear algebra that this is the length of $x$’s shadow on the line through $u$, when $\norm{u} = 1$).

    Which direction? A first guess is the line joining the two class means: that pushes the projected means furthest apart. But if each class is a long, tilted cloud, that direction can smear both clouds across each other. Fisher’s idea: reward a large gap between projected means, and penalise a large spread of each class along the line.

    Notation
    $m_1, m_2$
    the mean (average point) of class 1 and of class 2
    $S_W$
    within-class scatter: $\sum_{x \in C_1}(x - m_1)(x - m_1)^\top + \sum_{x \in C_2}(x - m_2)(x - m_2)^\top$, a $d \times d$ matrix measuring how spread each class is around its own mean
    $S_B$
    between-class scatter: $(m_2 - m_1)(m_2 - m_1)^\top$, measuring how far apart the means are

    For a direction $u$, the projected class means are $u^\top m_1$ and $u^\top m_2$, so their squared gap is $(u^\top(m_2 - m_1))^2 = u^\top S_B u$. The total squared spread of the projected points around their own class means is $u^\top S_W u$. Fisher’s linear discriminant chooses $u$ to maximise $$J(u) = \frac{u^\top S_B u}{u^\top S_W u} = \frac{\text{(gap between projected means)}^2}{\text{spread within classes along } u}.$$ Scaling $u$ by any non-zero number leaves $J$ unchanged, so only the direction matters.

    Try it

    Turn the purple line with the slider. Each point casts a dotted shadow onto the line; the strip underneath shows the shadows as a number line (squares are losses, dots are wins, tall ticks are the projected means). Press Mean difference: the means are far apart but both clouds smear across each other. Now press Fisher direction: the gap is smaller but the clouds are much tighter, and $J$ more than triples.

    GATE DA 2024 · Q22 · MCQ · 1 mark

    For any binary classification dataset, let $S_B \in \mathbb{R}^{d\times d}$ and $S_W \in \mathbb{R}^{d\times d}$ be the between-class and within-class scatter (covariance) matrices, respectively. The Fisher linear discriminant is defined by $u^* \in \mathbb{R}^d$, that maximizes $$J(u) = \frac{u^T S_B u}{u^T S_W u}$$ If $\lambda = J(u^*)$, $S_W$ is non-singular and $S_B \ne 0$, then $(u^*, \lambda)$ must satisfy which ONE of the following equations?

    Note: $\mathbb{R}$ denotes the set of real numbers.

    1. $S_W^{-1} S_B u^* = \lambda u^*$
    2. $S_W u^* = \lambda S_B u^*$
    3. $S_B S_W u^* = \lambda u^*$
    4. ${u^*}^T u^* = \lambda^2$
    1. At a maximum, the gradient of $J$ is zero. Write $J = N/D$ with $N = u^\top S_B u$ and $D = u^\top S_W u$. For a symmetric matrix $A$, the gradient of $u^\top A u$ is $2Au$.

      Both scatter matrices are symmetric (sums of $vv^\top$ terms), so the standard quadratic-form gradient applies (recall Calculus).

    2. Quotient rule: $\nabla J = \dfrac{2S_Bu\,D - 2S_Wu\,N}{D^2} = 0 \;\Rightarrow\; S_B u = \dfrac{N}{D}\,S_W u = J(u)\,S_W u$.

      Setting the numerator to zero and dividing by $D \gt 0$.

    3. At $u^*$, $J(u^*) = \lambda$, so $S_B u^* = \lambda S_W u^*$. Multiply on the left by $S_W^{-1}$ (it exists): $S_W^{-1} S_B u^* = \lambda u^*$. That’s (A).

      This is a generalised eigenvalue problem: $u^*$ is an eigenvector of $S_W^{-1}S_B$, and the maximum value of $J$ is its largest eigenvalue.

    4. Check the others. (B) has $S_W$ and $S_B$ swapped: it would hold with $1/\lambda$, not $\lambda$. (C) multiplies the matrices in the wrong order and without the inverse. (D) is a normalisation, and $J$ doesn’t depend on the length of $u$ at all. Official key: A.

      A quick dimension or scaling check eliminates distractors like (D).

    With two classes, $S_B u = (m_2 - m_1)\big[(m_2 - m_1)^\top u\big]$ is always a multiple of $m_2 - m_1$. So $S_B u^* = \lambda S_W u^*$ forces $$u^* \propto S_W^{-1}(m_2 - m_1), \qquad J_{\max} = \lambda = (m_2 - m_1)^\top S_W^{-1}(m_2 - m_1).$$ $S_B$ has rank 1, so $S_W^{-1}S_B$ has exactly one non-zero eigenvalue. With $K$ classes, $S_B$ has rank at most $K - 1$, so LDA gives at most $K - 1$ useful directions; this is how LDA is used for feature extraction (supervised dimensionality reduction).

    To classify, project a new point onto $u^*$ and compare with a threshold, typically the midpoint of the two projected means. The boundary $u^{*\top}x = t$ is a hyperplane: LDA is a linear classifier.

    Wins of the Nagpur Neural Nets: $(1, 1), (2, 3), (3, 2)$. Losses: $(4, 5), (5, 7), (6, 6)$. Find the Fisher direction, the maximum value of $J$, and a classification rule.

    1. Means: $m_1 = (2, 2)$, $m_2 = (5, 6)$, so $m_2 - m_1 = (3, 4)$.

      Average each coordinate within the class.

    2. Deviations from the mean are $(-1, -1), (0, 1), (1, 0)$ in both classes. Each class contributes $\begin{pmatrix}2 & 1\\ 1 & 2\end{pmatrix}$, so $S_W = \begin{pmatrix}4 & 2\\ 2 & 4\end{pmatrix}$.

      Sum the outer products $vv^\top$: $(-1,-1)$ gives $\begin{pmatrix}1&1\\1&1\end{pmatrix}$, $(0,1)$ gives $\begin{pmatrix}0&0\\0&1\end{pmatrix}$, $(1,0)$ gives $\begin{pmatrix}1&0\\0&0\end{pmatrix}$.

    3. $S_W^{-1} = \frac{1}{12}\begin{pmatrix}4 & -2\\ -2 & 4\end{pmatrix}$, so $u^* \propto \begin{pmatrix}4 & -2\\ -2 & 4\end{pmatrix}\begin{pmatrix}3\\4\end{pmatrix} = \begin{pmatrix}4\\10\end{pmatrix} \propto (2, 5)$.

      The 2×2 inverse: swap the diagonal, negate the off-diagonal, divide by the determinant $16 - 4 = 12$. The constant $\frac{1}{12}$ only rescales $u$.

    4. $J_{\max} = (3, 4)\cdot\frac{1}{12}(4, 10) = \frac{12 + 40}{12} = \frac{13}{3} \approx 4.33$. For comparison, the mean-difference direction $(3, 4)$ gives $J = \frac{25^2}{148} \approx 4.22$.

      Fisher’s direction tilts from $(3, 4)$ towards the axis along which the clouds are thin.

    5. Projected means: $(2, 5)\cdot(2, 2) = 14$ and $(2, 5)\cdot(5, 6) = 40$. Rule: predict Loss if $2x_1 + 5x_2 \gt 27$, Win otherwise.

      The midpoint $\frac{14 + 40}{2} = 27$ is the natural threshold when the classes are equally common.

    The nearest-mean classifier is linear too

    An even simpler rule: assign a point to whichever class mean it is closer to. It sounds like it should give a curved boundary, because distances are squared. It doesn’t. Expand $f(x) = \norm{\mu_r - x}^2 - \norm{\mu_g - x}^2$: $$f(x) = \norm{\mu_r}^2 - 2\mu_r^\top x + \norm{x}^2 - \norm{\mu_g}^2 + 2\mu_g^\top x - \norm{x}^2 = 2(\mu_g - \mu_r)^\top x + \norm{\mu_r}^2 - \norm{\mu_g}^2.$$ The $\norm{x}^2$ terms cancel, leaving $w^\top x + b$ with $w = 2(\mu_g - \mu_r)$ and $b = \norm{\mu_r}^2 - \norm{\mu_g}^2$. The boundary $f = 0$ is the perpendicular bisector of the segment joining the two means.

    The link to LDA: if each class is a Gaussian with the same covariance $\Sigma$ and the classes are equally likely, the Bayes-optimal rule has a linear boundary with normal $\Sigma^{-1}(\mu_2 - \mu_1)$, the same direction as Fisher’s. When $\Sigma$ is a multiple of $I$ (round clouds), that’s exactly the nearest-mean rule. If the classes have different covariances, the boundary becomes quadratic (QDA).

    For the worked example above ($m_2 - m_1 = (3, 4)$, $S_W = \begin{pmatrix}4 & 2\\ 2 & 4\end{pmatrix}$), compute the Fisher score $J(u)$ for $u = (1, 0)$, that is, using only the first feature.

    $u^\top S_B u = (u^\top(m_2 - m_1))^2$ and $u^\top S_W u$ is the top-left entry of $S_W$ when $u = (1, 0)$.

    Numerator $(1\cdot3 + 0\cdot4)^2 = 9$. Denominator $= 4$. $J = 9/4 =$ 2.25, well below the best possible $13/3 \approx 4.33$.

    Two classes have $m_2 - m_1 = (2, 4)$ and within-class scatter $S_W = \begin{pmatrix}2 & 0\\ 0 & 8\end{pmatrix}$. If the Fisher direction is scaled so that its first component is 1, what is its second component?

    $u^* \propto S_W^{-1}(m_2 - m_1)$; a diagonal matrix is inverted entry by entry.

    $S_W^{-1}(m_2 - m_1) = (2/2,\; 4/8) = (1, 0.5)$. Second component 0.5. The second feature is noisier (spread 8), so Fisher trusts it less than the mean difference alone would suggest.

    A nearest-mean classifier has class means $\mu_A = (0, 0)$ and $\mu_B = (4, 2)$ and computes $f(x) = \norm{\mu_A - x}^2 - \norm{\mu_B - x}^2$, assigning class A when $f(x) \lt 0$. Find $f(x)$ at $x = (3, 0)$.

    Either compute both squared distances directly, or use $f(x) = 2(\mu_B - \mu_A)^\top x + \norm{\mu_A}^2 - \norm{\mu_B}^2$.

    $\norm{\mu_A - x}^2 = 9$ and $\norm{\mu_B - x}^2 = 1 + 4 = 5$, so $f = $ 4, and $x$ goes to class B. Check with the linear form: $2(4, 2)\cdot(3, 0) + 0 - 20 = 24 - 20 = 4$.

    GATE DA 2025 · Q55 · MSQ · 2 marks

    Consider a two-class problem in $\mathbb{R}^d$ with class labels red and green. Let $\mu_{red}$ and $\mu_{green}$ be the means of the two classes. Given test sample $x \in \mathbb{R}^d$, a classifier calculates the squared Euclidean distance (denoted by $\norm{\cdot}^2$) between $x$ and the means of the two classes and assigns the class label that the sample $x$ is closest to. That is, the classifier computes $$f(x) = \norm{\mu_{red} - x}^2 - \norm{\mu_{green} - x}^2$$ and assigns the label red to $x$ if $f(x) \lt 0$, and green otherwise. Which of the following statements is/are correct?

    1. The sample $x = 0$ is assigned the label green if $\norm{\mu_{red}} \lt \norm{\mu_{green}}$
    2. $f$ is a linear function of $x$
    3. $f(x) = w^\top x + b$, where $w$ and $b$ are functions of $\mu_{red}$ and $\mu_{green}$
    4. $f$ is a quadratic polynomial in $x$

    Expand both squared norms. What happens to the $\norm{x}^2$ terms? Then evaluate at $x = 0$.

    Expanding, $f(x) = 2(\mu_{green} - \mu_{red})^\top x + \norm{\mu_{red}}^2 - \norm{\mu_{green}}^2$: the $\norm{x}^2$ terms cancel. So (C) holds with $w = 2(\mu_{green} - \mu_{red})$, $b = \norm{\mu_{red}}^2 - \norm{\mu_{green}}^2$, and (B) holds in the sense used here (a linear function plus a constant). (D) fails: there is no $x^2$ term left.

    (A): $f(0) = \norm{\mu_{red}}^2 - \norm{\mu_{green}}^2 \lt 0$ when $\norm{\mu_{red}} \lt \norm{\mu_{green}}$, so $x = 0$ is labelled red, not green. False.

    Answer: B; C. Official key: B; C.

    Two classes have $m_2 - m_1 = (3, 0)$ and within-class scatter $S_W = \begin{pmatrix}2 & 1\\ 1 & 2\end{pmatrix}$. What is the largest possible value of the Fisher criterion $J(u) = \dfrac{u^\top S_B u}{u^\top S_W u}$?

    For two classes, $J_{\max} = (m_2 - m_1)^\top S_W^{-1}(m_2 - m_1)$. Invert the 2×2 matrix.

    $S_W^{-1} = \frac13\begin{pmatrix}2 & -1\\ -1 & 2\end{pmatrix}$, so $S_W^{-1}(3, 0) = (2, -1)$. That is the Fisher direction.

    $J_{\max} = (3, 0)\cdot(2, -1) = $ 6.

    The tempting answer 4.5 comes from using the mean-difference direction $u = (3, 0)$: $J = \frac{9^2}{(3,0)S_W(3,0)^\top} = \frac{81}{18} = 4.5$. The optimum tilts away from $m_2 - m_1$ because the clouds are elongated along $(1, 1)$.

    Which statements about Fisher’s linear discriminant are correct? (Select all that apply.)

    1. $J(cu) = J(u)$ for every non-zero real number $c$.
    2. For two classes, the between-class scatter matrix $S_B$ has rank 1.
    3. The Fisher direction is always parallel to $m_2 - m_1$.
    4. With $K$ classes, LDA yields at most $K - 1$ directions with a non-zero eigenvalue.

    (A): $c$ appears squared in numerator and denominator. (C): look at the hard question above.

    (A) True: both quadratic forms pick up $c^2$, which cancels.

    (B) True: $S_B = vv^\top$ with $v = m_2 - m_1 \ne 0$.

    (C) False: $u^* \propto S_W^{-1}(m_2 - m_1)$, which is parallel to $m_2 - m_1$ only in special cases, such as $S_W$ a multiple of $I$.

    (D) True: $S_B$ is a sum of $K$ rank-one terms whose vectors $m_k - m$ satisfy one linear relation (their weighted sum is 0), so its rank is at most $K - 1$.

    Answer: A; B; D.

    A nearest-mean classifier has $\mu_{red} = (1, 2)$ and $\mu_{green} = (5, 4)$. Its decision boundary is a straight line. At what value of $x_1$ does that line cross the $x_1$-axis?

    Write $f(x) = 2(\mu_{green} - \mu_{red})^\top x + \norm{\mu_{red}}^2 - \norm{\mu_{green}}^2$ and solve $f = 0$ with $x_2 = 0$.

    $w = 2(4, 2) = (8, 4)$ and $b = (1 + 4) - (25 + 16) = -36$. The boundary is $8x_1 + 4x_2 = 36$, that is $2x_1 + x_2 = 9$.

    At $x_2 = 0$: $x_1 = $ 4.5.

    Check: the boundary is the perpendicular bisector of the segment between the means. Its midpoint $(3, 3)$ satisfies $2\cdot3 + 3 = 9$, and the line’s normal $(2, 1)$ is parallel to $\mu_{green} - \mu_{red} = (4, 2)$. A common slip is to forget the $b$ term and answer 0, or to use the midpoint’s $x_1 = 3$.

    • Remember the recipe: means, then $S_W$, then $u^* \propto S_W^{-1}(m_2 - m_1)$.
    • Use the “gap squared over spread” reading of $J$ to sanity-check answers.
    • Expand squared distances to show a nearest-mean boundary is linear.
    • Writing $S_B^{-1}S_W$ or $S_BS_W$ instead of $S_W^{-1}S_B$.
    • Assuming the best direction is the line joining the means.
    • Calling the nearest-mean rule quadratic because of the squares: the $\norm{x}^2$ terms cancel.
    1. Fisher’s LDA maximises J(u) = u⊤S_B u / u⊤S_W u: projected means far apart, each class tight.
    2. The optimum solves S_W⁻¹S_B u = λu with λ = J(u); for two classes u ∝ S_W⁻¹(m₂ − m₁).
    3. The nearest-mean classifier is linear: f(x) = 2(μ_g − μ_r)⊤x + ‖μ_r‖² − ‖μ_g‖², the perpendicular bisector of the means.

    You must squash two-dimensional data from two classes onto a single line and still tell the classes apart. The best line is the one where

    the overall spread of all the points is largest
    That’s what PCA looks for, and it ignores the labels; the spread could be within a class.
    the projected class means are far apart and each class stays tightly packed
    That’s Fisher’s criterion: gap squared divided by within-class spread.
    the projected class means are as far apart as possible, whatever the spread
    Large overlapping spreads can make far-apart means useless. Try the widget’s mean-difference button.
    the line passes through both class means
    That’s the mean-difference direction; it ignores the shape of the clouds.

    For two classes, the Fisher direction is proportional to

    $m_2 - m_1$
    Only when $S_W$ is a multiple of the identity. In general the within-class scatter tilts it.
    the top eigenvector of $S_W$
    That direction is where the classes are most spread out: the worst choice.
    $S_W^{-1}(m_2 - m_1)$
    From $S_Bu = \lambda S_Wu$, with $S_Bu$ always a multiple of $m_2 - m_1$.
    $S_B^{-1}(m_2 - m_1)$
    $S_B$ has rank 1 and is not invertible when $d \ge 2$.

    The decision boundary of a nearest-mean classifier with two classes is

    a circle around one of the means
    Expand the squared distances: the $\norm{x}^2$ terms cancel.
    the line through the two means
    Points on that line can be closer to either mean. Where are points equally close to both?
    a parabola
    No squared terms in $x$ survive.
    the perpendicular bisector of the segment joining the means
    The set of points equidistant from two points is their perpendicular bisector, a hyperplane.

    Which of these models is discriminative?

    Naive Bayes
    It models $P(x\mid y)P(y)$, then uses Bayes’ theorem: generative.
    Logistic regression
    It models $P(y\mid x)$ directly.
    Gaussian discriminant analysis
    It models each class as a Gaussian, $P(x\mid y)$: generative, despite “discriminant” in the name.
    PCA
    PCA isn’t a classifier at all; it uses no labels.

    A naive Bayes classifier computes prior × likelihood scores of 0.03 for Win and 0.01 for Loss. $P(\text{Win}\mid x)$ is

    0.03
    That’s the unnormalised score. Divide by the total.
    0.3
    Recompute: the total of the two scores is 0.04.
    0.75
    $0.03 / (0.03 + 0.01)$.
    0.97
    Normalise by the sum of the class scores, not by 1.

    If $u$ maximises the Fisher criterion $J(u)$, then so does

    only $u/\norm{u}$
    Any non-zero multiple works, not only the unit vector.
    $-3u$
    $J(cu) = J(u)$ for every $c \ne 0$: the factor $c^2$ cancels.
    $S_W u$
    Multiplying by a matrix changes the direction in general.
    $u + (m_2 - m_1)$
    Adding a vector changes the direction.

    A logistic regression model labels a match “Win” when $P(\text{Win}\mid x) \ge t$. Raising the threshold $t$ from 0.5 to 0.9 typically makes the “Win” predictions

    higher in both precision and recall
    Fewer matches are called “Win” at all. What does that do to the share of actual wins you catch?
    lower in precision, higher in recall
    That’s what lowering the threshold tends to do.
    higher in precision, lower in recall
    Only very confident cases are called “Win”, so they’re more often right (precision up) but more real wins are missed (recall down).
    unchanged, because the boundary is still linear
    The boundary stays linear but shifts parallel, so the predictions change.

    Logistic regression is trained on linearly separable data. Adding an L2 penalty $\lambda\norm{w}^2$ to the cross-entropy loss (as in ridge regression)

    keeps the weights finite instead of letting them grow without bound
    Without the penalty, scaling a separating $w$ up always lowers the loss; the penalty stops that.
    makes the decision boundary curved
    The model is still $\sigma(w^\top x + b)$, so the boundary is still a hyperplane.
    sets some weights exactly to zero
    That’s typical of an L1 penalty (lasso), not L2.
    has no effect, because the data are separable
    Separable data is exactly when the unpenalised weights blow up.

    Three classifiers that think in pictures. k-nearest neighbours copies the label of the most similar past examples. A support vector machine draws the line with the widest empty street around it. A decision tree asks a short chain of yes/no questions. Between them they have produced a question in every GATE DA paper: support vectors, the margin, the smallest k that flips a prediction, an information gain.

    You need: features, labels and training sets from Part 1; the bias–variance trade-off and cross-validation from Part 2; linear classifiers and decision boundaries from Part 3; dot products and lengths of vectors from the vectors refresher; logarithms base 2.

    k-nearest neighbours: ask the most similar examples

    k-nearest neighbours (kNN) labels a new point by finding the $k$ training points closest to it and taking a majority vote of their labels.

    GATE DA 2024 Q63 (2 marks) gave five points on a grid and asked for the smallest odd $k$ that flips a prediction; kNN also turns up in options about overfitting and scaling.

    It’s like guessing a new neighbour’s favourite team by asking the three nearest houses on the street and going with the majority.

    Where it shows up in GATE DA

    A small grid of labelled points, a query point, and “what does kNN predict for this k?”

    2024 Q63 · smallest odd k for “square”
    Heat: 1 question in 3 papers, 2 marks; quick marks once distances are listed
    DPL story

    The Haryana Heuristics have signed a new batter and want to know what kind of player they are: an anchor (bats long, scores steadily) or a hitter (scores fast, gets out more). The scouts have scored every batter in the league on two numbers from 0 to 10: consistency and power. The new batter scores 4.9 and 4.9.

    The scouts’ rule of thumb: find the three existing batters whose two numbers are closest to the new one’s, and go with what most of them are. That rule is the whole algorithm.

    Some words from Part 1, in this setting. Each batter is a data point. The two numbers describing them are features (here $x_1$ = consistency, $x_2$ = power), so each batter is a point $\x = (x_1, x_2)$ on a plane. The answer we want to predict, anchor or hitter, is the label. The batters whose labels we already know form the training set. The new batter is the query.

    kNN has no formula to fit. It stores the training set and does all its work when a query arrives. Because it postpones the work, it is called a lazy learner.

    For points $\x = (x_1, \ldots, x_d)$ and $\z = (z_1, \ldots, z_d)$ with $d$ features:

    Euclidean distance (the straight-line, ruler distance): $$\norm{\x - \z} = \sqrt{(x_1 - z_1)^2 + \cdots + (x_d - z_d)^2}.$$ Manhattan distance (walking along a city grid): $$|x_1 - z_1| + \cdots + |x_d - z_d|.$$ Example: from $(1, 2)$ to $(4, 6)$ the Euclidean distance is $\sqrt{3^2 + 4^2} = 5$ and the Manhattan distance is $3 + 4 = 7$.

    Given a training set $(\x_1, y_1), \ldots, (\x_n, y_n)$, a number $k$ and a query $\x$:

    1. Compute the distance from $\x$ to every training point.
    2. Keep the $k$ training points with the smallest distances: the $k$ nearest neighbours.
    3. Classification: predict the label that occurs most often among them (majority vote). Regression (a number to predict): predict the average of their values.

    There is no training step. Predicting one query costs $n$ distance computations, each over $d$ features.

    Try it

    Drag the diamond (the new batter). The dashed circle passes through the $k$-th nearest neighbour, so everything inside it gets a vote. Set $k = 1$ and watch the shaded regions become jagged islands around single points; raise $k$ towards 15 and they smooth out until the larger class takes over. Try an even $k$ near the border to see a tied vote, and switch to Manhattan distance to see the circle turn into a diamond.

    Choosing k

    Small $k$ (say 1) follows every training point, including odd ones. With $k = 1$ each training point is its own nearest neighbour, so the training error is zero (as long as no two identical points carry different labels). The boundary is jagged and the model reacts to noise: low bias, high variance, in the language of Part 2.

    Large $k$ averages over many points, so the boundary is smooth. Push it to $k = n$ and every query gets the same answer: the majority class of the whole training set. That is high bias.

    So $k$ is a hyperparameter: a setting you choose rather than learn from the data. The usual way to choose it is cross-validation. With two classes, pick an odd $k$ so the vote cannot tie.

    Two kinds of tie

    A vote tie (two hitters, two anchors with $k = 4$) is avoided by odd $k$. A distance tie happens when the $k$-th and $(k+1)$-th neighbours are equally far. Exam questions are set so that it doesn’t matter, but check: list the distances in order and see whether the cut-off falls in the middle of a tie.

    Scaling the features

    Distance adds up differences across features, so a feature measured in big units swamps the others. If one feature is an auction price in lakh rupees (from 20 to 1500) and the other is age in years (18 to 40), the price difference decides almost every distance. The fix is to put features on a common scale first, for example min–max scaling $x \mapsto \frac{x - \min}{\max - \min}$ (everything between 0 and 1) or standardising $x \mapsto \frac{x - \bar x}{s}$ (mean 0, standard deviation 1).

    Careful: multiplying every feature by the same positive number never changes a kNN prediction (all distances scale together, so their order stays the same). Rescaling one feature can change it completely.
    Go deeper: the shape of the 1-NN boundary, and many features

    With $k = 1$ the plane splits into one cell per training point: the region closer to that point than to any other (a Voronoi cell). Between two neighbouring points the boundary is their perpendicular bisector, so the 1-NN decision boundary is made of straight pieces of bisectors between points of different classes.

    With many features, distances behave strangely: in 100 dimensions the nearest and farthest training points from a query are often almost equally far, so “nearest” loses its meaning. This is the curse of dimensionality, and it is why kNN works best with a modest number of well-scaled features.

    GATE DA 2024 · Q63 · NAT · 2 marks

    Given the two-dimensional dataset consisting of 5 data points from two classes (circles and squares) and assume that the Euclidean distance is used to measure the distance between two points. The minimum odd value of $k$ in $k$-nearest neighbor algorithm for which the diamond (⋄) shaped data point is assigned the label square is ______.

    (Figure redrawn from the paper.)

    1. Read the points: circles at $(1,1)$ and $(1,2)$; squares at $(2,3)$, $(3,3)$ and $(3,2)$; the diamond (the query) at $(2,1)$.

      Writing coordinates down first stops you misreading a point mid-calculation.

    2. Distances from $(2,1)$: to $(1,1)$ it is $1$; to $(1,2)$ it is $\sqrt{1+1} = \sqrt2 \approx 1.41$; to $(3,2)$ also $\sqrt2$; to $(2,3)$ it is $2$; to $(3,3)$ it is $\sqrt{1+4} = \sqrt5 \approx 2.24$.

      Euclidean distance: square the differences in each coordinate, add, take the square root.

    3. Sorted: circle (1), circle ($\sqrt2$), square ($\sqrt2$), square (2), square ($\sqrt5$).

      kNN only cares about the order of the distances.

    4. $k = 1$: one circle, so circle. $k = 3$: two circles and one square, so circle. (The 2nd and 3rd are tied at $\sqrt2$, but $k = 3$ takes both, so the tie does not matter.)

      The question asks for odd $k$, so even values are skipped.

    5. $k = 5$: two circles and three squares, so square. The answer is 5.

      The two circles are the closest points, so the squares can only outvote them once all five points vote. Official key: 5.

    List every training point with its squared distance (no square roots needed: squaring keeps the order). Sort once. Then read off the vote for each $k$ by counting labels from the top of the list.

    Find the Euclidean and the Manhattan distance between the batters $(1, 2)$ and $(4, 6)$.

    The differences are 3 and 4. Euclidean: square, add, square root. Manhattan: add the absolute differences.

    Euclidean: $\sqrt{3^2 + 4^2} = \sqrt{25} = 5$. Manhattan: $3 + 4 = 7$. Manhattan is never smaller than Euclidean, because walking along the grid is never shorter than the straight line.

    Training points: $(1,1)$ class A, $(2,2)$ class A, $(4,3)$ class B, $(5,2)$ class B, $(3,5)$ class B. Using Euclidean distance, what does kNN predict for the query $(3,2)$ with $k = 1$, and then with $k = 3$?

    Squared distances from $(3,2)$: 5, 1, 2, 4, 9.

    Distances: $(2,2)$ A: 1; $(4,3)$ B: $\sqrt2$; $(5,2)$ B: 2; $(1,1)$ A: $\sqrt5$; $(3,5)$ B: 3.

    $k = 1$: the nearest is $(2,2)$, class A. $k = 3$: A, B, B, so B. Answer: A then B. A single close point can win at $k = 1$ and be outvoted as soon as more neighbours join.

    A kNN model describes DPL players by auction price (in lakh rupees, between 20 and 1500) and age (in years, between 18 and 40), with no scaling. Which feature mostly decides who counts as a “nearest” neighbour?

    Compare a typical difference in price with a typical difference in age.

    Price. Two players can differ by hundreds of lakhs but by at most 22 years, and the squared differences are added, so price dominates. Min–max scaling or standardising both features first gives them equal say.

    kNN can also predict numbers. Past matches at one ground had grass length (mm) and first-innings score: (2, 160), (4, 172), (5, 180), (7, 150), (9, 140). Predict the score for grass length 5.4 by averaging the scores of the 3 nearest matches. (Round to two decimal places.)

    Distances from 5.4: 3.4, 1.4, 0.4, 1.6, 3.6.

    The three nearest are 5 (0.4 away), 4 (1.4) and 7 (1.6), with scores 180, 172 and 150. Average: $\frac{180 + 172 + 150}{3} = \frac{502}{3} \approx$ 167.33.

    Seven players are described by one feature with labels: 1.0 (A), 2.0 (A), 3.5 (B), 4.2 (A), 6.1 (B), 7.1 (B), 9.0 (A). In leave-one-out evaluation each point in turn is removed, classified by kNN using the other six, and counted as an error if the prediction is wrong. How many errors does 1-NN make, and how many does 3-NN make?

    For each point, list its distances to the other six (never to itself). For 3-NN, take a majority of the three closest.

    1-NN. 1.0 → 2.0 (A) right; 2.0 → 1.0 (A) right; 3.5 → 4.2 (A) wrong; 4.2 → 3.5 (B) wrong; 6.1 → 7.1 (B) right; 7.1 → 6.1 (B) right; 9.0 → 7.1 (B) wrong. Errors: 3.

    3-NN. 1.0: 2.0 A, 3.5 B, 4.2 A → A, right. 2.0: 1.0 A, 3.5 B, 4.2 A → A, right. 3.5: 4.2 A, 2.0 A, 1.0 A (2.5) → A, wrong. 4.2: 3.5 B, 6.1 B, 2.0 A → B, wrong. 6.1: 7.1 B, 4.2 A, 3.5 B → B, right. 7.1: 6.1 B, 9.0 A, 4.2 A → A, wrong. 9.0: 7.1 B, 6.1 B, 4.2 A → B, wrong. Errors: 4.

    A larger $k$ is not automatically better: here the lone A at 9.0 still loses, and 7.1 now gets outvoted. The tempting slip is to include the point itself among its neighbours, which makes 1-NN look perfect.

    Two known players: P = (40 runs, 1 wicket per match), a batter; Q = (30 runs, 4 wickets), an all-rounder. A new player has (36 runs, 3.5 wickets). Runs range from 0 to 100 and wickets from 0 to 5. What does 1-NN with Euclidean distance predict on the raw features, and after min–max scaling each feature by its range?

    1. batter, then batter
    2. batter, then all-rounder
    3. all-rounder, then batter
    4. all-rounder, then all-rounder

    Scaling here means dividing runs by 100 and wickets by 5. Compute both distances in both versions.

    Raw: to P, $\sqrt{4^2 + 2.5^2} = \sqrt{22.25} \approx 4.72$; to Q, $\sqrt{6^2 + 0.5^2} = \sqrt{36.25} \approx 6.02$. Nearest is P: batter.

    Scaled: P = (0.40, 0.20), Q = (0.30, 0.80), new = (0.36, 0.70). To P, $\sqrt{0.04^2 + 0.5^2} \approx 0.502$; to Q, $\sqrt{0.06^2 + 0.1^2} \approx 0.117$. Nearest is Q: all-rounder. Answer (B).

    On raw numbers the 10-run gap looks large and the 3-wicket gap small, yet 3 wickets is most of the wicket range. (A) is what you get if you forget to scale; (C) and (D) come from mixing up which point is closer.

    Which statements about kNN classification (unweighted majority vote) are true? Assume no two training points are identical.

    1. With $k = 1$, the error on the training set itself is zero.
    2. With $k = n$ (the whole training set), every query gets the training set’s majority class.
    3. Increasing $k$ always lowers the error on new data.
    4. Multiplying every feature by 10 can change some predictions.

    For (D), think about what happens to the order of the distances.

    (A) True: each training point is at distance 0 from itself, so it predicts its own label. (B) True: all $n$ points vote whatever the query, so the answer never changes. (C) False: too large a $k$ underfits (Ch. 4.1 hard question 1 shows a larger $k$ doing worse). (D) False: every distance is multiplied by 10, so the order and the neighbours are unchanged. Only scaling features differently can change predictions. Answer: A; B.

    • Write all distances in a sorted list before voting; use squared distances to skip square roots.
    • Scale features to comparable ranges before using distances.
    • Choose odd $k$ for two classes, and pick $k$ by cross-validation.
    • Counting the query itself as one of its neighbours when it is a training point (leave-one-out).
    • Assuming larger $k$ is always better: very large $k$ just predicts the majority class.
    • Forgetting that an even $k$ can tie, and that the $k$-th distance can tie with the next.
    1. kNN stores the training data and, for a query, takes a majority vote of the k closest points (an average for regression).
    2. Small k: jagged boundary, low bias, high variance (k = 1 has zero training error). Large k: smooth boundary, high bias; k = n predicts the majority class.
    3. Distances depend on units: scale features first; prefer odd k for two classes.

    A new batter’s nearest neighbour is an anchor at distance 0.5. The next two are hitters at distances 0.9 and 1.0. What does 3-NN predict?

    Anchor, because it is the closest
    Closeness only decides who gets a vote. Once inside the top 3, each neighbour’s vote counts the same.
    Hitter
    The three nearest are one anchor and two hitters, and the majority wins.
    A tie
    With three voters and two classes, one class always has at least two votes.
    It can’t be decided without the other points
    For 3-NN only the three nearest points matter, and you know all of them.

    Why do people choose an odd $k$ for a two-class kNN problem?

    Odd $k$ makes the boundary linear
    The boundary’s shape doesn’t depend on whether $k$ is odd. Think about the vote count.
    Odd $k$ gives zero training error
    Only $k = 1$ guarantees that.
    So the majority vote can never be tied
    With two classes and an odd number of votes, one class always has more.
    Odd $k$ removes the need to scale features
    Scaling is about the units of the features, not about $k$.

    A training set has 60 hitters and 40 anchors. kNN is run with $k = 100$ (all of them). What does it predict for a new batter who is extremely close to one anchor?

    Anchor
    Every one of the 100 points gets a vote, wherever the query is.
    Hitter
    With $k = n$, all 100 points vote every time: 60 to 40 for hitter, whatever the query.
    It depends on the distance measure
    With all points voting, distances no longer matter.
    A tie
    60 against 40 is not a tie.

    Support vector machines: the widest street between two classes

    A support vector machine (SVM) separates two classes with the straight line (or flat plane) that stays as far as possible from the nearest points of both classes.

    SVMs have appeared in every GATE DA paper so far: 2024 Q17 (which points are support vectors), 2024 Q53 (which datasets are linearly separable), 2025 Q53 (find $w$, $b$ and the margin) and the sample paper’s Q29 (what happens if you delete a point).

    It’s like painting a road between two villages: you want the widest road that touches no house, and only the houses at the very edge of the road decide where it goes.

    Where it shows up in GATE DA

    Small 2-D datasets: find the separator, the support vectors or the margin, or decide whether a line can separate the classes at all.

    2024 Q17 · possible support vectors2025 Q53 · w, b, margin √22024 Q53 · linearly separable?Sample Q29 · remove a non-support vector
    Heat: every year, 1 to 2 questions, 1–2 marks each
    DPL story

    The Hyderabad Hyperplanes’ analyst plots last season’s matches on two numbers: run rate in the first six overs ($x_1$) and run rate at the death ($x_2$). Wins and losses fall into two clouds, and many straight lines separate them. Which line should they trust for next season? A line that grazes a past win will misjudge the next similar match. The safest line keeps the biggest gap to both clouds.

    Recall from Part 3 that a linear classifier computes a score $\w\cdot\x + b$ and predicts by its sign: $f(\x) = \text{sign}(\w\cdot\x + b)$, which is $+1$ on one side and $-1$ on the other. Here $\w$ is a vector of weights (one per feature) and $b$ is a number called the bias. Labels are written $y = +1$ and $y = -1$.

    The decision boundary is where the score is zero: $\w\cdot\x + b = 0$. In two dimensions this is a straight line; in three, a flat plane; in general it is called a hyperplane, meaning a flat boundary with one dimension fewer than the space. Example: $\w = (1, 1)$, $b = -1$ gives the line $x_1 + x_2 = 1$.

    How far is a point from the line?

    Two facts from the vectors refresher do all the work. First, $\w$ points straight across the boundary (it is perpendicular to it): if $\x$ and $\x'$ are both on the boundary, $\w\cdot\x + b = \w\cdot\x' + b = 0$, so $\w\cdot(\x - \x') = 0$. Second, if you step a distance $t$ along the unit vector $\w/\norm{\w}$, the score changes by exactly $t\,\norm{\w}$. So a point whose score is $s$ is $|s|/\norm{\w}$ away from the place where the score is zero.

    The distance from a point $\x_0$ to the hyperplane $\w\cdot\x + b = 0$ is $$\text{dist} = \frac{|\w\cdot\x_0 + b|}{\norm{\w}}.$$ Example: from $(3, 4)$ to $3x_1 + 4x_2 - 5 = 0$ the distance is $\frac{|9 + 16 - 5|}{\sqrt{9 + 16}} = \frac{20}{5} = 4$.

    The margin and the support vectors

    Multiplying $\w$ and $b$ by the same positive number gives the same line, so we are free to fix the scale. The SVM convention: scale them so that the training points closest to the line have score exactly $+1$ (on the positive side) or $-1$ (on the negative side). Every training point then satisfies $y_i(\w\cdot\x_i + b) \ge 1$.

    With that scale, the closest points are $1/\norm{\w}$ from the boundary, and the empty “street” between the lines $\w\cdot\x + b = +1$ and $\w\cdot\x + b = -1$ is $2/\norm{\w}$ wide. That width is the margin. The training points lying exactly on the two edges of the street are the support vectors: they “support” the street the way pillars hold up a roof.

    For training data $(\x_i, y_i)$ with $y_i \in \{+1, -1\}$, the hard-margin SVM solves $$\min_{\w,\,b}\ \tfrac12\norm{\w}^2 \quad\text{subject to}\quad y_i(\w\cdot\x_i + b) \ge 1 \text{ for every } i.$$ Making $\norm{\w}$ small makes the margin $2/\norm{\w}$ large. The constraints say every point is on its correct side, at least on the edge of the street. The support vectors are the points with $y_i(\w\cdot\x_i + b) = 1$.

    Careful with the word “margin”: some books use it for the distance from the boundary to the nearest point, $1/\norm{\w}$. GATE DA 2025 Q53 uses the full street width $2/\norm{\w}$. If both appear in the options, read the question’s wording; if only one fits, that tells you the convention.

    The solution can be written $\w = \sum_i \alpha_i y_i \x_i$ with weights $\alpha_i \ge 0$, and $\alpha_i \gt 0$ only for support vectors. Moving or deleting a point that is not a support vector (while it stays outside the street) leaves $\w$, $b$ and the margin unchanged.

    Try it

    Choose “Your direction” and turn the slider: for each direction of $\w$ the widget draws the widest street that direction allows. Find the angle with the widest street, then switch to “Maximum margin” to compare. Drag a point that is not ringed: nothing moves until it enters the street. Drag one into the other cloud and the data stops being separable. Finally load “2025 Q53” and “2024 Q17” and read off $\w$, $b$, the margin and the points on the margin lines.

    GATE DA 2025 · Q53 · MSQ · 2 marks

    Consider designing a linear binary classifier $f(x) = \text{sign}(w^\top x + b)$, $x \in \R^2$ on the following training data:

    Class-1: $\left\{\begin{pmatrix}2\\0\end{pmatrix}, \begin{pmatrix}0\\2\end{pmatrix}, \begin{pmatrix}2\\2\end{pmatrix}\right\}$, Class-2: $\left\{\begin{pmatrix}0\\0\end{pmatrix}\right\}$

    Hard-margin support vector machine (SVM) formulation is solved to obtain $w$ and $b$. Which of the following options is/are correct?

    1. $w = \begin{pmatrix}4\\4\end{pmatrix}$ and $b = 1$
    2. The number of support vectors is 3
    3. The margin is $\sqrt2$
    4. Training accuracy is 98%
    1. Picture it. Class-1 is $(2,0)$, $(0,2)$, $(2,2)$; Class-2 is the origin. Take Class-1 as $y = +1$. The Class-1 points nearest the origin are $(2,0)$ and $(0,2)$, both on the line $x_1 + x_2 = 2$; $(2,2)$ is farther out, on $x_1 + x_2 = 4$.

      The support vectors are the points closest to the other class, so find those first.

    2. The widest street runs between the origin (on $x_1 + x_2 = 0$) and the line $x_1 + x_2 = 2$. So $\w$ points along $(1, 1)$ and the boundary is halfway: $x_1 + x_2 = 1$.

      No street can be wider: the origin is $\sqrt2$ from the point $(1,1)$, the midpoint of $(2,0)$ and $(0,2)$, and any separating street must fit between them.

    3. Fix the scale: $\w = c(1,1)$ with score $-1$ at $(0,0)$ and $+1$ at $(2,0)$: $b = -1$ and $2c - 1 = 1$, so $c = 1$. Hence $\w = (1, 1)$, $b = -1$.

      The SVM scale puts the nearest points of each class at scores $\pm1$.

    4. Scores: $(2,0)$ and $(0,2)$ give $+1$, $(0,0)$ gives $-1$, $(2,2)$ gives $+3$. Three points on the margin lines, so three support vectors: (B) is true.

      A support vector is a point with $y_i(\w\cdot\x_i + b) = 1$ exactly.

    5. Margin $= 2/\norm{\w} = 2/\sqrt2 = \sqrt2$: (C) is true. Check with the distance formula: $(0,0)$ is $|0 + 0 - 1|/\sqrt2 = 1/\sqrt2$ from the boundary, and the street is twice that.

      This question calls the full street width the margin.

    6. (A) is false: with $\w = (4,4)$, $b = 1$, the origin scores $+1$, the same sign as Class-1, so it is misclassified (and the scale is wrong too). (D) is false: the data are separable and a hard-margin SVM classifies every training point correctly, so training accuracy is 100%.

      Hard margin means no training point may be on the wrong side. Official key: B; C.

    When no line works: soft margins and kernels

    A dataset is linearly separable if some hyperplane has every positive point on one side and every negative point on the other. The hard-margin SVM only has a solution for separable data.

    A quick test for “not separable”: if a point of one class is an average of points of the other class (it sits inside their convex hull, the region you get by stretching a rubber band around them), no line can separate them. The score $\w\cdot\x + b$ of an average is the average of the scores, so it cannot have the opposite sign to all of them.

    Allow each point a slack $\xi_i \ge 0$ (how far it is allowed to violate the street) and pay for it: $$\min_{\w,\,b,\,\xi}\ \tfrac12\norm{\w}^2 + C\sum_i \xi_i \quad\text{subject to}\quad y_i(\w\cdot\x_i + b) \ge 1 - \xi_i,\ \ \xi_i \ge 0.$$ $\xi_i = 0$: on the correct side, outside the street. $0 \lt \xi_i \le 1$: inside the street but still correct. $\xi_i \gt 1$: misclassified.

    The hyperparameter $C$ sets the price of violations. Large $C$: violations are expensive, so the street narrows to avoid them (as $C \to \infty$ on separable data you get the hard margin). Small $C$: a wider street that tolerates more violations, usually less overfitting.

    The other way out is to add features. A kernel lets the SVM work as if each point $\x$ had been mapped to a longer feature vector $\phi(\x)$, without ever building that vector: the SVM only ever needs dot products between points, and a kernel function $k(\x, \z) = \phi(\x)\cdot\phi(\z)$ supplies them directly. A straight boundary in the new features is a curved boundary in the original ones.

    Linear: $k(\x, \z) = \x\cdot\z$ (the plain SVM). Polynomial: $k(\x, \z) = (\x\cdot\z + c)^p$. RBF (Gaussian): $k(\x, \z) = \exp(-\gamma\norm{\x - \z}^2)$. Example: in two dimensions $(\x\cdot\z)^2 = \phi(\x)\cdot\phi(\z)$ with $\phi(\x) = (x_1^2,\ \sqrt2\,x_1x_2,\ x_2^2)$, so the kernel computes a dot product in three dimensions while only touching two.

    Go deeper: the dual problem and the hinge loss

    The hard-margin problem has an equivalent “dual” form in the weights $\alpha_i$: maximise $\sum_i \alpha_i - \tfrac12\sum_{i,j}\alpha_i\alpha_j y_i y_j\,\x_i\cdot\x_j$ subject to $\alpha_i \ge 0$ and $\sum_i \alpha_i y_i = 0$. The data enter only through dot products $\x_i\cdot\x_j$, which is exactly why kernels can be swapped in. Points with $\alpha_i \gt 0$ are the support vectors. When several points lie on the margin lines (2024 Q17 has four), a solver may give positive weight to only some of them; all of them are on the margin and are usually called support vectors.

    The soft-margin problem is the same as minimising $\tfrac12\norm{\w}^2 + C\sum_i \max(0,\ 1 - y_i(\w\cdot\x_i + b))$. The term $\max(0, 1 - y\,s)$ is the hinge loss: zero for points safely outside the street, growing linearly with the violation.

    An SVM has $\w = (3, 4)$ and $b = -5$, already scaled so that the support vectors have scores $\pm1$. Find the distance of the point $(3, 4)$ from the boundary, and the margin $2/\norm{\w}$.

    $\norm{\w} = 5$. The score of $(3,4)$ is $9 + 16 - 5$.

    Distance $= |3\cdot3 + 4\cdot4 - 5|/5 = 20/5 = 4$. Margin $= 2/5 = 0.4$. A bigger $\norm{\w}$ always means a narrower street.

    GATE DA 2024 · Q17 · MCQ · 1 mark

    Consider the dataset with six datapoints: $\{(\x_1, \y_1), (\x_2, \y_2), \ldots, (\x_6, \y_6)\}$, where $\x_1 = \begin{bmatrix}1\\0\end{bmatrix}$, $\x_2 = \begin{bmatrix}0\\1\end{bmatrix}$, $\x_3 = \begin{bmatrix}0\\-1\end{bmatrix}$, $\x_4 = \begin{bmatrix}-1\\0\end{bmatrix}$, $\x_5 = \begin{bmatrix}2\\2\end{bmatrix}$, $\x_6 = \begin{bmatrix}-2\\-2\end{bmatrix}$ and the labels are given by $\y_1 = \y_2 = \y_5 = 1$, and $\y_3 = \y_4 = \y_6 = -1$. A hard margin linear support vector machine is trained on the above dataset.

    Which ONE of the following sets is a possible set of support vectors?

    1. $\{\x_1, \x_2, \x_5\}$
    2. $\{\x_3, \x_4, \x_5\}$
    3. $\{\x_4, \x_5\}$
    4. $\{\x_1, \x_2, \x_3, \x_4\}$

    Plot the six points. The positive points nearest the negatives are $\x_1$ and $\x_2$, on the line $x_1 + x_2 = 1$. Where are the nearest negative points?

    The positives $\x_1, \x_2$ lie on $x_1 + x_2 = 1$ and the negatives $\x_3, \x_4$ on $x_1 + x_2 = -1$; $\x_5$ and $\x_6$ are far out, on $x_1 + x_2 = \pm4$. The widest street is between those two lines: $\w = (1, 1)$, $b = 0$, and the scores are $\x_1, \x_2: +1$; $\x_3, \x_4: -1$; $\x_5: +4$; $\x_6: -4$. The margin is $2/\sqrt2 = \sqrt2$.

    The points on the margin lines are $\x_1, \x_2, \x_3, \x_4$, so (D). Every other option contains $\x_5$, which is $4/\sqrt2 \approx 2.83$ from the boundary, well outside the street; a point that far away cannot be a support vector. Official key: D.

    GATE DA 2024 · Q53 · MSQ · 2 marks

    Consider the following figures representing datasets consisting of two-dimensional features with two classes denoted by circles and squares.

    Which of the following is/are TRUE?

    1. (i) is linearly separable.
    2. (ii) is linearly separable.
    3. (iii) is linearly separable.
    4. (iv) is linearly separable.

    (Figure redrawn from the paper; positions read from the printed grids.)

    Try to draw a line for each picture. For the ones where you can’t, look for a point of one class that is an average of points of the other class.

    (i) The line $x_2 = x_1 - 0.5$ has all three circles above it and all three squares below it: separable.

    (ii) The circle $(2,2)$ is the midpoint of the squares $(1,2)$ and $(3,2)$. Any linear score at $(2,2)$ is the average of the scores at those two squares, so it has their sign: not separable.

    (iii) This is the XOR pattern. $(2,2)$ is the midpoint of the two circles and also of the two squares, so its score would have to be both positive and negative: not separable.

    (iv) The same line $x_2 = x_1 - 0.5$ has the three squares above and the three circles below: separable.

    Answer: A; D. Official key: A; D.

    GATE DA 2024 sample paper · Q29 · MCQ · 2 marks

    A maximum margin linear SVM (SVM1) is learned for a binary classification task. Another maximum margin linear SVM (SVM2) is trained for the same task using the same training set but with one of the non-support vectors of SVM1 removed. Which one of the following statements is TRUE?

    1. Margin of SVM1 > Margin of SVM2
    2. Margin of SVM2 > Margin of SVM1
    3. Margin of SVM1 = Margin of SVM2
    4. No conclusion can be drawn between the margins of SVM1 and SVM2

    Which training points does the SVM solution actually depend on?

    The SVM solution depends only on the support vectors: solving the problem with just their constraints gives the same street, and every other point was strictly outside it. SVM2 still has all of SVM1’s support vectors, and its street is still valid for the reduced data. So SVM2 finds the same $\w$, $b$ and margin: (C). (Sample paper, no official key; this is our answer.)

    (A) and (B) would need the solution to depend on a point with $\alpha_i = 0$. (D) is the guess for when you don’t remember that only support vectors matter.

    Positive class: $(4,1)$, $(3,3)$, $(5,4)$. Negative class: $(0,0)$, $(1,2)$, $(2,0)$. A hard-margin linear SVM is trained. Find the margin $2/\norm{\w}$ (round to two decimal places) and the number of training points that lie exactly on the margin lines.

    Try the direction $\w \propto (2, 1)$ and compute $2x_1 + x_2$ for every point. For an upper bound on any margin, find the distance between the midpoint of two negative points and the midpoint of two positive points.

    Scores $2x_1 + x_2$: negatives $0, 4, 4$; positives $9, 9, 14$. In the unit direction $(2,1)/\sqrt5$ the classes are separated by a gap of $(9 - 4)/\sqrt5 = \sqrt5$.

    No street can be wider. The midpoint of the negatives $(1,2)$ and $(2,0)$ is $(1.5, 1)$; the midpoint of the positives $(4,1)$ and $(3,3)$ is $(3.5, 2)$. Any separating street must fit between these two points, which are $\sqrt{2^2 + 1^2} = \sqrt5$ apart.

    Scaling: $\w = c(2,1)$ with $4c + b = -1$ and $9c + b = 1$ gives $c = 0.4$, $b = -2.6$, so $\w = (0.8, 0.4)$ and $2/\norm{\w} = 2/\sqrt{0.8} = \sqrt5 \approx$ 2.24.

    Points with score exactly $\pm1$: $(1,2)$, $(2,0)$, $(4,1)$, $(3,3)$, so 4. The tempting slips: using $1/\norm{\w} \approx 1.12$ (half the street), or taking the closest pair of opposite points, $(2,0)$ and $(4,1)$, also $\sqrt5$ apart, and stopping at 2 support vectors without checking the other scores.

    For a soft-margin linear SVM with penalty $C$ and slacks $\xi_i$, which statements are true?

    1. On linearly separable data, as $C \to \infty$ the solution approaches the hard-margin SVM.
    2. Increasing $C$ typically makes the margin wider.
    3. A training point with $\xi_i \gt 1$ is misclassified.
    4. A point strictly outside the street on its correct side has $\xi_i = 0$, and moving it a little (staying outside) does not change $\w$.

    $C$ is the price per unit of violation. What does the optimiser do when violations become very expensive?

    (A) True: infinitely expensive slack forces every $\xi_i = 0$, which is the hard-margin problem. (B) False: larger $C$ punishes violations more, so the street usually narrows to avoid them; small $C$ gives the wider street. (C) True: $y_i(\w\cdot\x_i + b) \ge 1 - \xi_i$ with the smallest allowed slack means the score has the wrong sign when $\xi_i \gt 1$. (D) True: such a point has $\alpha_i = 0$, so it does not appear in $\w = \sum\alpha_i y_i \x_i$. Answer: A; C; D.

    The XOR data: circles at $(1,1)$ and $(3,3)$, squares at $(1,3)$ and $(3,1)$. You add one new feature $z$ and train a linear SVM on $(x_1, x_2, z)$. Which choice of $z$ makes the data linearly separable?

    1. $z = x_1 + x_2$
    2. $z = (x_1 - 2)(x_2 - 2)$
    3. $z = x_1 - x_2$
    4. $z = x_1^2$

    A feature that is a linear combination of $x_1$ and $x_2$ adds nothing a line couldn’t already do. For the others, compute $z$ at all four points.

    (B): $z = (-1)(-1) = 1$ at $(1,1)$ and $1\cdot1 = 1$ at $(3,3)$, but $z = -1$ at $(1,3)$ and $(3,1)$. The plane $z = 0$ separates them.

    (A) and (C) are linear in $x_1, x_2$, so any linear rule in $(x_1, x_2, z)$ is still a linear rule in $(x_1, x_2)$, and XOR is not linearly separable. (D) fails too: a rule $a x_1 + c x_2 + e x_1^2 + d$ at $x_1 = 1$ needs $c \lt 0$ (circle at $x_2 = 1$ above, square at $x_2 = 3$ below), while at $x_1 = 3$ it needs $c \gt 0$. Answer (B). A degree-2 polynomial kernel contains exactly this product $x_1x_2$.

    • Sketch the points; the support vectors are the ones nearest the other class.
    • Fix the scale so the support vectors score exactly $\pm1$, then use $2/\norm{\w}$.
    • Check every point’s score at the end: all positives $\ge 1$, all negatives $\le -1$.
    • Reporting $1/\norm{\w}$ when the question means the full street width (or the reverse).
    • Believing a far-away point can be a support vector, or that deleting it changes the margin.
    • Saying "large $C$ means a wider margin": it is the other way round.
    1. Distance from x₀ to the hyperplane w·x + b = 0 is |w·x₀ + b| / ‖w‖.
    2. The SVM scales w, b so the nearest points score ±1 and minimises ½‖w‖²; the margin is 2/‖w‖ and the points on the margin lines are the support vectors, the only points that matter.
    3. Not separable? A soft margin (penalty C: large C, narrow street) or a kernel (a linear boundary in new features) handles it.

    Many straight lines separate two clouds of points. Which one does a hard-margin SVM pick?

    The one through the midpoint of the two class means
    That uses every point equally. The SVM’s line depends only on the points nearest the other class.
    The one with the fewest misclassified points
    All separating lines make zero mistakes, so that doesn’t pick one out.
    The one farthest from the nearest points of both classes
    It maximises the margin, the width of the empty street around the line.
    The one that passes closest to the most points
    The SVM wants to stay as far from the points as possible.

    An SVM has $\w = (6, 8)$, scaled so the support vectors score $\pm1$. Its margin $2/\norm{\w}$ is

    0.1
    That is $1/\norm{\w}$, the distance to one edge only.
    2
    Divide by the length of $\w$.
    10
    That is $\norm{\w}$ itself.
    0.2
    $\norm{\w} = \sqrt{36 + 64} = 10$, so $2/10 = 0.2$.

    What does the kernel trick let an SVM do?

    Use dot products in a richer feature space without building those features
    The SVM only needs $\phi(\x)\cdot\phi(\z)$, and the kernel computes it directly.
    Skip the optimisation and pick the support vectors directly
    The optimisation still has to be solved; only the dot products change.
    Remove the need for labels
    An SVM is still a supervised method.
    Guarantee zero test error
    A flexible kernel can make it easier to overfit.

    Decision trees: twenty questions, learned from data

    A decision tree predicts by asking a sequence of yes/no questions about the features, each answer sending you down one branch until you reach a leaf that holds the prediction.

    GATE DA 2024 Q62 (2 marks) asked for the information gain of one attribute in a ten-row cricket table: entropy, a weighted average and a subtraction. Expect that kind of calculation, plus questions on overfitting.

    It’s like a doctor’s checklist: “Fever? Yes. Rash? No. Cough? Yes. Then probably flu.” Each question is chosen to rule out as much as possible.

    Where it shows up in GATE DA

    Entropy and information gain from a small table; sometimes Gini, overfitting or what a tree can guarantee.

    2024 Q62 · InformationGain(C, Pitch)
    Heat: 1 numerical question in 3 papers, 2 marks; pure arithmetic once the formula is fixed
    DPL story

    The Kalinga Kernels’ coach wants a rule for predicting their own matches. From last season they write a flowchart: “Did we lose more than 2 wickets in the powerplay? If no, we usually win. If yes, were the powerplay runs above 50? …” Each question splits the past matches into two groups, and a good question makes each group as one-sided as possible, nearly all wins or nearly all losses.

    Vocabulary: each question is a node (the first one is the root); each answer is a branch; a node with no more questions is a leaf and predicts the majority label of the training examples that reach it. The number of questions on the longest path is the tree’s depth.

    The learning problem is choosing the questions. We need a number for “how mixed is this group?”, called impurity, and then we pick the question that reduces it most.

    For a group $S$ in which a fraction $p_k$ of the examples has class $k$:

    Entropy (in bits): $$H(S) = -\sum_k p_k \log_2 p_k \qquad (\text{with } 0\log_2 0 = 0).$$ Gini impurity: $$G(S) = 1 - \sum_k p_k^2.$$ Both are 0 for a pure group (one class only) and largest for an even mix. With two classes: $H$ ranges from 0 to 1, $G$ from 0 to 0.5. Example: 3 wins and 1 loss gives $H = -\tfrac34\log_2\tfrac34 - \tfrac14\log_2\tfrac14 \approx 0.811$ and $G = 1 - \tfrac{9}{16} - \tfrac{1}{16} = 0.375$.

    Splitting $S$ on attribute $A$ creates subgroups $S_v$, one for each value $v$ of $A$. The information gain is the drop in entropy: $$\text{IG}(S, A) = H(S) - \sum_v \frac{|S_v|}{|S|}\,H(S_v).$$ The children’s entropies are weighted by their sizes, so a tiny pure child doesn’t count for much. With Gini instead of entropy, the same difference is the Gini decrease.

    1. If all examples at the node have the same label (or no attributes remain, or a size or depth limit is reached), make a leaf with the majority label.
    2. Otherwise compute the information gain of every attribute (for a numeric feature, of every threshold between consecutive sorted values) and split on the best.
    3. Repeat on each child with the examples that reach it.

    This is greedy: at each node it takes the best split right now and never revisits it, so the final tree is not guaranteed to be the best possible tree.

    Try it

    Sixteen Kernels matches (circles won, squares lost). Slide the threshold and watch the counts on each side, their impurities and the gain; the lower chart shows the gain for every threshold at once. Compare “Split on runs” with “Split on wickets” and press “Jump to the best split” for each: the root question is the one with the higher peak. Switch to Gini and check that the best split stays the same here.

    $H$ of a two-class group with minority share: $\tfrac12 \to 1$; $\tfrac25 \to 0.971$; $\tfrac13 \to 0.918$; $\tfrac14 \to 0.811$; $\tfrac15 \to 0.722$; $\tfrac18 \to 0.544$; $0 \to 0$. Most exam tables use these fractions, which saves several logarithms.

    GATE DA 2024 · Q62 · NAT · 2 marks

    Details of ten international cricket games between two teams “Green” and “Blue” are given in Table C. This table consists of matches played on different pitches, across formats along with their winners. The attribute Pitch can take one of two values: spin-friendly (represented as $S$) or pace-friendly (represented as $F$). The attribute Format can take one of two values: one-day match (represented as $O$) or test match (represented as $T$).

    A cricket organization would like to use the information given in Table C to develop a decision-tree model to predict outcomes of future games between these two teams.

    To develop such a model, the computed InformationGain(C, Pitch) with respect to the Target is ______ (rounded off to two decimal places).

    Table C
    Match NumberPitchFormatWinner (Target)
    1$S$$T$Green
    2$S$$T$Blue
    3$F$$O$Blue
    4$S$$O$Blue
    5$F$$T$Green
    6$F$$O$Blue
    7$S$$O$Green
    8$F$$T$Blue
    9$F$$O$Blue
    10$S$$O$Green
    1. Whole table: Green won matches 1, 5, 7, 10 (4 wins) and Blue the other 6. $H(C) = -0.4\log_2 0.4 - 0.6\log_2 0.6 \approx 0.971$.

      Information gain starts from the entropy before any split.

    2. Pitch $= S$: matches 1, 2, 4, 7, 10, winners Green, Blue, Blue, Green, Green: 3 Green, 2 Blue. $H = 0.971$ (minority share $\tfrac25$).

      Filter the rows by the attribute value, then count the target.

    3. Pitch $= F$: matches 3, 5, 6, 8, 9, winners Blue, Green, Blue, Blue, Blue: 1 Green, 4 Blue. $H = -0.2\log_2 0.2 - 0.8\log_2 0.8 \approx 0.722$.

      Minority share $\tfrac15$, one of the values in the shortcut box.

    4. Weighted entropy after the split: $\tfrac{5}{10}(0.971) + \tfrac{5}{10}(0.722) \approx 0.846$.

      Each child is weighted by its share of the rows: 5 of 10 each.

    5. $\text{IG}(C, \text{Pitch}) = 0.971 - 0.846 \approx$ 0.12 (more precisely 0.1245).

      Official key: 0.12 to 0.13. For comparison, Format gives only $0.971 - (0.4\cdot1 + 0.6\cdot0.918) \approx 0.02$, so a tree would ask about Pitch first.

    When trees go wrong: overfitting and pruning

    Keep splitting and every leaf eventually holds one example, so the tree is 100% right on the training data (unless two identical rows disagree). But the deep questions are fitting accidents of last season, not patterns: high variance, in the language of Part 2. Typical symptom: training accuracy near 100%, test accuracy much lower.

    Two remedies. Pre-pruning stops early: a maximum depth, a minimum number of examples per leaf, or a minimum gain for a split. Post-pruning grows the full tree and then removes subtrees whose removal does not hurt accuracy on held-out data (choose the amount by cross-validation).

    Information gain also has a blind spot: it favours attributes with many values. Splitting Table C on “Match Number” gives ten pure leaves, so its gain is the full 0.971, yet it says nothing about future matches. The gain ratio divides the gain by the entropy of the split itself to penalise this.

    With numeric features each question is “feature ≤ threshold?”, so a tree cuts the plane into rectangles with sides parallel to the axes. A diagonal boundary needs many small steps.

    A leaf holds 3 wins and 1 loss. What is its entropy in bits? (Round to two decimal places.)

    $p = \tfrac34$ and $\tfrac14$. $\log_2\tfrac14 = -2$ and $\log_2\tfrac34 \approx -0.415$.

    $H = -\tfrac34(-0.415) - \tfrac14(-2) = 0.311 + 0.5 \approx$ 0.81.

    A node holds 6 wins and 2 losses. What is its Gini impurity?

    $1 - (\tfrac68)^2 - (\tfrac28)^2$.

    $1 - 0.5625 - 0.0625 = $ 0.375. A pure node would give 0; a 4–4 node, 0.5.

    A node has 8 wins and 8 losses. Split A gives children (6 wins, 2 losses) and (2 wins, 6 losses). Split B gives children (8 wins, 4 losses) and (0 wins, 4 losses). Which split has the higher information gain?

    Parent entropy is 1. Use $H(\tfrac14) = 0.811$ and $H(\tfrac13) = 0.918$, and weight by child size.

    A: $1 - \tfrac12(0.811) - \tfrac12(0.811) = 0.189$. B: $1 - \tfrac{12}{16}(0.918) - \tfrac{4}{16}(0) = 1 - 0.689 = 0.311$. Split B wins: a completely pure child is worth a lot. (Gini agrees: decreases 0.125 and 0.167.)

    A fully grown tree is 100% accurate on the training matches but only 68% accurate on new matches. Which change is most likely to help?

    What does the gap between training and test accuracy tell you?

    The gap signals overfitting, so make the tree simpler: limit the depth or prune the tree. Growing deeper makes it worse; entropy and Gini usually choose nearly the same splits; and the test set is how you noticed the problem.

    Using Table C from the worked example, the root splits on Pitch. Within the Pitch $= F$ branch only, what is the information gain of splitting on Format? (Round to two decimal places.)

    The $F$ rows are matches 3, 5, 6, 8, 9. Split them by Format and count winners in each part.

    The $F$ branch has 1 Green and 4 Blue, so $H = 0.722$.

    Format $T$: matches 5 (Green) and 8 (Blue), $H = 1$. Format $O$: matches 3, 6, 9, all Blue, $H = 0$.

    $\text{IG} = 0.722 - \left(\tfrac25\cdot1 + \tfrac35\cdot0\right) = 0.722 - 0.4 \approx$ 0.32.

    Two slips to avoid: using the whole table’s entropy 0.971 as the parent (that gives 0.57), and forgetting the weights $\tfrac25$, $\tfrac35$. Note that Format looked useless at the root (gain 0.02) but is useful inside this branch, which is why trees recompute gains at every node.

    Eight matches, by powerplay runs, with results: 10 L, 20 L, 30 W, 40 L, 50 L, 60 W, 70 W, 80 W. Candidate thresholds are midpoints between consecutive values, and the rule is “runs ≤ t”. Which threshold gives the lowest weighted Gini impurity of the two children, and what is that weighted Gini?

    Check $t = 25$, $45$ and $55$ carefully. The parent Gini is 0.5.

    $t = 25$: left (0 W, 2 L) has $G = 0$; right (4 W, 2 L) has $G = 1 - \tfrac49 - \tfrac19 = \tfrac49$. Weighted: $\tfrac68\cdot\tfrac49 \approx 0.333$.

    $t = 45$: (1 W, 3 L) and (3 W, 1 L), each $G = 0.375$. Weighted 0.375.

    $t = 55$: left (1 W, 4 L) has $G = 1 - 0.04 - 0.64 = 0.32$; right (3 W, 0 L) is pure. Weighted: $\tfrac58\cdot0.32 =$ 0.2, the lowest of all seven thresholds (the others give 0.429, 0.467, 0.333, 0.429). Best threshold 55.

    The tempting answer is 25 because its left child is pure, but that child holds only 2 of 8 matches; at 55 the pure side holds 3 and the other side is nearly pure.

    Which statements are true?

    1. A node whose examples are spread equally over $m$ classes has entropy $\log_2 m$ bits.
    2. The information gain of a split is never negative.
    3. Splitting on an attribute that is unique to every row (such as a match ID) gives the maximum possible information gain, yet is useless for prediction.
    4. The Gini impurity of a two-class node can exceed 0.5.

    For (D), find the largest value of $1 - p^2 - (1-p)^2$.

    (A) True: each $p_k = 1/m$, so $H = -m\cdot\tfrac1m\log_2\tfrac1m = \log_2 m$ (3 classes: 1.585 bits). (B) True: the weighted average of the children’s entropies never exceeds the parent’s (entropy is concave), so the gain is at least 0. (C) True: every child is pure, so the gain equals $H(S)$, the most possible; but a new match has a new ID that no branch covers. (D) False: $1 - p^2 - (1-p)^2 = 2p(1-p)$, at most 0.5 at $p = \tfrac12$. Answer: A; B; C.

    • Count the target in each child carefully: tabulate (value, wins, losses) before any logarithms.
    • Weight each child’s entropy by its share of the rows.
    • Recompute gains inside each branch; an attribute weak at the root can be strong lower down.
    • Forgetting to subtract from the parent entropy (reporting the weighted entropy as the gain).
    • Using natural logs when the question means bits ($\log_2$).
    • Trusting a deep tree because its training accuracy is 100%.
    1. Entropy H = −Σ p log₂ p and Gini 1 − Σ p² measure how mixed a node is: 0 when pure, largest when evenly mixed (1 and 0.5 for two classes).
    2. Information gain = parent entropy − size-weighted child entropies; a tree greedily splits on the attribute with the largest gain.
    3. Fully grown trees overfit; limit depth or prune, and beware attributes with many values.

    Which group of matches is the most “impure” (hardest to predict with one label)?

    10 wins, 0 losses
    One label fits every match: that’s a pure group.
    9 wins, 1 loss
    Predicting “win” is right 90% of the time. Look for the most even mix.
    5 wins, 5 losses
    An even split is the most uncertain: entropy 1 bit, Gini 0.5.
    7 wins, 3 losses
    Mixed, but still leaning to wins. One option is more balanced.

    The entropy (base 2) of a node with 4 wins and 4 losses is

    0
    That’s for a pure node.
    0.5
    That’s its Gini impurity, not its entropy.
    1
    $-\tfrac12\log_2\tfrac12 - \tfrac12\log_2\tfrac12 = 1$ bit.
    2
    With two classes, entropy is at most 1 bit.

    A tree scores 100% on its training data and 68% on new data. Pruning it will most likely

    raise the training accuracy
    It’s already 100%; a smaller tree can only match or lower it.
    lower the training accuracy a little and raise the test accuracy
    Pruning removes branches that fit noise: a little worse on training data, better on new data.
    leave both unchanged
    Removing branches changes some predictions.
    lower both
    That happens only if you prune far too much. The gap here signals overfitting.

    All training points are distinct. A 1-NN classifier is evaluated on its own training set. Its error is

    about 50%
    Each training point has a neighbour at distance 0.
    0
    Each point’s nearest neighbour is itself, with its own label.
    the same as its test error
    Training error is usually much lower than test error for 1-NN.
    impossible to say without k-fold cross-validation
    Think about which training point is nearest to a training point.

    An SVM has boundary $x_1 + x_2 - 1 = 0$ with $\w = (1, 1)$, $b = -1$. How far is the point $(2, 2)$ from the boundary?

    3
    That’s the score $\w\cdot\x + b$. Divide by $\norm{\w}$.
    $\sqrt2$
    That’s the margin $2/\norm{\w}$, not this point’s distance.
    $3/\sqrt2 \approx 2.12$
    $|2 + 2 - 1|/\sqrt{1 + 1} = 3/\sqrt2$.
    $2\sqrt2$
    That’s the distance from the origin to $(2, 2)$.

    Which training points determine a hard-margin SVM’s boundary?

    All of them, equally
    Points far from the boundary can move without changing it.
    The points farthest from the boundary
    Those are the ones that matter least.
    The class means
    That describes a nearest-mean classifier, not an SVM.
    Only the support vectors on the margin lines
    $\w = \sum\alpha_i y_i\x_i$ with $\alpha_i \gt 0$ only for support vectors.

    A parent node has entropy 1. A split creates two equal-sized children with entropies 0.5 and 0.3. The information gain is

    0.2
    Subtract the weighted average of the children, not their difference.
    0.6
    $1 - (0.5\cdot0.5 + 0.5\cdot0.3) = 1 - 0.4 = 0.6$.
    0.4
    That’s the weighted child entropy. The gain is what’s left after subtracting it from the parent.
    0.2 or 0.6 depending on the class labels
    The formula only needs the entropies and the sizes.

    Which classifier’s decision boundary is always a single hyperplane (a straight line in two dimensions)?

    1-nearest neighbour
    Its boundary is made of many pieces of bisectors.
    A decision tree of depth 3
    It makes axis-parallel staircases.
    Logistic regression on the raw features
    It predicts by the sign of $\w\cdot\x + b$, like a linear SVM.
    An SVM with an RBF kernel
    The kernel makes the boundary curved in the original features.

    A neural network is many small logistic-regression-like units wired in layers. This part builds one from a single neuron, shows why the activation function is what makes depth worth having, counts a network’s parameters the way GATE asks, and then trains it: gradient descent, its stochastic version, and backpropagation, which is the chain rule applied carefully.

    You need: loss functions and linear regression (Part 1), logistic regression and the perceptron update (Part 3), the dot product (refreshers) and the chain rule (refreshers: derivatives).

    Neurons and feed-forward networks: stacking simple units

    A neural network passes its input through layers of neurons; each neuron takes a weighted sum of what it receives, adds a bias, and applies a simple non-linear function.

    GATE DA asks about the structure more than the training: 2024 Q43 asked when a ReLU network equals a single neuron, and 2026 Q56 and sample Q43 asked you to count a network’s learnable parameters. Each of these is 2 marks and takes a minute once you see the pattern.

    It’s like a selection committee: each selector scores the players on a few weighted criteria, the chair combines the selectors’ verdicts, and the final decision depends on the whole chain, not on any one person.

    Where it shows up in GATE DA

    Network structure: forward passes through ReLU layers, equivalent networks, and counting weights and biases.

    2024 Q43 · equivalent ReLU networks2026 Q56 · parameters, no biasesSample Q43 · parameters with biases
    Heat: every paper, usually one 2-mark question

    The Nagpur Neural Nets’ analyst wants to predict, partway through a chase, whether the team will win. Two numbers seem to matter: $x_1$, the wickets still in hand, and $x_2$, the runs still needed per over. Each of these is a feature (an input measurement), and “won” or “lost” is the label (the answer we want to predict), as in Part 1.

    Recall logistic regression from Part 3: weight each feature, add a constant, and squash the total into a probability. Suppose the weights are $0.8$ for wickets and $-0.5$ for the required rate, and the constant is $1$. With 6 wickets in hand and 9 runs an over needed, the total is $0.8\times6 - 0.5\times9 + 1 = 1.3$, and the squashing function turns 1.3 into about $0.79$: a 79% chance of winning.

    That single calculation is one neuron. A neural network is nothing more than many of them, with the outputs of some becoming the inputs of others.

    A neuron with inputs $x_1,\ldots,x_n$ computes $$z = w_1x_1 + \cdots + w_nx_n + b = \mathbf{w}\T\x + b, \qquad a = g(z).$$ The numbers $w_i$ are its weights (how much each input counts), $b$ is its bias (a constant that shifts the threshold), $z$ is the pre-activation and $g$ is the activation function. The output $a$ is called the activation. Weights and biases are the parameters: the numbers training adjusts.

    Step (the perceptron of Part 3): $g(z) = 1$ if $z \ge 0$, else $0$.
    Sigmoid: $\sigma(z) = \dfrac{1}{1+e^{-z}}$, output strictly between 0 and 1, $\sigma(0) = 0.5$. Logistic regression is one sigmoid neuron.
    ReLU (rectified linear unit): $\mathrm{ReLU}(z) = \max(0, z)$. It passes positive values unchanged and replaces negative ones by 0. Example: $\mathrm{ReLU}(3) = 3$, $\mathrm{ReLU}(-2) = 0$.
    Identity (no activation): $g(z) = z$.

    Why one neuron is not enough

    A single neuron with a step or sigmoid activation decides by the sign of $\mathbf{w}\T\x + b$. The boundary $\mathbf{w}\T\x + b = 0$ is a straight line in two dimensions (a hyperplane in general: a flat cut through the feature space). Some patterns cannot be split by one straight line.

    The classic example is XOR (“exclusive or”): the output is 1 when exactly one of two yes/no inputs is 1. Put the four points (0,0), (1,0), (0,1), (1,1) on a grid: the two 1s sit on one diagonal and the two 0s on the other. No single line separates them, so no single perceptron learns XOR.

    The fix is to add a hidden layer: neurons between the inputs and the output whose values nobody labels. Each hidden neuron draws its own line; the output neuron combines them.

    Neurons are arranged in layers. The input layer just holds the features (it has no parameters); then come one or more hidden layers; the last is the output layer. In a fully connected layer every neuron receives every activation of the layer before. Information flows one way, input to output, with no loops: that’s what feed-forward means. A multi-layer perceptron (MLP) is such a network.

    The forward pass computes, layer by layer, with $\a^{(0)} = \x$: $$\z^{(l)} = W^{(l)}\a^{(l-1)} + \b^{(l)}, \qquad \a^{(l)} = g\big(\z^{(l)}\big),$$ where $W^{(l)}$ has one row per neuron in layer $l$ and one column per neuron in layer $l-1$, and $g$ is applied to each entry.

    Try it

    This 2-2-1 network has hidden neurons $h_1 = \mathrm{ReLU}(x_1 + x_2)$ and $h_2 = \mathrm{ReLU}(x_1 + x_2 - 1)$, and outputs class 1 when $h_1 + v\,h_2 \gt 0.5$. With the default $v = -2$ it gets all four XOR points right. Drag the probe to follow the forward pass. Then switch to “No activation”: the shaded region becomes a half-plane and at least one XOR point is always wrong, whatever $v$ you choose.

    If every activation is the identity, a network with weight matrices $W^{(1)}, W^{(2)}, \ldots, W^{(L)}$ (and zero biases) computes $$W^{(L)}\cdots W^{(2)}W^{(1)}\x = M\x,$$ one matrix times $\x$: a single linear layer. With biases it is still one affine map $M\x + \mathbf{c}$. So the non-linear activation is what lets extra layers represent new shapes.

    Corollary for ReLU: if every pre-activation in the network is positive, every ReLU acts as the identity, and the network again collapses to $M\x$. With non-negative weights, zero biases and positive inputs, this always happens.

    When every ReLU stays active, the coefficient of input $x_i$ in the collapsed network is the sum, over every path from $x_i$ to the output, of the product of the weights on that path. If all weights in a layer are equal, this is (number of paths) × (product of one weight per layer).

    Counting parameters

    A fully connected layer from $m$ neurons to $n$ neurons has one weight per pair, so $m\times n$ weights, plus one bias per receiving neuron, so $n$ biases. Add this up over the layers. The sizes of the layers are hyperparameters (choices you make before training), not parameters.

    For layer sizes $n_0$ (inputs), $n_1, \ldots, n_L$ (output), $$\#\text{parameters} = \sum_{l=1}^{L} n_{l-1}\,n_l \;+\; \underbrace{\sum_{l=1}^{L} n_l}_{\text{only if biases are used}} = \sum_{l=1}^{L} (n_{l-1}+1)\,n_l \text{ with biases}.$$ The input layer contributes no biases of its own.

    Try it

    Set the four layer sizes and switch biases on or off. The readout shows each layer’s weights and biases. Check the rule: with biases, each layer costs (inputs to it + 1) × (its neurons). Set a second hidden layer to 0 to remove it, and notice how the count changes.

    GATE DA 2024 · Q43 · MCQ · 2 marks

    Consider the two neural networks (NNs) shown in Figures 1 and 2, with $ReLU$ activation ($ReLU(z) = \max\{0, z\}, \forall z \in \mathbb{R}$). $\mathbb{R}$ denotes the set of real numbers. The connections and their corresponding weights are shown in the Figures. The biases at every neuron are set to 0. For what values of $p, q, r$ in Figure 2 are the two NNs equivalent, when $x_1, x_2, x_3$ are positive?

    Figure 1

    Figure 2

    1. $p = 36, q = 24, r = 24$
    2. $p = 24, q = 24, r = 36$
    3. $p = 18, q = 36, r = 24$
    4. $p = 36, q = 36, r = 36$
    1. Every weight is positive, every bias is 0 and every input is positive, so every pre-activation is positive and every ReLU acts as the identity.

      This is the corollary above: with nothing negative anywhere, $\max\{0, z\} = z$ at every neuron, so the network is linear on this region.

    2. First hidden layer: top $= x_1 + x_2$, middle $= x_1 + x_3$, bottom $= x_1 + x_2 + x_3$.

      Read the edges into each neuron: $x_1$ feeds all three, $x_2$ feeds top and bottom, $x_3$ feeds middle and bottom, all with weight 1.

    3. Each second-hidden neuron receives $2\times$(sum of the three) $= 2(3x_1 + 2x_2 + 2x_3)$.

      Every first-hidden neuron feeds both second-hidden neurons with weight 2, and the three sums add to $3x_1 + 2x_2 + 2x_3$.

    4. Output $= 3\cdot 2(3x_1 + 2x_2 + 2x_3) + 3\cdot 2(3x_1 + 2x_2 + 2x_3) = 36x_1 + 24x_2 + 24x_3$.

      Path check: $x_1$ reaches the output by $3\times2 = 6$ paths, each with weight product $1\cdot2\cdot3 = 6$, giving 36; $x_2$ and $x_3$ each have $2\times2 = 4$ paths, giving 24.

    5. Figure 2 outputs $\mathrm{ReLU}(px_1 + qx_2 + rx_3) = px_1 + qx_2 + rx_3$ for positive inputs and weights, so $p = 36$, $q = 24$, $r = 24$: (A).

      (B) swaps $x_1$ and $x_3$; (C) halves $x_1$’s coefficient; (D) treats all three inputs as if each fed three neurons. Official key: A.

    A network has inputs $\x = (2, -1)$, one hidden layer of two ReLU neurons with $$W^{(1)} = \begin{pmatrix}1 & 3\\ 3 & 1\end{pmatrix},\qquad \b^{(1)} = \begin{pmatrix}-1\\ -2\end{pmatrix},$$ and a linear output neuron $y = 2h_1 + 1\cdot h_2 + 0.5$. Find $y$.

    Compute $\z = W^{(1)}\x + \b^{(1)}$ first, then apply ReLU to each entry before the output layer.

    $z_1 = 1\cdot2 + 3\cdot(-1) - 1 = -2$, so $h_1 = \mathrm{ReLU}(-2) = 0$.

    $z_2 = 3\cdot2 + 1\cdot(-1) - 2 = 3$, so $h_2 = 3$.

    $y = 2\cdot0 + 3 + 0.5 = $ 3.5. Forgetting the ReLU would give $2(-2) + 3 + 0.5 = -0.5$.

    Which statements about activation functions are true? (Select all that apply.)

    (A) $\mathrm{ReLU}(z)$ is never negative.   (B) The sigmoid’s output lies strictly between 0 and 1.   (C) The derivative of ReLU at $z = -2$ is 1.   (D) $\sigma(0) = 0$.

    Sketch both functions. ReLU is flat on the negative side; the sigmoid crosses the vertical axis halfway between its two limits.

    (A) True: $\max(0, z) \ge 0$. (B) True: $e^{-z} \gt 0$ makes the denominator exceed 1, and it is finite. (C) False: for $z \lt 0$ ReLU is the constant 0, so its slope is 0. (D) False: $\sigma(0) = \tfrac{1}{1+1} = 0.5$.

    GATE DA 2026 · Q56 · NAT · 2 marks

    Consider a fully-connected feed-forward multi-layer perceptron. It has 30 neurons in the input layer, followed by two hidden layers and an output layer. The first hidden layer has 4 neurons and the second hidden layer has 3 neurons. The output layer has only one neuron. Assume that no bias parameters are used.

    The number of learnable parameters in the multi-layer perceptron is ______ . (Answer in integer)

    No biases, so only weights: multiply the sizes of each pair of consecutive layers and add.

    $30\times4 + 4\times3 + 3\times1 = 120 + 12 + 3 = $ 135. The input “neurons” hold the features and have no parameters of their own. Official key: 135.

    GATE DA 2024 sample paper · Q43 · NAT · 2 marks

    Consider a Multi-Layer Perceptron (MLP) model with one hidden layer and one output layer. The hidden layer has 10 neurons, and the output layer has 3 neurons. The input to the MLP is a 5-dimensional vector. Each neuron is connected to every neuron in the previous layer, and a bias term is included for each neuron. The activation function used is the sigmoid function. The total number of trainable parameters in this MLP model is ______.

    Each layer costs (inputs to it + 1) × (its neurons). The activation function has no parameters.

    Hidden layer: $(5 + 1)\times10 = 60$. Output layer: $(10 + 1)\times3 = 33$. Total 93. Without the biases it would be 80; the sigmoid adds nothing. (Sample paper, no official key; this is our answer.)

    A fully connected network takes 12 input features, has one hidden layer of $H$ neurons and 4 output neurons, and every neuron has a bias. It has 344 learnable parameters. The Hyderabad Hyperplanes’ analyst replaces the single hidden layer by two hidden layers of 10 neurons each (biases everywhere, still fully connected). How many fewer learnable parameters does the new network have?

    Write the count of the first network as a function of $H$ and solve for $H$. Then count the new network layer by layer.

    First network: $(12 + 1)H + (H + 1)\times4 = 17H + 4 = 344$, so $H = 20$.

    New network: $(12+1)\times10 + (10+1)\times10 + (10+1)\times4 = 130 + 110 + 44 = 284$.

    Difference: $344 - 284 = $ 60. Two narrower layers can be cheaper than one wide one. Dropping the biases from the new network gives $120 + 100 + 40 = 260$ and a wrong difference of 84.

    A network with zero biases has three ReLU hidden neurons $h_A = \mathrm{ReLU}(2x_1 + x_2)$, $h_B = \mathrm{ReLU}(-x_1 - x_2)$, $h_C = \mathrm{ReLU}(x_1 + 3x_2)$, and a ReLU output $y = \mathrm{ReLU}(h_A + 5h_B + 2h_C)$. For all positive $x_1, x_2$, the network is equivalent to

    1. $y = 4x_1 + 7x_2$
    2. $y = -x_1 + 2x_2$
    3. $y = 3x_1 + 4x_2$
    4. no single linear neuron, because $h_B$ has negative weights

    For positive inputs, decide which hidden neurons are switched on. A ReLU that is always switched off contributes nothing, whatever its outgoing weight.

    For $x_1, x_2 \gt 0$: $2x_1 + x_2 \gt 0$ and $x_1 + 3x_2 \gt 0$, so $h_A$ and $h_C$ pass their inputs unchanged; $-x_1 - x_2 \lt 0$, so $h_B = 0$ always.

    Output pre-activation: $(2x_1 + x_2) + 5\cdot0 + 2(x_1 + 3x_2) = 4x_1 + 7x_2 \gt 0$, so the output ReLU is also the identity: (A).

    (B) ignores the ReLU on $h_B$ and multiplies its negative pre-activation by 5. (C) drops the output weight 2 on $h_C$. (D) is wrong because a switched-off neuron simply disappears on this region; the network is linear there.

    Which statements are true? (Select all that apply.)

    (A) A network with any number of layers but identity activations everywhere can represent only affine functions $M\x + \mathbf{c}$ of its input.
    (B) A single neuron with a step activation can classify all four XOR points correctly if its weights are chosen well.
    (C) A network whose hidden activations are all ReLU (and whose output is linear) computes a continuous, piecewise-linear function of its input.
    (D) With ReLU activations, zero biases, non-negative weights and positive inputs, the network equals a single linear neuron.

    Composing affine maps gives an affine map. ReLU is itself continuous and piecewise linear. For (B), think about what boundary one neuron draws.

    (A) True: $W_2(W_1\x + \b_1) + \b_2 = (W_2W_1)\x + (W_2\b_1 + \b_2)$, and so on for more layers.

    (B) False: one neuron’s boundary is a single line, and XOR’s two classes sit on opposite diagonals, so no line separates them.

    (C) True: sums, scalings and compositions of continuous piecewise-linear functions stay continuous and piecewise linear.

    (D) True: every pre-activation is non-negative, so each ReLU is the identity and the network collapses to a product of weight matrices (this is 2024 Q43). Answer A, C, D.

    • Before simplifying a ReLU network, check the sign of every pre-activation for the inputs in question.
    • Count parameters layer by layer: (inputs + 1) × neurons with biases, inputs × neurons without.
    • Read the figure carefully: list, for each neuron, exactly which inputs feed it.
    • Counting the input layer’s “neurons” as having weights or biases.
    • Adding parameters for the activation function: sigmoid, ReLU and step have none.
    • Believing more layers always means more power: without a non-linear activation they collapse to one layer.
    1. A neuron computes a = g(wᵀx + b); a network feeds the activations of one layer into the next.
    2. Without a non-linear activation, any stack of layers is one linear map; ReLU networks are linear wherever no neuron changes on/off state.
    3. Parameters = Σ nₗ₋₁·nₗ weights, plus Σ nₗ biases if biases are used.

    A network has two hidden layers but no activation functions at all: each neuron just outputs its weighted sum. Compared with a single linear neuron per output, what can it represent?

    Much more complicated, curved decision boundaries
    Try multiplying the weight matrices together: what kind of map do you get?
    Exactly the same family of linear (affine) functions
    A product of matrices is a matrix, so the whole network is one linear layer. The non-linear activation is what makes depth useful.
    Only constant functions
    The output still depends on the input; think about what kind of dependence.
    XOR, but nothing more complex
    XOR needs a non-linear boundary. Can a composition of linear maps produce one?

    A fully connected 3-4-2 network (3 inputs, 4 hidden, 2 outputs) uses biases. How many learnable parameters does it have?

    20
    That counts only the weights. Every hidden and output neuron also has a bias.
    9
    That’s the number of neurons, counting the inputs. Parameters live on the connections and in the biases.
    26
    $(3+1)\times4 + (4+1)\times2 = 16 + 10 = 26$.
    29
    The input layer has no biases. Use (inputs + 1) × neurons for each layer.

    In neural-network terms, logistic regression from Part 3 is

    a network with no hidden layer and one sigmoid output neuron
    Weighted sum plus bias, then the sigmoid: exactly one neuron.
    a network with one hidden ReLU layer
    Logistic regression has no hidden layer: its boundary is a single hyperplane.
    a single neuron with a step activation
    That’s the perceptron. Logistic regression outputs a probability, not a hard 0/1.
    a network with identity activations everywhere
    That would be linear regression. Which function turns a score into a probability?

    Training a network: gradient descent and backpropagation

    Training means adjusting the weights so the loss gets smaller: gradient descent says which way to move each weight, and backpropagation computes those directions efficiently with the chain rule.

    GATE DA 2025 Q42 asked for two gradients through a small ReLU network, and 2026 Q29 asked for one stochastic gradient descent step. Both are quick if you know where gradients stop: at a switched-off ReLU.

    It’s like walking down a foggy hillside: you can’t see the valley, but you can feel which way the ground slopes under your feet, so you take a step downhill and feel again.

    Where it shows up in GATE DA

    One-step gradient updates, and gradients of the output with respect to individual weights.

    2025 Q42 · ∂y/∂a and ∂y/∂f through ReLUs2026 Q29 · one SGD step
    Heat: 2025 and 2026, 1–2 marks

    The Bengaluru Backprops’ network has a few thousand weights. Before training they are random, and its predictions are poor. Recall from Part 1 that a loss measures how wrong the predictions are on the training set (the examples whose labels we know): for example the mean squared error $\frac1N\sum_i (y_i - \hat y_i)^2$, or for classification the cross-entropy of Part 3.

    The loss is a function of the weights. Picture it as a landscape: each point is one setting of all the weights, and the height is the loss. Training is a search for a low point.

    The gradient $\grad L$ is the vector of partial derivatives $\partial L/\partial w$, one per weight (see refreshers: gradients). It points in the direction in which the loss rises fastest. So step the other way.

    Starting from some weights $\mathbf{w}_0$, repeat $$\mathbf{w} \leftarrow \mathbf{w} - \eta\,\grad L(\mathbf{w}).$$ The step size $\eta \gt 0$ is the learning rate, a hyperparameter. Each weight moves against its own partial derivative: if $\partial L/\partial w \gt 0$, increasing $w$ would raise the loss, so $w$ decreases.

    A tiny example. Let $L(w) = (w-4)^2 + 1$, start at $w = 1$, and use $\eta = 0.1$. The derivative is $L'(w) = 2(w-4)$.

    • Step 1: $L'(1) = -6$, so $w = 1 - 0.1\times(-6) = 1.6$.
    • Step 2: $L'(1.6) = -4.8$, so $w = 1.6 + 0.48 = 2.08$.

    Each step closes 20% of the remaining gap to the minimum at $w = 4$: the gap goes $3 \to 2.4 \to 1.92$.

    The training loss is an average over examples: $L(\mathbf{w}) = \frac1N\sum_{i=1}^N \ell_i(\mathbf{w})$, where $\ell_i$ is the loss on example $i$.

    (Full-)batch gradient descent uses the gradient of the whole average at every step.
    Stochastic gradient descent (SGD) uses the gradient of one example’s loss $\ell_i$ (chosen at random, or in shuffled order) per step: $\mathbf{w} \leftarrow \mathbf{w} - \eta\,\grad\ell_i(\mathbf{w})$.
    Mini-batch SGD averages over a small random batch, say 32 examples.

    One iteration is one update; one epoch is one pass through all $N$ examples. SGD’s steps are cheap and noisy; on average they point the same way as the full gradient.

    Try it

    The model $\hat y = w x$ is fitted to three points by gradient descent on the mean squared error. Press Step a few times at the default learning rate and watch $w$ slide to the green minimum. Then raise $\eta$ above 0.214 and reset: each step overshoots further and the loss grows. Finally switch to SGD: it uses one point per step, so the path zig-zags and keeps jittering near the minimum instead of settling exactly.

    Careful: too small a learning rate is slow; too large a learning rate diverges. For a quadratic loss $L(w) = \frac{k}{2}(w - w^\ast)^2$ one step multiplies the gap $w - w^\ast$ by $(1 - \eta k)$, so gradient descent converges exactly when $0 \lt \eta \lt 2/k$, and it oscillates (overshoots back and forth) when $1/k \lt \eta \lt 2/k$.

    Backpropagation: the chain rule, organised

    To run gradient descent on a network we need $\partial L/\partial w$ for every weight. Each weight affects the loss only through a chain of intermediate values: its neuron’s pre-activation, that neuron’s activation, the next layer, and so on. The chain rule (from refreshers) multiplies the local derivatives along that chain.

    Backpropagation does this for all weights at once. The forward pass computes and stores every $z$ and $a$. The backward pass starts at the loss and moves towards the input, computing $\partial L/\partial z$ for each neuron from the layer after it. Each weight’s gradient is then one multiplication.

    For $z = w\,x$: $\dfrac{\partial z}{\partial w} = x$ and $\dfrac{\partial z}{\partial x} = w$.
    ReLU: $\dfrac{d}{dz}\mathrm{ReLU}(z) = 1$ if $z \gt 0$, and $0$ if $z \lt 0$ (at $z = 0$ take 0).
    Sigmoid: $\sigma'(z) = \sigma(z)\big(1 - \sigma(z)\big)$, at most $0.25$ (at $z = 0$).

    Write $\delta_j = \partial L/\partial z_j$ for neuron $j$ ("the error signal arriving at $j$"). For the weight $w_{ji}$ on the edge from activation $a_i$ into neuron $j$: $$\frac{\partial L}{\partial w_{ji}} = \delta_j\,a_i, \qquad \frac{\partial L}{\partial b_j} = \delta_j,$$ and the signals are passed backwards by $$\delta_j = g'(z_j)\sum_{k} w_{kj}\,\delta_k,$$ summing over the neurons $k$ that $j$ feeds.

    (signal arriving at the neuron’s $z$) × (the value that travelled along that edge in the forward pass). A ReLU that was switched off in the forward pass ($z \lt 0$) passes back 0, so every weight feeding it, and every weight that only reaches the output through it, gets gradient 0 for this example.

    Try it

    The network from 2025 Q42 with weights $a = b = c = 1$, $e = 4$ and adjustable $u$, $v$, $d$, $f$. Coral numbers above each neuron are the forward pass; blue numbers below are the backward signals $\partial y/\partial z$. With the defaults the bottom neuron is switched off (grey): see that $\partial y/\partial c$, $\partial y/\partial d$ and $\partial y/\partial f$ are all 0. Now raise $d$ until the bottom neuron switches on, and watch those gradients appear.

    GATE DA 2025 · Q42 · MCQ · 2 marks

    Consider the neural network shown in the figure with

    inputs: $u, v$
    weights: $a, b, c, d, e, f$
    output: $y$
    $R$ denotes the ReLU function, $R(x) = \max(0, x)$.

    Given $u = 2, v = 3$,
    $a = 1, b = 1, c = 1, d = -1, e = 4, f = -1$,
    which one of the following is correct?

    1. $\dfrac{\partial y}{\partial a} = 8, \dfrac{\partial y}{\partial f} = 0$
    2. $\dfrac{\partial y}{\partial a} = 1, \dfrac{\partial y}{\partial f} = 0$
    3. $\dfrac{\partial y}{\partial a} = 1, \dfrac{\partial y}{\partial f} = -1$
    4. $\dfrac{\partial y}{\partial a} = 2, \dfrac{\partial y}{\partial f} = -1$
    1. Forward pass, top neuron: $z_1 = au + bv = 2 + 3 = 5$, $h_1 = R(5) = 5$.

      Read from the figure: $u$ reaches the top neuron through $a$, $v$ through $b$.

    2. Bottom neuron: $z_2 = cu + dv = 2 - 3 = -1$, $h_2 = R(-1) = 0$. It is switched off.

      $u$ reaches the bottom neuron through $c$, $v$ through $d = -1$.

    3. Output: $z_o = e h_1 + f h_2 = 4\times5 + (-1)\times0 = 20$, $y = R(20) = 20$. The output ReLU is on, so $\partial y/\partial z_o = 1$.

      Store every $z$ and $h$: the backward pass needs them to know which ReLUs pass gradient.

    4. $\dfrac{\partial y}{\partial f} = \dfrac{\partial y}{\partial z_o}\cdot h_2 = 1\times0 = 0$.

      The gradient of a weight is the signal at its neuron times the value that travelled along its edge, and $h_2 = 0$ travelled along $f$.

    5. $\dfrac{\partial y}{\partial a} = \dfrac{\partial y}{\partial z_o}\cdot e\cdot R'(z_1)\cdot u = 1\times4\times1\times2 = 8$. Answer (A).

      Chain rule from $y$ back to $a$: through the output ReLU (1), weight $e$ (4), the top ReLU, which is on (1), and finally $\partial z_1/\partial a = u = 2$. Option (D)'s $\partial y/\partial a = 2$ stops at $u$, and (C)'s $-1$ uses $f$’s own value instead of $h_2$. Official key: A.

    Gradient descent with learning rate $\eta = 0.25$ minimises $L(w) = (w - 2)^2$ starting from $w_0 = 5$. What is $w$ after two steps?

    $L'(w) = 2(w-2)$. Apply $w \leftarrow w - \eta L'(w)$ twice.

    Step 1: $L'(5) = 6$, $w_1 = 5 - 0.25\times6 = 3.5$.

    Step 2: $L'(3.5) = 3$, $w_2 = 3.5 - 0.75 = $ 2.75. Each step halves the gap to 2 (here $k = 2$ and $1 - \eta k = 0.5$).

    A single sigmoid neuron outputs $\hat y = \sigma(wx)$ and is trained with loss $L = \tfrac12(\hat y - y)^2$. For the example $x = 2$, $y = 1$, at the current weight $w = 0$, find $\partial L/\partial w$.

    Chain rule: $\dfrac{\partial L}{\partial w} = (\hat y - y)\cdot\sigma'(z)\cdot x$ with $z = wx$, and $\sigma'(z) = \sigma(z)(1 - \sigma(z))$.

    $z = 0$, so $\hat y = \sigma(0) = 0.5$ and $\sigma'(0) = 0.5\times0.5 = 0.25$.

    $\dfrac{\partial L}{\partial w} = (0.5 - 1)\times0.25\times2 = $ −0.25. It is negative, so gradient descent increases $w$, pushing $\hat y$ towards the label 1.

    A training set has 10,000 examples. Which statement about stochastic gradient descent (SGD) with one example per update is correct?

    1. Each update uses the gradient of the average loss over all 10,000 examples.
    2. One epoch consists of exactly one update.
    3. One epoch consists of 10,000 updates, each using the gradient of a single example’s loss.
    4. SGD needs no learning rate because the noise sets the step size.

    An epoch is one pass through every example. How many examples does each SGD step look at?

    SGD updates after every single example, so one pass through 10,000 examples is 10,000 updates: (C). (A) and (B) describe full-batch gradient descent; (D) is false, since every SGD step is $\mathbf{w} \leftarrow \mathbf{w} - \eta\grad\ell_i$.

    GATE DA 2026 · Q29 · NAT · 1 mark

    Consider that for a supervised learning task, the objective function being minimized is $f_w(x) = wx$, where $x \in \mathbb{R}$ is the input and $w \in \mathbb{R}$ is the parameter. Stochastic Gradient Descent with learning rate of 0.10 is used for parameter updates.

    Suppose that at the end of iteration $i$, the value of $w$ becomes 10.00.

    Let $x = 10.00$ be the input for iteration $(i + 1)$.

    The value of $w$ at the end of iteration $(i + 1)$ is ______ . (Rounded off to two decimal places)

    Differentiate the objective with respect to the parameter $w$, not the input: $\partial(wx)/\partial w = x$.

    The gradient of $f_w(x) = wx$ with respect to $w$ is $x = 10$.

    One SGD step: $w \leftarrow 10 - 0.10\times10 = $ 9.00. Adding the gradient instead of subtracting it gives 11.00, the common slip. Official key: 8.90 to 9.10.

    A logistic-regression neuron (Part 3) has $\mathbf{w} = (0.5, -1)$, $b = 0$ and is trained with the cross-entropy loss, for which $\dfrac{\partial\ell}{\partial\mathbf{w}} = (\sigma(z) - y)\,\x$ and $\dfrac{\partial\ell}{\partial b} = \sigma(z) - y$, where $z = \mathbf{w}\T\x + b$. One SGD step with $\eta = 0.5$ is taken on the example $\x = (2, 1)$, $y = 1$. What is the new value of $z$ for that same example?

    Three stages: compute $z$ and $\sigma(z)$ at the current weights, update both $\mathbf{w}$ and $b$, then recompute $z$ with the new values.

    Current: $z = 0.5\times2 - 1\times1 + 0 = 0$, $\sigma(0) = 0.5$, so $\sigma(z) - y = -0.5$.

    Update: $\mathbf{w} \leftarrow (0.5, -1) - 0.5\times(-0.5)(2, 1) = (0.5, -1) + (0.5, 0.25) = (1, -0.75)$; $b \leftarrow 0 - 0.5\times(-0.5) = 0.25$.

    New $z = 1\times2 - 0.75\times1 + 0.25 = $ 1.5, so the predicted probability rises from 0.5 to $\sigma(1.5) \approx 0.82$.

    Getting the sign of the step wrong gives $-1.5$; forgetting to update $b$ gives $1.25$.

    A network has input $\x = (x_1, x_2) = (1, 2)$, two ReLU hidden neurons $h_1 = \mathrm{ReLU}(w_{11}x_1 + w_{12}x_2)$ and $h_2 = \mathrm{ReLU}(w_{21}x_1 + w_{22}x_2)$ with $w_{11} = 1$, $w_{12} = -1$, $w_{21} = 2$, $w_{22} = 1$, and a linear output $\hat y = v_1h_1 + v_2h_2$ with $v_1 = 3$, $v_2 = 0.5$. The loss is $L = \tfrac12(\hat y - y)^2$ with label $y = 5$. Which statements are true? (Select all that apply.)

    (A) $\partial L/\partial v_2 = -12$   (B) $\partial L/\partial w_{11} = -9$   (C) $\partial L/\partial w_{22} = -3$   (D) One gradient descent step with $\eta = 0.1$ changes $v_1$.

    Forward pass first: find both pre-activations, both $h$’s, $\hat y$ and $\hat y - y$. Then each gradient is a chain of local derivatives; watch for a switched-off ReLU.

    Forward: $z_1 = 1 - 2 = -1$, $h_1 = 0$ (off); $z_2 = 2 + 2 = 4$, $h_2 = 4$. $\hat y = 3\cdot0 + 0.5\cdot4 = 2$, so $\partial L/\partial\hat y = \hat y - y = -3$.

    (A) $\partial L/\partial v_2 = -3\times h_2 = -12$. True.

    (B) $\partial L/\partial w_{11} = -3\times v_1\times\mathrm{ReLU}'(z_1)\times x_1 = -3\times3\times0\times1 = 0$, not $-9$. False ($-9$ is what you get by ignoring that $h_1$ is off).

    (C) $\partial L/\partial w_{22} = -3\times v_2\times1\times x_2 = -3\times0.5\times2 = -3$. True.

    (D) $\partial L/\partial v_1 = -3\times h_1 = 0$, so $v_1$ does not move. False. Answer A, C.

    Gradient descent with learning rate $\eta$ is run on $L(w) = 2(w - 3)^2$ starting from $w_0 = 5$. Which option gives both $w_2$ (the value after two steps when $\eta = 0.4$) and the full set of learning rates for which the iterates converge to 3 from every start?

    1. $w_2 = 3.72$; converges exactly when $0 \lt \eta \lt 0.5$
    2. $w_2 = 3.72$; converges exactly when $0 \lt \eta \lt 0.25$
    3. $w_2 = 2.28$; converges exactly when $0 \lt \eta \lt 0.5$
    4. $w_2 = 1.8$; converges exactly when $0 \lt \eta \lt 1$

    $L'(w) = 4(w-3)$, so one step maps the gap $w - 3$ to $(1 - 4\eta)(w - 3)$. When does repeatedly multiplying by $(1 - 4\eta)$ shrink the gap to 0?

    One step: $w - 3 \mapsto (1 - 4\eta)(w - 3)$. With $\eta = 0.4$ the factor is $-0.6$: the gap goes $2 \to -1.2 \to 0.72$, so $w_1 = 1.8$ and $w_2 = 3.72$.

    Convergence needs $|1 - 4\eta| \lt 1$, i.e. $0 \lt \eta \lt 0.5$. Answer (A).

    (B) is the condition for no overshoot ($1 - 4\eta \ge 0$, i.e. $\eta \le 0.25$), which is stricter than convergence. (C) drops the sign flip of the oscillation. (D) gives $w_1$, not $w_2$.

    • Do the forward pass first and write down every $z$: the signs decide which ReLUs pass gradient.
    • Move against the gradient: $w - \eta\,\partial L/\partial w$.
    • Differentiate with respect to the parameter, treating the input as a fixed number.
    • Adding the gradient instead of subtracting it.
    • Giving a non-zero gradient to weights that feed a switched-off ReLU.
    • Confusing an epoch (a pass through the data) with an iteration (one update).
    1. Gradient descent: w ← w − η∇L; too large an η overshoots and can diverge.
    2. SGD uses one example’s gradient per update (mini-batch: a few); one epoch is one pass through the data.
    3. Backprop: ∂L/∂w = (signal δ at the neuron) × (input on that edge); a ReLU with z < 0 passes back 0.

    At the current weight $w = 3$, the loss has slope $dL/dw = +4$. To reduce the loss, gradient descent will

    increase $w$
    A positive slope means the loss rises as $w$ increases. Which way is downhill?
    decrease $w$
    $w \leftarrow 3 - 4\eta$: it steps against the slope.
    leave $w$ unchanged until the slope is zero
    A non-zero slope is exactly what tells it to move.
    set $w$ to 0
    The step is small and proportional to the slope; it doesn’t jump to a fixed value.

    During training the loss bounces up and down and then grows without limit. The most likely cause is

    the learning rate is too small
    A tiny learning rate makes training slow, not explosive.
    the network has too few layers
    Depth affects what the network can represent, not whether the updates blow up.
    the training set is too large
    More data makes each gradient more reliable, not larger.
    the learning rate is too large
    Each step overshoots the minimum by more than it corrects, so the error grows.

    In the forward pass, a ReLU neuron had pre-activation $z = -1.5$. In the backward pass, the gradient of the loss with respect to each of its incoming weights is

    0
    $\mathrm{ReLU}'(-1.5) = 0$, so the chain is multiplied by 0.
    $-1.5$ times the input
    The pre-activation’s value isn’t the local derivative. What is the slope of ReLU for negative $z$?
    the input on that edge
    That would be right only if the neuron were on and the arriving signal were 1.
    undefined
    ReLU is only non-differentiable at exactly $z = 0$.

    Which activation function’s output can be read as a probability between 0 and 1?

    ReLU
    ReLU’s output is unbounded above.
    Sigmoid
    $\sigma(z) = 1/(1+e^{-z})$ lies strictly between 0 and 1.
    Identity
    The identity can output any real number.
    Step
    The step outputs only 0 or 1, a hard decision rather than a probability.

    One gradient descent step on $L(w) = (w - 1)^2$ from $w = 3$ with $\eta = 0.5$ gives

    2
    Recompute the derivative: $L'(3) = 2(3 - 1)$.
    5
    Gradient descent subtracts the gradient.
    1
    $L'(3) = 4$, so $w = 3 - 0.5\times4 = 1$, the minimum.
    −1
    Check the size of the step: $\eta\times L'(3)$.

    A fully connected 2-3-1 network without biases is trained by backpropagation. How many partial derivatives $\partial L/\partial w$ does each backward pass produce?

    6
    That’s only the first layer. Count the output layer’s weights too.
    3
    That’s the number of hidden neurons.
    13
    That would include biases, which this network doesn’t have.
    9
    One per weight: $2\times3 + 3\times1 = 9$.

    Why can no single perceptron (Part 3) learn XOR?

    Its decision boundary is one straight line, and XOR’s classes sit on opposite diagonals
    One hyperplane cannot separate them; a hidden layer can.
    The perceptron update rule has no learning rate
    The update rule isn’t the obstacle: no choice of weights works at all.
    XOR has too few training points
    Four points are plenty; the problem is their arrangement.
    The step activation is not differentiable
    That matters for gradient descent, but a perceptron can’t represent XOR with any weights.

    For one example, the squared error of the model $\hat y = wx$ is $(y - wx)^2$. Its derivative with respect to $w$ is

    $2(y - wx)$
    The chain rule also multiplies by the derivative of $y - wx$ with respect to $w$.
    $-2w(y - wx)$
    Differentiate with respect to $w$: the inner derivative is $-x$, not $-w$.
    $-2x(y - wx)$
    Outer derivative $2(y - wx)$ times inner derivative $-x$.
    $x^2$
    That’s not the derivative; use the chain rule on the square.

    Everything so far in this module learned from labelled examples: each player came with the answer (a role, a score, a win or a loss). Unsupervised learning works with no answers at all. It looks for structure in the data itself: groups of similar players (clustering, with k-means and hierarchical clustering) and a few directions that capture most of the variation (principal component analysis). Each of these three topics has been asked in GATE DA, usually as a quick 1- or 2-mark question you can do by hand.

    You need: Chapter 1.1 (features, labels, supervised versus unsupervised); distances between points; for PCA, eigenvalues and eigenvectors of a symmetric matrix (Linear algebra 3.2) and covariance (Statistics 1.2).

    k-means and k-medoids: finding groups without labels

    k-means splits data into $k$ groups by repeating two moves: send every point to its nearest centre, then move every centre to the middle of its group.

    GATE DA has asked about it from several sides: which point must share a cluster (2024 Q19), one iteration by hand (sample paper Q42) and matching k-medoid to clustering (2026 Q23).

    It’s like placing three water coolers in a training ground: each player walks to the nearest cooler, then you move each cooler to the middle of the crowd using it, and repeat until nobody switches.

    Where it shows up in GATE DA

    Short conceptual MCQs and a by-hand iteration, 1–2 marks.

    2024 Q19 · which point must be in cluster 3Sample Q42 · one k-means iteration2026 Q23 · k-medoid is for clustering
    Heat: every year, 1–2 marks

    Learning without answers

    Recall from Chapter 1.1 that a feature is a measured property of an example (a player’s batting score) and a label is the answer we want to predict (the player’s role). In supervised learning every training example comes with its label, and the model learns to predict labels for new examples.

    In unsupervised learning there are no labels. You have only the features, and the goal is to find structure in them: groups of similar examples, unusual examples, or a smaller set of numbers that describes each example well.

    Why would anyone want that? Three everyday reasons:

    • Labels are expensive. The DPL’s scouts have statistics for every player in every league, but nobody has sat down and tagged each one as “batter”, “bowler” or “all-rounder”. Clustering can suggest those groups for free.
    • You may not know the groups yet. A franchise might discover that its fans fall into four buying patterns nobody had named before.
    • It helps other methods. Squeezing 20 statistics down to 2 (with PCA, Chapter 6.3) makes data easier to plot, faster to train on and less noisy.

    The clustering problem

    A cluster is a group of examples that are close to each other and far from the other groups. “Close” needs a distance; in this chapter it’s the ordinary straight-line (Euclidean) distance $\norm{\x - \y}$.

    Picture 19 DPL players plotted by a batting score and a bowling score. Your eye sees batters in one corner, bowlers in another and all-rounders in the middle. k-means is a recipe that finds such groups when there are too many points, or too many features, to see.

    Choose a number of clusters $k$. Each cluster $j$ gets a centre (or centroid) $\boldsymbol\mu_j$, and every point $\x_i$ belongs to exactly one cluster $c(i)$. The objective (the quantity k-means tries to make small) is the total squared distance from points to their own centres: $$J = \sum_{i=1}^{n} \norm{\x_i - \boldsymbol\mu_{c(i)}}^2.$$ Small $J$ means tight clusters. It’s also called the within-cluster sum of squares.

    Start with $k$ centres (often $k$ randomly chosen data points). Then repeat:

    1. Assign: put each point in the cluster of its nearest centre.
    2. Update: move each centre to the mean (average) of the points assigned to it.

    Stop when an assignment step changes nothing. The two steps are sometimes called the E-step and the M-step, because k-means is a “hard” version of the Expectation–Maximisation (EM) algorithm. That is why sample paper Q42 calls one round “one iteration of the Expectation Maximization Algorithm”.

    A tiny run by hand

    Five players have run totals 1, 2, 3, 8 and 9. Take $k = 2$ with starting centres 1 and 2.

    • Assign: 1 goes to centre 1; 2, 3, 8, 9 are all at least as close to centre 2. Update: the centres become 1 and $(2+3+8+9)/4 = 5.5$.
    • Assign: 1, 2, 3 are now nearer to 1 than to 5.5; 8 and 9 go to 5.5. Update: the centres become $2$ and $8.5$.
    • Assign: nothing changes, so the algorithm stops with clusters {1, 2, 3} and {8, 9} and $J = (1 + 0 + 1) + (0.25 + 0.25) = 2.5$.

    Why it always stops

    Each step can only lower $J$ or leave it alone. The assign step picks the nearest centre for every point, which can’t increase any point’s squared distance. The update step uses the fact that, for a fixed group of points, the single point $\boldsymbol\mu$ that minimises $\sum \norm{\x_i - \boldsymbol\mu}^2$ is their mean (set the derivative $2\sum(\boldsymbol\mu - \x_i)$ to zero). There are only finitely many ways to split $n$ points into $k$ groups, so $J$ can’t keep falling forever.

    The catch: it stops at a local minimum, a split that no single step can improve, which need not be the best split overall. Different starting centres can give different answers.

    Once the centres are fixed, the set of all locations nearer to $\boldsymbol\mu_j$ than to any other centre is called the Voronoi region of $\boldsymbol\mu_j$. The boundary between two regions is the perpendicular bisector of the segment joining their centres, so each region is an intersection of half-planes. That makes every region convex: if two points lie in it, so does every point on the segment between them.

    Try it

    Press Next step a few times and read the readout: the steps alternate between assigning players to the nearest centre (the shaded regions are the Voronoi regions) and moving the centres. Watch $J$: it never goes up. Then press New start several times with $k = 3$ and notice that some starts end in a worse split (larger final $J$). Finally switch to k-medoids: the centres must now sit on actual players, so the superstar in the top-right corner can never drag a centre into empty space.

    k-medoids: centres that are real data points

    The mean has two weaknesses. One extreme point can drag it a long way, and it only makes sense when you can average the data (you can’t average two team line-ups or two text messages).

    Take the run totals 1, 2, 3, 4 and 100. The mean is 22, which looks like nobody in the group. The member with the smallest total distance to the others is 3 (total $2+1+0+1+97 = 101$, against 102 for 2 or 4). That member is called the medoid.

    The medoid of a cluster is the member $\x_m$ that minimises the total dissimilarity $\sum_i D(\x_i, \x_m)$ to the other members, for some dissimilarity (distance) $D$. k-medoids runs the same two-step loop as k-means, but the update step moves each centre to its cluster’s medoid. It needs only the pairwise dissimilarities, never an average, and it is less sensitive to outliers (unusual extreme points).

    Practical choices

    • Initialisation. Run k-means several times from different random starts and keep the run with the smallest $J$. A popular smarter start, k-means++, picks starting centres that are spread out.
    • Choosing $k$. $J$ always falls as $k$ grows (with $k = n$, every point is its own centre and $J = 0$), so you can’t just minimise $J$ over $k$. A common heuristic (a rule of thumb that usually works) is the elbow: plot $J$ against $k$ and pick the $k$ where the curve stops dropping steeply.
    • Scaling. If one feature is runs (0 to 100) and another is wickets (0 to 5), distances are dominated by runs. Standardise features first.
    GATE DA 2024 sample paper · Q42 · NAT · 2 marks

    Given the dataset: (1, 1), (3, 3), (4, 4), (5, 5), (6, 6), (9, 9), (0, 3), (3, 0) and assuming the initial centroids for ($K = 3$ – means clustering) to be $C_1 = (3,3), C_2 = (5,5)$ and $C_3 = (6,6)$. One iteration of the Expectation Maximization Algorithm for $K$-means clustering, will update $C_3$ to (a, a). The value of a is ____ .

    1. One iteration means one assign step (E) followed by one update step (M). Only $C_3$ is asked for, so you need to know exactly which points join $C_3$.

      The update step for a centre uses only the points assigned to that centre.

    2. Assign each point to the nearest centre (compare squared distances):

      • (1, 1), (3, 3), (0, 3), (3, 0) → $C_1$ (for example (0, 3) is at squared distance 9 from $C_1$, 29 from $C_2$).
      • (5, 5) → $C_2$ (distance 0); (6, 6) → $C_3$ (distance 0).
      • (9, 9): squared distance 32 to $C_2$ and 18 to $C_3$ → $C_3$.
      • (4, 4): squared distance 2 to $C_1$ and 2 to $C_2$, a tie. It is 8 from $C_3$, so it never goes to $C_3$.

      The tie only decides whether (4, 4) joins $C_1$ or $C_2$. Either way it is not in $C_3$’s cluster, so it cannot change $C_3$’s update.

    3. Update: $C_3$’s cluster is {(6, 6), (9, 9)}, so the new $C_3 = \left(\frac{6+9}{2}, \frac{6+9}{2}\right) = (7.5, 7.5)$, and $a = $ 7.5.

      The new centre is the mean of its members. (For the record, $C_2$ becomes (5, 5) or (4.5, 4.5) and $C_1$ becomes (2.2, 2.2) or (1.75, 1.75), depending on how the tie is broken.) Sample paper, no official key; this is our answer.

    For "where does centre $j$ move?", list only the points whose nearest centre is $j$. Compare squared distances (no square roots needed). Points that are nearer to some other centre can be ignored, even if they are tied between two other centres.

    Run k-means with $k = 2$ on the one-dimensional data 2, 4, 6, 14, 16, starting from centres 3 and 6. Give the two centres when the algorithm stops.

    Alternate: assign each point to the nearer centre, then replace each centre by the mean of its points. Stop when an assignment repeats. It takes two updates.

    Assign: 2, 4 → 3; 6, 14, 16 → 6. Update: centres $3$ and $(6 + 14 + 16)/3 = 12$.

    Assign: 6 is at distance 3 from 3 and 6 from 12, so it moves to the first cluster: {2, 4, 6} and {14, 16}. Update: centres $4$ and $15$.

    Assign again: nothing changes. Final centres 4 and 15 (with $J = 8 + 2 = 10$).

    A cluster holds five players’ run totals: 10, 12, 13, 15, 60. Find its mean and its medoid (using the distance $|a - b|$).

    For the medoid, add up each member’s distances to all the others and pick the member with the smallest total.

    Mean $= 110/5 = 22$, which is no player’s total.

    Totals of distances: 10 → 60, 12 → 54, 13 → 53, 15 → 55, 60 → 190. The medoid is 13. The outlier 60 pulls the mean up by 9 but barely affects the medoid.

    GATE DA 2024 · Q19 · MCQ · 1 mark

    Euclidean distance based $k$-means clustering algorithm was run on a dataset of 100 points with $k = 3$. If the points $\begin{bmatrix}1\\1\end{bmatrix}$ and $\begin{bmatrix}-1\\1\end{bmatrix}$ are both part of cluster 3, then which ONE of the following points is necessarily also part of cluster 3?

    1. $\begin{bmatrix}0\\0\end{bmatrix}$
    2. $\begin{bmatrix}0\\2\end{bmatrix}$
    3. $\begin{bmatrix}2\\0\end{bmatrix}$
    4. $\begin{bmatrix}0\\1\end{bmatrix}$

    A k-means cluster is the set of points nearer to its centre than to the other centres. What shape does that region have, and what does that say about the segment joining two of its points?

    Each k-means cluster is a Voronoi region, an intersection of half-planes, so it is convex: it contains the whole segment between any two of its points. The midpoint of (1, 1) and (−1, 1) is (0, 1), so (0, 1) must be in cluster 3. Answer (D).

    The other points lie off that segment, and a different placement of the three centres could put each of them in another cluster. Official key: D.

    GATE DA 2026 · Q23 · MSQ · 1 mark

    In the following table, the Task column lists a few tasks related to machine learning. The Algorithm column lists a few algorithms.

    Each entry “t” from the Task column is to be matched with an appropriate entry “a” from the Algorithm column such that the task “t” can be solved using the algorithm “a”. Denote such a match as t:a

    TaskAlgorithm
    T1 – ClusteringA1 – Markov Chain Monte Carlo
    T2 – ClassificationA2 – K-Medoid
    T3 – SamplingA3 – Linear Discriminant Analysis
    T4 – Feature ExtractionA4 – Naive Bayes

    Which of the following options is/are the correct matching(s)?

    1. T1:A4, T2:A3, T3:A1, T4:A2
    2. T1:A2, T2:A4, T3:A1, T4:A3
    3. T1:A3, T2:A4, T3:A1, T4:A2
    4. T1:A4, T2:A2, T3:A1, T4:A3

    Start with the clustering row: which algorithm in the list works without labels and groups points? Then check each option’s first entry.

    K-medoid groups unlabelled points, so T1:A2. That alone rules out (A), (C) and (D), whose clustering entries are Naive Bayes or LDA (both need labels).

    The rest of (B) also fits: Naive Bayes is a classifier (T2:A4); Markov Chain Monte Carlo draws samples from a distribution (T3:A1, see the AI module’s sampling chapter); Linear Discriminant Analysis finds a projection that separates classes, which is feature extraction (T4:A3). Answer (B) only. Official key: B.

    Seven players have (batting, bowling) scores (1, 1), (2, 1), (1, 2), (5, 4), (6, 5), (5, 6) and (2, 5). Run k-means with $k = 2$, starting from centres (1, 1) and (2, 1), until it stops. What is the final value of the objective $J$ (sum of squared distances to the assigned centres)? (Round off to two decimal places.)

    The first assignment is lopsided: only (1, 1) and (1, 2) are nearer to (1, 1) than to (2, 1). Keep alternating; it settles after the third assignment. Then compute $J$ with the final centres.

    Assign 1. (1, 1) and (1, 2) are nearer to (1, 1); the other five are nearer to (2, 1). Update 1. Centres $(1, 1.5)$ and $\left(\frac{2+5+6+5+2}{5}, \frac{1+4+5+6+5}{5}\right) = (4, 4.2)$.

    Assign 2. (2, 1) is at squared distance $1.25$ from $(1, 1.5)$ and $14.24$ from $(4, 4.2)$, so it switches. (2, 5) is at $13.25$ from $(1, 1.5)$ and $4.64$ from $(4, 4.2)$, so it stays. Clusters {(1, 1), (2, 1), (1, 2)} and {(5, 4), (6, 5), (5, 6), (2, 5)}. Update 2. Centres $(4/3, 4/3)$ and $(4.5, 5)$.

    Assign 3. Nothing changes, so it stops.

    $J$ for the first cluster: $\frac29 + \frac59 + \frac59 = \frac43$. For the second: $1.25 + 2.25 + 1.25 + 6.25 = 11$. Total $J = \frac{37}{3} \approx$ 12.33.

    Tempting wrong answers: 16.31 is the value after only the second assignment (with the old centres $(1, 1.5)$ and $(4, 4.2)$), and stopping after one update misses the switch of (2, 1).

    Which statements about k-means (Lloyd’s algorithm, Euclidean distance, all points distinct) are correct?

    1. The objective $J$ never increases from one step to the next.
    2. From any starting centres it reaches the smallest possible $J$ for that $k$.
    3. With $k = n$ (one cluster per point), the smallest possible $J$ is 0.
    4. If every feature of every point is multiplied by 2, the optimal $J$ doubles.

    Think about what each of the two steps does to $J$, and what happens to a squared distance when lengths double.

    (A) is true: the assign step picks the nearest centre for each point, and the update step uses the mean, which minimises the squared distance sum for a fixed group.

    (B) is false: it can stop at a local minimum; different starts give different final $J$ (try New start in the widget).

    (C) is true: each point can be its own centre, giving distance 0.

    (D) is false, and it’s the trap: the same clusters stay optimal, but every squared distance is multiplied by $2^2 = 4$, so $J$ quadruples. Answer A; C.

    A cluster contains the points (0, 0), (2, 0), (0, 2), (2, 2) and (20, 20). Using Euclidean distance, which is correct about its mean (the k-means centre) and its medoid (the k-medoids centre)?

    1. Mean (4.8, 4.8); medoid (2, 2)
    2. Mean (1, 1); medoid (2, 2)
    3. Mean (4.8, 4.8); medoid (0, 0)
    4. Mean (4, 4); medoid (1, 1)

    The mean includes the outlier. For the medoid, compute each member’s total distance to the other four; (2, 2) and (0, 0) are the main candidates.

    Mean: $(0+2+0+2+20)/5 = 4.8$ in each coordinate, so (4.8, 4.8).

    Total distances: from (2, 2): $2.83 + 2 + 2 + 25.46 = 32.28$; from (2, 0) or (0, 2): $2 + 2.83 + 2 + 26.91 = 33.74$; from (0, 0): $2 + 2 + 2.83 + 28.28 = 35.11$; from (20, 20): about 107.6. The medoid is (2, 2). Answer (A).

    (B) drops the outlier from the mean, which k-means does not do. (C) picks the corner nearest the origin without computing totals; the outlier makes (2, 2), the corner nearest to it, the best. (D)'s medoid (1, 1) is not a data point, and a medoid must be one.

    • Alternate strictly: assign all points, then update all centres.
    • Compare squared distances; skip the square roots.
    • Standardise features before clustering when their units differ.
    • Run several random starts and keep the smallest $J$.
    • Moving a centre before every point has been reassigned.
    • Choosing $k$ by minimising $J$ (it always prefers more clusters).
    • Thinking k-means finds the best possible clusters; it finds a local minimum.
    • Calling a medoid an average: it is always one of the data points.
    1. Unsupervised learning finds structure (groups, directions) in data with no labels.
    2. k-means alternates “assign to nearest centre” and “move centre to the mean”; J never rises, and it stops at a local minimum. Clusters are convex Voronoi regions.
    3. k-medoids uses a real member (the medoid) as centre: it needs only distances and resists outliers.

    The DPL has statistics for 500 players, but nobody has labelled their roles. Grouping similar players automatically is an example of

    classification
    Classification learns from examples that already have labels. Here there are none.
    regression
    Regression predicts a number from labelled examples.
    clustering (unsupervised learning)
    No labels, and the goal is to find groups: that’s clustering.
    reinforcement learning
    That learns from rewards for actions, not from a table of statistics.

    In the update step of k-means, each centre moves to

    the data point nearest to it
    That’s closer to a k-medoids idea, and even there the rule is different.
    the midpoint of the two farthest points in its cluster
    That ignores most of the cluster. Which point minimises the sum of squared distances?
    the nearest other centre
    Centres don’t move towards each other; they follow their own points.
    the mean of the points assigned to it
    The mean minimises the sum of squared distances to the cluster’s points.

    Why might k-medoids be chosen instead of k-means?

    It needs only pairwise distances and is less affected by outliers
    The centre is a real member chosen by total distance, so one extreme point can’t drag it far.
    It always finds the global minimum
    Like k-means, it can stop at a local minimum.
    It doesn’t need $k$ to be chosen
    The “k” is still in the name.
    It needs labelled data
    It’s unsupervised, just like k-means.

    Hierarchical clustering: a family tree of the data

    Agglomerative clustering starts with every point as its own cluster and keeps merging the two closest clusters until one remains, recording the whole history as a tree called a dendrogram.

    It has appeared every year: drawing the single-linkage dendrogram from a distance table (2024 Q42), which linkage uses min or max (2025 Q30) and the first merge with Manhattan distance (2026 Q36).

    It’s like a knockout of friendships: the two closest friends pair up first, then the closest pair of groups joins, and so on until the whole squad is one group.

    Where it shows up in GATE DA

    Run single or complete linkage by hand on 4–5 points; know which linkage is min and which is max.

    2024 Q42 · single-linkage dendrogram2025 Q30 · min versus max linkage2026 Q36 · first merge, Manhattan distance
    Heat: every year, 1–2 marks

    k-means makes you pick $k$ before you start. Often you’d rather see the structure at every scale: which two players are most alike, which small groups form, and how those groups combine. Hierarchical clustering gives you all of that in one picture.

    The DPL’s analysts have eight players, A to H. A, B, C and D sit in a long line, each a short hop from the next. E, F and G form a tight knot, and H stands a little apart. Which groups are “real”? The answer depends on how you measure the distance between two groups, not just two points.

    1. Start with $n$ clusters, one point each.
    2. Find the two clusters with the smallest linkage distance (defined below) and merge them. Record the distance as the merge height.
    3. Repeat until one cluster remains. There are always exactly $n - 1$ merges.

    (Divisive clustering goes the other way, splitting one big cluster top-down; GATE has asked only about the agglomerative version.)

    For clusters $C_1$, $C_2$ and a point distance $D(x, y)$:

    • Single linkage uses the closest pair: $\displaystyle\min_{x\in C_1,\,y\in C_2} D(x, y)$.
    • Complete linkage uses the farthest pair: $\displaystyle\max_{x\in C_1,\,y\in C_2} D(x, y)$.
    • Average linkage uses the mean of all cross distances $D(x, y)$.

    A dendrogram is a tree drawing of the merges. The leaves along the bottom are the points; each merge is a horizontal bar joining two branches, drawn at the merge height. Cutting the tree with a horizontal line at height $h$ undoes all merges above $h$: the branches that cross the line are the clusters. A higher cut gives fewer, bigger clusters.

    Single versus complete on four points

    Put four players on a line at 0, 1, 3 and 7.

    • Both linkages first merge {0, 1} at height 1 (the closest pair overall).
    • Single: 3 is at distance 2 from the nearest member, 1, so {0, 1, 3} forms at height 2; then 7 joins at height 4 (its gap to 3).
    • Complete: 3’s distance to {0, 1} is now measured to the farthest member, 0, giving 3; that still beats 7 (distance 4 from 3), so {0, 1, 3} forms at height 3. Then 7 joins at height 7 (its distance to 0).

    Same clusters here, different heights. In general the two can produce different trees. Single linkage can follow a chain of close neighbours and join far-apart points through it; complete linkage refuses, because it looks at the worst pair and so prefers compact, round clusters.

    Try it

    With single linkage, press Merge next repeatedly: A, B, C and D join one by one along the chain, and the final merge links D to H. Note the merge heights in the readout. Now switch to complete linkage and merge again: C and D pair up on their own, and the last merge is much higher (10.05 against 3.92). Drag the cut slider to see how many clusters each tree gives at the same height.

    GATE DA 2024 · Q42 · MCQ · 2 marks

    Consider the table below, where the $(i, j)^{th}$ element of the table is the distance between points $x_i$ and $x_j$. Single linkage clustering is performed on data points, $x_1, x_2, x_3, x_4, x_5$.

    $x_1$$x_2$$x_3$$x_4$$x_5$
    $x_1$01436
    $x_2$10353
    $x_3$43025
    $x_4$35201
    $x_5$63510

    Which ONE of the following is the correct representation of the clusters produced?

    1. The smallest entries in the table are $D(x_1, x_2) = 1$ and $D(x_4, x_5) = 1$. Merge both at height 1: clusters $\{x_1, x_2\}$, $\{x_3\}$, $\{x_4, x_5\}$.

      The two merges don’t share a point, so their order doesn’t matter.

    2. Single-linkage distances between the three clusters (closest pair each time):

      • $\{x_3\}$ to $\{x_4, x_5\}$: $\min(2, 5) = 2$.
      • $\{x_3\}$ to $\{x_1, x_2\}$: $\min(4, 3) = 3$.
      • $\{x_1, x_2\}$ to $\{x_4, x_5\}$: $\min(3, 6, 5, 3) = 3$.

      Single linkage takes the minimum over every cross pair.

    3. The smallest is 2, so $x_3$ joins $\{x_4, x_5\}$ at height 2. The last merge joins $\{x_1, x_2\}$ and $\{x_3, x_4, x_5\}$ at $\min(4, 3, 3, 6, 5, 3) = 3$.

      Two clusters remain, so they must merge; the height is the closest cross pair.

    4. Match the tree: $x_1x_2$ and $x_4x_5$ at the bottom, $x_3$ joining the $x_4x_5$ branch, then everything at the top. That is (A).

      (B) is what complete linkage gives: $x_3$’s farthest-pair distance is 4 to $\{x_1, x_2\}$ but 5 to $\{x_4, x_5\}$. (C) and (D) merge $x_3$ with $x_4$ alone, which leaves $x_5$ out even though $D(x_4, x_5) = 1$ is the smallest distance. Official key: A.

    Single linkage merges in the same order as you’d add the shortest edges of the distance table one by one, skipping edges between points that are already connected (Kruskal’s minimum spanning tree). So list the distances in increasing order and connect points; each new connection between different groups is a merge, at that edge’s length.

    Go deeper: why the merge heights never go down

    For single and complete linkage, every merge height is at least the previous one. Suppose $A$ and $B$ merge at height $d$, the smallest linkage distance at that moment. For any other cluster $C$, the new distance from $A\cup B$ to $C$ is the min (single) or max (complete) of the old distances from $A$ to $C$ and from $B$ to $C$, and both of those were at least $d$. So nothing can now be closer than $d$, and the dendrogram never has a bar below its children. (Centroid linkage, which measures between cluster means, can break this.)

    Use the same distance table as in the worked example:

    $x_1$$x_2$$x_3$$x_4$$x_5$
    $x_1$01436
    $x_2$10353
    $x_3$43025
    $x_4$35201
    $x_5$63510

    This time run complete linkage. At what height does $x_3$ join another cluster, and at what height is the final merge?

    The first two merges are the same as for single linkage. Then measure every cluster distance by the farthest cross pair.

    Merge $\{x_1, x_2\}$ and $\{x_4, x_5\}$ at height 1.

    Complete-linkage distances: $x_3$ to $\{x_1, x_2\}$ is $\max(4, 3) = 4$; $x_3$ to $\{x_4, x_5\}$ is $\max(2, 5) = 5$; $\{x_1, x_2\}$ to $\{x_4, x_5\}$ is $\max(3, 6, 5, 3) = 6$. The smallest is 4, so $x_3$ joins $\{x_1, x_2\}$ at height 4.

    Final merge: $\{x_1, x_2, x_3\}$ with $\{x_4, x_5\}$ at $\max(3, 6, 5, 3, 2, 5) =$ 6. This tree has the shape of option (B), not (A): the linkage choice changes the answer.

    Six players stand on a line at positions 1, 2, 4, 8, 9 and 15. Find the height of the final merge under single linkage and under complete linkage.

    On a line, single-linkage heights are the gaps between neighbours. For complete linkage, work through the merges: the distance from a group to a point is to the group’s far end.

    Single: the gaps are 1, 2, 4, 1, 6. Merges happen at 1, 1, 2, 4 and finally 6 (15 joining the rest).

    Complete: merge {1, 2} and {8, 9} at 1. Then 4 joins {1, 2} at $\max(3, 2) = 3$. Next the options are {1, 2, 4}–{8, 9} at $9 - 1 = 8$ and {8, 9}–{15} at $15 - 8 = 7$, so {8, 9, 15} forms at 7. The final merge is {1, 2, 4} with {8, 9, 15} at $15 - 1 =$ 14.

    Complete linkage’s final height is always the largest distance in the data (here 14), while single linkage’s is the largest gap the chain has to jump.

    GATE DA 2026 · Q36 · MCQ · 2 marks

    Let four points in three-dimensional space be:

    P1: [2, 3, −1], P2: [3, 1, 1], P3: [5, −2, 3] and P4: [3, 3, 3].

    Hierarchical Agglomerative Clustering is used to cluster the above points. If Manhattan Distance is used as the distance metric during clustering, which of the following options indicates the two points that will be merged first?

    1. $P1, P2$
    2. $P2, P3$
    3. $P3, P4$
    4. $P2, P4$

    Manhattan distance adds the absolute differences of the coordinates. The first merge is the closest pair, whatever the linkage.

    Manhattan distances: P1–P2 $= 1 + 2 + 2 = 5$; P1–P3 $= 3 + 5 + 4 = 12$; P1–P4 $= 1 + 0 + 4 = 5$; P2–P3 $= 2 + 3 + 2 = 7$; P2–P4 $= 0 + 2 + 2 = 4$; P3–P4 $= 2 + 5 + 0 = 7$.

    The smallest is 4, so P2 and P4 merge first. Answer (D). The linkage isn’t stated, and it doesn’t need to be: every linkage starts with the closest pair of single points. Official key: D.

    GATE DA 2025 · Q30 · MSQ · 1 mark

    Let C1 and C2 be two sets of objects. Let D(x, y) be a measure of dissimilarity between two objects x and y. Consider the following definitions of dissimilarity between C1 and C2.

    $$\text{DIS-1}(C_1, C_2) = \max_{x\in C_1,\, y\in C_2} D(x, y)$$ $$\text{DIS-2}(C_1, C_2) = \min_{x\in C_1,\, y\in C_2} D(x, y)$$

    Which of the following statements is/are correct?

    1. Single Linkage Clustering uses DIS-1
    2. Single Linkage Clustering uses DIS-2
    3. Complete Linkage Clustering uses DIS-2
    4. Complete Linkage Clustering uses DIS-1

    Single linkage: one close pair is enough. Complete linkage: every pair must be close.

    Single linkage measures the closest pair, the minimum (DIS-2). Complete linkage measures the farthest pair, the maximum (DIS-1). So (B) and (D) are correct. Official key: B; D.

    Seven players stand on a line at 0, 1.8, 4.0, 6.3, 8.7, 14 and 15. Build the dendrogram with single linkage and with complete linkage, and cut each at height 3. How many clusters does each give?

    Single linkage on a line merges along the gaps. For complete linkage, track the merges carefully: after {14, 15} and {0, 1.8}, compare 4.0’s distance to {0, 1.8} with its distance to 6.3.

    Single. Gaps: 1.8, 2.2, 2.3, 2.4, 5.3, 1. All gaps in the chain 0 to 8.7 are below 3, so the chain becomes one cluster; the 5.3 gap to 14 is above 3. Cut at 3: {0, …, 8.7} and {14, 15}, so 2 clusters.

    Complete. Merges: {14, 15} at 1; {0, 1.8} at 1.8. Now 4.0 is $4.0 - 0 = 4.0$ from {0, 1.8} but 2.3 from 6.3, so {4.0, 6.3} forms at 2.3. Then 8.7 is $8.7 - 4.0 = 4.7$ from {4.0, 6.3}; that is the next merge, at 4.7, above the cut. Below height 3 we have {0, 1.8}, {4.0, 6.3}, {8.7}, {14, 15}: 4 clusters.

    This is the chaining effect in numbers: single linkage strings the evenly spaced players into one long cluster, while complete linkage keeps clusters short. A tempting slip is to let 4.0 join {0, 1.8} under complete linkage because it is 2.2 from 1.8; complete linkage uses the far end, 0.

    Agglomerative clustering is run on $n \ge 3$ distinct points whose pairwise distances are all different. Which statements are correct?

    1. There are exactly $n - 1$ merges.
    2. Single and complete linkage always make the same first merge.
    3. Under complete linkage, the final merge height equals the largest pairwise distance in the data.
    4. Under single linkage, the final merge height equals the largest pairwise distance in the data.

    For (C), use the fact that complete-linkage heights never decrease, and that a cluster formed at height $h$ has all its internal distances at most $h$. For (D), try three points on a line.

    (A) True: each merge reduces the number of clusters by one, from $n$ to 1.

    (B) True: at the start every cluster is a single point, and min and max over one pair are the same number, so both pick the closest pair.

    (C) True: every complete-linkage cluster formed at height $h$ has all internal distances at most $h$, and heights never decrease. So the two final clusters have internal distances at most the final height, and the final height is the largest cross distance; hence it is the largest distance overall.

    (D) False: on the line 0, 1, 3, single linkage ends at height 2 (the gap 1 to 3), while the largest distance is 3. Answer A; B; C.

    Take the four points of GATE DA 2026 Q36, P1 = (2, 3, −1), P2 = (3, 1, 1), P3 = (5, −2, 3), P4 = (3, 3, 3), with Manhattan distance. Run agglomerative clustering to the end. What is the height of the final merge under single linkage, and under complete linkage?

    The Manhattan distances are 5, 12, 5, 7, 4, 7 (P1–P2, P1–P3, P1–P4, P2–P3, P2–P4, P3–P4). Both linkages merge P2 and P4 first; then recompute the distances to {P2, P4}.

    First merge: {P2, P4} at 4.

    Single: P1 to {P2, P4} is $\min(5, 5) = 5$; P3 to {P2, P4} is $\min(7, 7) = 7$; P1–P3 is 12. Merge P1 at 5. Then P3 to {P1, P2, P4} is $\min(12, 7, 7) =$ 7.

    Complete: P1 to {P2, P4} is $\max(5, 5) = 5$; P3 to {P2, P4} is $\max(7, 7) = 7$. Merge P1 at 5. Then P3 to {P1, P2, P4} is $\max(12, 7, 7) =$ 12.

    Both trees have the same shape; only the top height differs. Using Euclidean distance by mistake gives different numbers (for instance P2–P4 would be $\sqrt8$).

    • Write out the distance table before you start, and update it after each merge.
    • Single linkage: min over cross pairs. Complete linkage: max over cross pairs.
    • Check which distance (Euclidean, Manhattan) the question uses.
    • Mixing up the two: “single = one close pair is enough” is the memory hook.
    • Forgetting that a cluster distance must be recomputed from the original point distances after a merge.
    • Reading a dendrogram’s left-to-right order as meaningful; only the heights and the branching matter.
    1. Agglomerative clustering: start with singletons, merge the closest pair of clusters, repeat; n − 1 merges recorded as a dendrogram.
    2. Single linkage = closest pair (min), can chain; complete linkage = farthest pair (max), gives compact clusters.
    3. Cut the dendrogram at a height to get clusters; you choose the number of clusters after seeing the tree.

    Agglomerative (bottom-up) hierarchical clustering starts with

    every point in its own cluster
    Then it merges the two closest clusters, again and again.
    all points in one cluster
    That’s the starting point of divisive (top-down) clustering.
    $k$ randomly placed centres
    That’s how k-means starts.
    a labelled training set
    Hierarchical clustering is unsupervised: no labels.

    Under single linkage, the distance between two clusters is

    the distance between their means
    That’s centroid linkage. Single linkage looks at actual pairs of points.
    the largest distance between a point of one and a point of the other
    That’s complete linkage.
    the smallest distance between a point of one and a point of the other
    One close pair is enough to make two clusters “near” each other.
    the average of all cross distances
    That’s average linkage.

    You cut a dendrogram at a higher level than before. The number of clusters

    increases
    A higher cut sits above more merges. Does that join or split groups?
    stays the same
    It can stay the same if no merge lies between the two heights, but not in general.
    becomes $n$
    That’s a cut below every merge.
    decreases or stays the same
    Every merge below the cut is kept, so raising the cut can only join clusters.

    Principal component analysis: the directions that matter

    PCA finds new axes for your data, ordered by how much the data spreads along them; keeping the first few gives a smaller description that loses as little as possible.

    It’s asked every year: the variance along the top direction is the largest eigenvalue (2025 Q60), components are perpendicular (2026 Q11), and round data has no preferred direction (sample paper Q30).

    It’s like photographing a cricket bat: from the side you see its full length; end-on it’s a small rectangle. PCA finds the “side view” that shows the most.

    Where it shows up in GATE DA

    Conceptual MCQs and one-line numericals from eigenvalues.

    2025 Q60 · variance along the top direction2026 Q11 · angle between componentsSample Q30 · spherical data
    Heat: every year, 1–2 marks

    The DPL tracks 20 numbers for every player: runs, balls faced, fours, sixes, wickets, economy, catches, and so on. You can’t draw 20 dimensions, and many of the numbers move together (players who face more balls score more runs). Is there a way to replace the 20 numbers by two or three new ones that keep most of the information?

    PCA says: measure information by spread (variance). If all players have nearly the same value along some direction, that direction tells them apart poorly, and you can drop it. If they spread out a lot along another direction, keep it.

    Projecting onto a direction

    Assume the data has been centred: subtract the mean of each feature, so the average point is the origin. Take a unit vector $\u$ (length 1, $\u\T\u = 1$). The projection (or score) of a point $\x$ onto $\u$ is the number $z = \u\T\x$: the length of $\x$’s shadow on the line through $\u$.

    The variance of these shadows over $n$ points is $$\frac1n\sum_{i=1}^{n} (\u\T\x_i)^2 = \u\T\Big(\frac1n\sum_{i=1}^n \x_i\x_i\T\Big)\u = \u\T S\,\u,$$ where $S = \frac1n\sum_i \x_i\x_i\T$ is the covariance matrix of the centred data. Its diagonal entries are the variances of the features and its off-diagonal entries are the covariances (recall Statistics 1.2).

    From Linear algebra 3.2: a covariance matrix $S$ is symmetric ($S\T = S$), so its eigenvalues are real and it has an orthonormal set of eigenvectors $\u_1, \ldots, \u_d$ (unit length, mutually perpendicular) with $S\u_k = \lambda_k\u_k$. Because $\u\T S\u$ is a variance it is never negative, so every $\lambda_k \ge 0$. And from Linear algebra 3.3: the largest value of $\u\T S\u$ over unit vectors is the largest eigenvalue $\lambda_1$, reached at its eigenvector $\u_1$.

    Order the eigenvalues of the covariance matrix $\lambda_1 \ge \lambda_2 \ge \cdots \ge \lambda_d$ with orthonormal eigenvectors $\u_1, \ldots, \u_d$.

    • The direction of maximum variance is $\u_1$, the first principal component, and the variance along it is $\lambda_1$.
    • Among directions perpendicular to $\u_1$, the most variance is along $\u_2$, with variance $\lambda_2$; and so on. The $k$-th principal component is $\u_k$, with variance $\lambda_k$.
    • Principal components are mutually orthogonal (at 90°).
    • Total variance $= \operatorname{tr}(S) = \lambda_1 + \cdots + \lambda_d$. The share kept by the first $k$ components, the explained variance ratio, is $(\lambda_1 + \cdots + \lambda_k)/(\lambda_1 + \cdots + \lambda_d)$, and the mean squared reconstruction error is the sum of the dropped eigenvalues.

    Why the eigenvector? Maximise $\u\T S\u$ subject to $\u\T\u = 1$. With a Lagrange multiplier $\lambda$, the gradient condition is $2S\u - 2\lambda\u = \0$, that is, $S\u = \lambda\u$. So the best direction is an eigenvector, and then $\u\T S\u = \lambda\u\T\u = \lambda$. The biggest $\lambda$ wins.

    1. Centre the data (subtract each feature’s mean). If the features have different units, also divide each by its standard deviation (standardise).
    2. Form the covariance matrix $S = \frac1n X\T X$, where the rows of $X$ are the centred points.
    3. Find the eigenvalues and orthonormal eigenvectors of $S$; sort by eigenvalue, largest first.
    4. Keep the top $k$ eigenvectors as columns of $W$ ($d \times k$). The new $k$ features of each point are $\z = W\T\x$.
    Try it

    Turn the direction $\u$ with the slider. Each black point drops a shadow (coral) onto the line; the readout shows the variance of the shadows, $\u\T S\u$. Find the angle that makes it as large as possible, then press Snap to PC1 to check: the maximum equals $\lambda_1$. Snap to PC2: it is 90° away and its variance is $\lambda_2$. Then choose the round cloud: every direction gives the same variance.

    Four players have (batting, bowling) scores (7, 4), (3, 2), (6, 5) and (4, 1). Find the principal components, the share of variance explained by the first one, and the first-component scores. Use $S = \frac1n X\T X$.

    1. Mean: $\left(\frac{7+3+6+4}{4}, \frac{4+2+5+1}{4}\right) = (5, 3)$. Centred points: $(2, 1), (-2, -1), (1, 2), (-1, -2)$.

      PCA measures spread around the mean, so the mean must be removed first.

    2. $\sum x_1^2 = 4+4+1+1 = 10$, $\sum x_1x_2 = 2+2+2+2 = 8$, $\sum x_2^2 = 10$. So $S = \frac14\begin{bmatrix}10 & 8\\ 8 & 10\end{bmatrix} = \begin{bmatrix}2.5 & 2\\ 2 & 2.5\end{bmatrix}$.

      The positive off-diagonal entry says batting and bowling scores rise together here.

    3. Eigenvalues: $(2.5 - \lambda)^2 - 4 = 0$ gives $\lambda = 2.5 \pm 2$, so $\lambda_1 = 4.5$ and $\lambda_2 = 0.5$. Eigenvectors: $\u_1 = \frac{1}{\sqrt2}(1, 1)$ and $\u_2 = \frac{1}{\sqrt2}(1, -1)$.

      For a matrix of the form $\begin{bmatrix}a & b\\ b & a\end{bmatrix}$ the eigenvectors are always along $(1, 1)$ and $(1, -1)$, with eigenvalues $a + b$ and $a - b$. The two are perpendicular, as they must be.

    4. Explained variance of PC1: $\frac{4.5}{4.5 + 0.5} = 0.9$, so 90%.

      Total variance is the trace $2.5 + 2.5 = 5$, which equals $\lambda_1 + \lambda_2$.

    5. Scores $z = \u_1\T\x$: $\frac{3}{\sqrt2}, -\frac{3}{\sqrt2}, \frac{3}{\sqrt2}, -\frac{3}{\sqrt2}$ (about $\pm 2.12$). Their mean square is $\frac{9}{2} = 4.5 = \lambda_1$.

      This checks the theorem: the variance along PC1 is $\lambda_1$. Keeping only this one number per player loses a mean squared error of $\lambda_2 = 0.5$.

    Careful: PCA never looks at labels. The direction of largest variance need not be the direction that best separates two teams; for that you want a supervised method such as LDA (Chapter 3.3). Also, an eigenvector’s sign is arbitrary: $-\u_1$ is just as good a first component.
    Go deeper: PCA through the SVD

    If the centred data matrix has the singular value decomposition $X = U\Sigma V\T$ (Linear algebra 4.2), then $\frac1n X\T X = V\frac{\Sigma^2}{n}V\T$. So the principal components are the right singular vectors (columns of $V$) and $\lambda_k = \sigma_k^2/n$. Software computes PCA this way because it avoids forming $X\T X$, which loses numerical accuracy.

    The covariance matrix of four DPL statistics has eigenvalues 5, 3, 1.5 and 0.5. What fraction of the total variance do the first two principal components explain, and how many components are needed to explain at least 90%?

    Total variance is the sum of the eigenvalues. Add eigenvalues from the largest down until you pass 90% of the total.

    Total $= 5 + 3 + 1.5 + 0.5 = 10$. Two components: $(5 + 3)/10 = $ 0.8.

    Three components: $9.5/10 = 0.95 \ge 0.9$, while two give only 0.8. So 3 components are needed.

    GATE DA 2025 · Q60 · NAT · 2 marks

    Let $D = \{x^{(1)}, \ldots, x^{(n)}\}$ be a dataset of $n$ observations where each $x^{(i)} \in \R^{100}$. It is given that $\sum_{i=1}^{n} x^{(i)} = 0$. The covariance matrix computed from $D$ has eigenvalues $\lambda_i = 100^{2-i}$, $1 \le i \le 100$. Let $u \in \R^{100}$ be the direction of maximum variance with $u\T u = 1$.

    The value of $$\frac1n\sum_{i=1}^{n}\left(u\T x^{(i)}\right)^2 = \underline{\qquad\qquad}$$ (Answer in integer)

    The data is already centred. The expression is the variance of the projections onto $u$. What is that for the direction of maximum variance?

    Since the data is centred, $\frac1n\sum(u\T x^{(i)})^2 = u\T S u$. For the direction of maximum variance this is the largest eigenvalue.

    $\lambda_i = 100^{2-i}$ decreases with $i$: $\lambda_1 = 100^1 = 100$, $\lambda_2 = 1$, $\lambda_3 = 0.01$, and so on. The answer is 100. Official key: 100.

    GATE DA 2026 · Q11 · MCQ · 1 mark

    For a classification problem, Principal Component Analysis (PCA) has been used to reduce the dimensionality of a feature space from 100 to 10.

    Which of the following options is true about the angle $\theta$ between the first and the tenth principal components?

    1. $\theta = 0°$
    2. $\theta = 90°$
    3. $90° \lt \theta \le 180°$
    4. $0 \lt \theta \lt 90°$

    Principal components are eigenvectors of a symmetric matrix. What do you know about those?

    The principal components are orthonormal eigenvectors of the (symmetric) covariance matrix, so any two different components are perpendicular: $\theta = 90°$. Answer (B). The “classification problem” and “100 to 10” details don’t matter. Official key: B.

    GATE DA 2024 sample paper · Q30 · MCQ · 2 marks

    For perfectly spherical 2D data centered at the origin, which all of the following pairs of vectors are possible pairs of principal components?

    i) (1, 0) and (0, 1)
    ii) (0, -1) and (-1, 0)
    iii) (1, 1) and (1, 0)

    1. i only
    2. i and iii only
    3. i, ii, and iii only
    4. i and ii only

    For spherical data, the covariance matrix is a multiple of the identity. Which unit vectors are then eigenvectors, and what must be true of a pair of principal components?

    Spherical data has covariance $S = c\,I$, so every direction has the same variance $c$ and every nonzero vector is an eigenvector. Any pair of perpendicular unit directions is a valid pair of principal components.

    i) is perpendicular. ii) is too: $(0, -1)\cdot(-1, 0) = 0$ (signs don’t matter). iii) is not: $(1, 1)\cdot(1, 0) = 1 \ne 0$. So i and ii only, (D). (Sample paper, no official key; this is our answer.)

    Centred two-feature data has covariance matrix $S = \begin{bmatrix}5 & 2\\ 2 & 2\end{bmatrix}$. Each point is replaced by its projection onto the first principal component. What fraction of the total variance is kept, and what is the mean squared reconstruction error (the average of $\norm{\x - (\u_1\T\x)\u_1}^2$)? (Round off to two decimal places.)

    Find the eigenvalues from $\lambda^2 - (\text{trace})\lambda + \det = 0$. The kept variance is $\lambda_1$; what’s lost is everything else.

    Trace $= 7$, determinant $= 10 - 4 = 6$, so $\lambda^2 - 7\lambda + 6 = 0$ and $\lambda_1 = 6$, $\lambda_2 = 1$. (PC1 is along $(2, 1)/\sqrt5$: $S(2, 1)\T = (12, 6)\T = 6\,(2, 1)\T$.)

    Fraction kept: $6/7 \approx$ 0.86. Mean squared reconstruction error: the dropped eigenvalue, 1, since total variance $7 = 6 + 1$ splits into what the projection keeps and what it loses.

    Tempting wrong answers: $5/7 \approx 0.71$ uses the largest diagonal entry, the variance of feature 1 alone, which ignores the covariance; and an error of 2 uses feature 2’s variance instead of $\lambda_2$.

    Which statements about PCA on centred data are correct?

    1. The principal components are eigenvectors of the covariance matrix.
    2. Measuring one feature in different units (say runs in hundreds instead of ones) can change the principal directions.
    3. The first principal component is always the direction that best separates two labelled classes.
    4. The variance of the data projected onto the second principal component equals the second-largest eigenvalue.

    Rescaling one feature by $c$ changes its variance by $c^2$ and its covariances by $c$. And ask yourself whether PCA ever sees the labels.

    (A) True by the theorem.

    (B) True: rescaling a feature changes $S$ in a way that is not a multiple of $S$, so its eigenvectors can turn. For example, with $S = \begin{bmatrix}2.5 & 2\\ 2 & 2.5\end{bmatrix}$, multiplying feature 1 by 10 gives $\begin{bmatrix}250 & 20\\ 20 & 2.5\end{bmatrix}$, whose top eigenvector is within 5° of feature 1’s axis instead of $(1, 1)/\sqrt2$. That’s why features in different units are standardised first.

    (C) False: PCA ignores labels. Two classes can differ along a low-variance direction, which PCA would rank last.

    (D) True: $\u_2\T S\u_2 = \lambda_2$. Answer A; B; D.

    Three centred DPL statistics have covariance matrix $$S = \begin{bmatrix}6 & 0 & 0\\ 0 & 3 & 1\\ 0 & 1 & 3\end{bmatrix}.$$ Which is correct about the first principal component and the share of variance kept by the first two components?

    1. PC1 is $(1, 0, 0)$; two components keep $\frac{10}{12} \approx 83\%$.
    2. PC1 is $\frac{1}{\sqrt2}(0, 1, 1)$; two components keep $\frac{10}{12} \approx 83\%$.
    3. PC1 is $(1, 0, 0)$; two components keep $\frac{9}{12} = 75\%$.
    4. PC1 is $(1, 0, 0)$, PC2 is $(0, 1, 0)$; two components keep $75\%$.

    The matrix is block diagonal: feature 1 is uncorrelated with the others. Find the eigenvalues of the $2\times2$ block $\begin{bmatrix}3 & 1\\ 1 & 3\end{bmatrix}$ separately.

    Feature 1 alone gives eigenvalue 6 with eigenvector $(1, 0, 0)$. The block $\begin{bmatrix}3 & 1\\ 1 & 3\end{bmatrix}$ has eigenvalues $3 \pm 1$, so 4 along $\frac{1}{\sqrt2}(0, 1, 1)$ and 2 along $\frac{1}{\sqrt2}(0, 1, -1)$.

    Sorted: $6 \ge 4 \ge 2$. PC1 is $(1, 0, 0)$ and PC2 is $\frac{1}{\sqrt2}(0, 1, 1)$. Total variance $= 12$ (the trace), and two components keep $\frac{6 + 4}{12} = \frac{10}{12} \approx 83\%$. Answer (A).

    (C) and (D) read the variances off the diagonal (6 and 3), which ignores the covariance between features 2 and 3; a correlated pair has a combined direction with more variance (4) than either feature alone. (B) picks the eigenvector of 4 as if it were the largest.

    • Centre the data first; standardise when features have different units.
    • Use the trace as a shortcut for the total variance.
    • Remember: variance along $\u_k$ is $\lambda_k$, and components are perpendicular.
    • Reading variances off the diagonal of $S$ and calling them the eigenvalues (only true when the off-diagonal entries are 0).
    • Expecting PCA to find the direction that separates classes; it never sees labels.
    • Assuming principal components are unique when two eigenvalues are equal; then any perpendicular pair in that plane works.
    1. The variance of centred data along a unit vector u is uᵀSu, where S is the covariance matrix.
    2. Principal components are the eigenvectors of S, sorted by eigenvalue; the variance along the k-th is λₖ, and they are mutually perpendicular.
    3. Explained variance of the first k components = (λ₁ + … + λₖ) / (sum of all λ); the dropped eigenvalues are the reconstruction error.

    You want to describe each player’s 20 statistics with just 2 numbers while losing as little of the spread between players as possible. PCA chooses the 2 directions

    that best separate the five teams
    That would need team labels. PCA never uses labels.
    along which the data varies the most
    The first two principal components capture the most variance of any two perpendicular directions.
    of the two original statistics with the largest values
    PCA builds new directions, usually mixtures of all 20 statistics.
    picked at random
    PCA is deterministic: the eigenvectors of the covariance matrix.

    For centred data with covariance matrix $S$, the variance of the projections onto the $k$-th principal component equals

    the $k$-th diagonal entry of $S$
    That’s the variance of the $k$-th original feature, not of a component.
    1, because the component has unit length
    Unit length fixes the direction’s scale, not the data’s spread along it.
    the $k$-th largest eigenvalue $\lambda_k$
    $\u_k\T S\u_k = \lambda_k\u_k\T\u_k = \lambda_k$.
    the sum of all eigenvalues
    That’s the total variance over all directions.

    Two DPL statistics are runs (range 0 to 150) and catches (range 0 to 3). Before PCA you should usually

    sort the players by runs
    The order of the rows doesn’t affect PCA.
    drop the catches column
    That throws information away. The problem is the units.
    do nothing; PCA is unaffected by units
    Rescaling a feature changes the covariance matrix and can change the components.
    standardise each feature (subtract its mean, divide by its standard deviation)
    Otherwise runs, with its far bigger variance, would dominate the first component.

    After one full k-means iteration (assign, then update), the objective $J$

    may go up if a point switches clusters
    A point switches only to a nearer centre, which lowers its term.
    is less than or equal to its previous value
    Both steps can only lower $J$ or keep it the same.
    always reaches its global minimum
    k-means can stop at a local minimum.
    doubles
    There’s no reason for a fixed factor.

    Points at 0, 1, 3 on a line. Under complete linkage, at what height does 3 join {0, 1}?

    2
    That’s the single-linkage height (closest member, 1).
    1
    That’s the height at which {0, 1} formed.
    3
    Complete linkage measures to the farthest member, 0.
    2.5
    That’s the distance to the cluster’s mean (centroid linkage).

    A covariance matrix has eigenvalues 8, 1, 1. The first principal component explains

    8%
    Divide by the total, 10, not by 100.
    80% of the variance
    $8/(8 + 1 + 1) = 0.8$.
    89%
    That’s $8/9$, which leaves out one of the eigenvalues.
    it can’t be known without the eigenvectors
    The share depends only on the eigenvalues.

    Which method does not need the number of clusters to be fixed before it runs?

    k-means
    You must choose $k$ to place $k$ centres.
    k-medoids
    It also starts from $k$ centres.
    agglomerative hierarchical clustering
    It builds the whole tree; you choose the number of clusters afterwards by where you cut.
    none of them
    One of them builds the full hierarchy first.

    Both PCA and LDA find a direction to project data onto. The key difference is that

    PCA needs class labels and LDA does not
    It’s the other way round.
    PCA directions need not be perpendicular
    PCA directions are always perpendicular.
    LDA maximises total variance
    That’s PCA’s goal.
    PCA maximises total variance without labels; LDA uses labels to separate the classes
    PCA is unsupervised; LDA is supervised.
    Every module complete

    Every question, answered right.

    You worked through every quiz and every practice problem in GATE Data Science & AI. That took real effort, and the understanding is yours to keep. Add your name to make a certificate.