Supervised learning
GATE DA150 min read
The setting
Definition. In supervised learning we are given labelled examples , where each is a feature vector and its label, and we learn a function so that on new data. If is a real number the task is regression; if is one of a few classes it is classification.
Training, validation and test data. We fit the model on the training set, choose settings (hyperparameters such as in k-NN or in ridge regression) on a validation set, and report performance once on a test set that was never used for choices.
Exam point. A model is judged by its error on unseen data, not on the data it was trained on. A model with zero training error can still generalise badly.
Linear regression
Simple linear regression fits by minimising the sum of squared errors . Setting the derivatives to zero gives
So the fitted line always passes through the point .
Multiple linear regression stacks the inputs as rows of a matrix (with a column of 1s for the intercept) and fits . The least-squares solution satisfies the normal equations
Ridge regression adds a penalty on large weights: minimise with . The solution is
Adding makes the matrix invertible for every , shrinks the weights towards 0, and trades a little bias for lower variance.
Exam point. gives ordinary least squares; as the weights go to 0. Ridge never makes a weight exactly zero (that is what the L1 penalty, lasso, does).
Solved examples
Example 1: slope from data. Points . Here , .
- .
- .
- and .
- Fitted line: .
Example 2: ridge in one dimension. With one feature and no intercept, least squares gives and ridge gives . If and : least squares gives , ridge with gives . The penalty shrinks the weight.
Logistic regression
Definition. For two classes , logistic regression models the probability of class 1 as
The sigmoid maps any real number into ; , and . We predict class 1 when , that is when , so the decision boundary is linear.
The weights are found by maximising the likelihood, equivalently minimising the cross-entropy (log) loss . There is no closed form; gradient descent is used, and the loss is convex, so there is a single minimum.
Exam point. The log-odds are linear: . Despite the name, logistic regression is a classification method.
Solved example
Example 3. , , . Then , so : the point lies on the decision boundary.
k-nearest neighbours (k-NN)
Definition. To classify a new point, find the training points closest to it (usually by Euclidean distance) and take a majority vote of their labels (for regression, average their values). There is no training step: k-NN is a lazy, non-parametric method.
- Small (e.g. ): very flexible boundary, low bias, high variance, sensitive to noise.
- Large : smoother boundary, higher bias, lower variance. always predicts the majority class.
- Features must be on comparable scales, because distance mixes them.
Example 4. Training points: A class +, B class +, C class −, D class −. Query . Squared distances: A 2, B 1, C 8, D 13. With the nearest are B, A, C: two + and one −, so predict +.
Naive Bayes
Definition. Bayes' theorem gives . Naive Bayes assumes the features are conditionally independent given the class:
The probabilities are estimated by counting in the training data. A zero count makes the whole product zero, so Laplace (add-one) smoothing is used: .
Example 5. Classes: Spam with prior 0.4, Ham with prior 0.6. , . For an email containing "offer": Spam score , Ham score . Normalising, . Predict Spam.
Linear discriminant analysis (LDA)
Definition. LDA assumes each class is Gaussian with its own mean but a shared covariance matrix . Then the boundary between classes is linear. For two classes, Fisher's LDA projects onto the direction
which maximises the separation of the projected means relative to the spread within each class.
Exam point. Shared covariance gives a linear boundary (LDA); separate covariances give a quadratic boundary (QDA).
Support vector machines (SVM)
Definition. For linearly separable data, the SVM finds the hyperplane with the largest margin. With the scaling for every point, the margin width is , so we
The points with lie on the margin and are the support vectors; only they determine the boundary. The soft-margin SVM allows some violations with a cost (large : fewer violations, narrower margin). Kernels (polynomial, RBF) replace dot products by to get non-linear boundaries.
Example 6. If the optimal , then and the margin width is .
Decision trees
Definition. A decision tree splits the data on one feature at a time, choosing the split that makes the child nodes as pure as possible. Two common impurity measures for a node with class proportions :
Information gain of a split = entropy of the parent − weighted average entropy of the children. The split with the largest gain is chosen. Deep trees overfit; limiting depth or pruning helps.
Example 7. A node with 4 positive and 4 negative examples has bit and Gini . A split sends (4+, 0−) left and (0+, 4−) right: both children have entropy 0, so the information gain is 1 bit, the best possible.
Example 8. Node with 6 positive, 2 negative: , Gini .
Bias, variance and model complexity
Definition. The expected squared error of a model at a point splits into
- Bias: error from wrong assumptions (a straight line for curved data). High bias means underfitting: high training and test error.
- Variance: sensitivity to the particular training set. High variance means overfitting: low training error, high test error.
- More complex models (deeper trees, smaller , higher-degree polynomials, smaller ) lower bias and raise variance.
Exam point. Regularisation (ridge, pruning, larger ) reduces variance at the cost of some bias. More training data reduces variance but not bias.
Cross-validation
k-fold cross-validation splits the data into equal folds. Each fold is used once as the validation set while the model trains on the other ; the validation errors are averaged. Each model is trained times. Leave-one-out (LOOCV) is the case .
You have read the free 28% of this note
Sign in with Google to keep reading. It is free, takes one tap, and you also get:
- 6 practice questions from this note
- Every note in full, plus the PDF library
- Official past papers as timed tests, with explanations
- An AI tutor for doubts, in Hindi or English
- Your progress, mistakes and study plan saved on every device