Supervised Learning MCQs for the NSCT
Supervised learning trains a model on examples that already carry the correct answer (a label), so it can predict that answer for new inputs: a number in regression, a category in classification. It is the sixth of the 17 topics in the AI / Machine Learning and Data Analytics area, which carries 10% of the NSCT according to HEC's Areas of Competencies.
Expect hand calculations (a regression prediction, a KNN distance, Gini or entropy) and diagnosis questions about overfitting and the choice of algorithm. Clean, scaled inputs from Data Collection & Pre-processing are assumed throughout.
Regression
Regression predicts a continuous value. Linear regression fits y = b0 + b1x1 + ... + bnxn, and ordinary least squares (OLS) chooses the coefficients that minimise the sum of squared residuals. With y = 50 + 4x, a student who studies 10 hours is predicted to score 90.
Common error measures: MSE (mean of squared errors), RMSE (its square root, in the target's units) and MAE (mean absolute error). Ridge (L2) and Lasso (L1) add a penalty on coefficient size to curb overfitting.
Exam angle: a U-shaped residual plot means the straight line misses curvature. Add polynomial terms or use a non-linear model.
Classification
Classification predicts a discrete class: binary (spam or not) or multi-class (digit 0 to 9).
Logistic regression computes a linear score z and turns it into a probability with the sigmoid, 1 / (1 + e^-z). At z = 0 the probability is 0.5; at z = 2 it is about 0.88. A threshold, 0.5 by default, gives the class. Naive Bayes applies Bayes' theorem with the assumption that features are independent given the class.
Exam angle: logistic regression is a classifier despite its name. Lowering its threshold flags more positives, raising recall and usually lowering precision.
KNN
k-nearest neighbours stores the training data and, for a query, finds the k closest points and takes a majority vote (or an average for regression). It is a lazy, instance-based learner.
| Distance | Formula for (3, 4) to (6, 8) | Result |
|---|---|---|
| Euclidean (L2) | sqrt(3² + 4²) | 5 |
| Manhattan (L1) | 3 + 4 | 7 |
Small k gives low bias and high variance (overfitting); large k smooths the boundary, and k equal to the training-set size always predicts the majority class. Choose k by cross-validation and use an odd k for two classes to avoid ties.
Exam angle: KNN needs feature scaling, and it degrades with many irrelevant features (the curse of dimensionality).
SVM
A support vector machine finds the hyperplane w.x + b = 0 with the widest margin between classes. The margin width is 2 / ||w||, and only the support vectors, the points on or inside the margin, define it.
- Soft margin: the parameter C trades margin width for training errors. Large C means few violations, a narrow margin and more overfitting risk.
- Kernel trick: kernels such as polynomial and RBF give non-linear boundaries without computing the high-dimensional mapping.
Exam angle: deleting a point that is not a support vector leaves the boundary unchanged.
Decision trees
A decision tree tests one feature at each internal node and gives a prediction at each leaf. It picks the split that most reduces impurity.
| Measure | Formula | Pure node | 50/50 two-class node |
|---|---|---|---|
| Entropy (ID3, C4.5) | -Σ p log2 p | 0 | 1 |
| Gini (CART) | 1 - Σ p² | 0 | 0.5 |
For a node with 3 positive and 1 negative, entropy is 0.811 and Gini is 0.375. Information gain is parent entropy minus the weighted entropy of the children. It favours attributes with many values, which is why C4.5 uses the gain ratio.
Trees need no scaling and are easy to read, but deep trees overfit. Pre-pruning (max depth, minimum samples per leaf) or post-pruning helps, and Ensemble Learning combines many trees.
Common traps
- Calling logistic regression a regression algorithm in "regression or classification?" questions.
- Mixing up the maximums: two-class entropy peaks at 1, Gini at 0.5.
- Forgetting to weight child impurities by their sample share when scoring a split.
- Reading 100% training accuracy with k = 1 as a good model. Each point is its own nearest neighbour.
- Thinking a larger C widens the SVM margin. It narrows it.
- Using linear regression for 0/1 labels. Outputs fall outside 0 to 1.
Worked examples
1. Understanding. A bank predicts whether an applicant will default (yes or no) from past labelled loans. Which learning type and task is this? Answer: supervised binary classification. The labels are known for past loans and the target has two classes.
2. Application. A node has 8 'yes' and 2 'no' samples. What is its Gini impurity? Answer: 1 - (0.8² + 0.2²) = 1 - (0.64 + 0.04) = 0.32.
3. Analysis. An unpruned decision tree scores 99% on training data and 70% on validation data. What should you change first? Answer: the tree is overfitting. Limit its growth with a maximum depth or minimum samples per leaf, chosen by cross-validation, or prune it after training. A random forest is a stronger next step.
Practise
The quiz below has 100 questions on this topic, filterable by tier and difficulty.
Practise: 100 questions
FAQs
What is the difference between regression and classification?
Both are supervised. Regression predicts a continuous number, such as a price or temperature, and is judged with MSE, RMSE or MAE. Classification predicts a category, such as spam or not spam, and is judged with accuracy, precision, recall and F1. Some algorithms, such as KNN and decision trees, can do either.
How do I choose k in KNN?
Try a range of values and keep the one with the best cross-validated score. Small k follows noise and overfits; large k blurs class boundaries and underfits. For binary problems an odd k avoids tied votes. Always scale features first, because distance is dominated by the feature with the largest range.
When should I use an SVM instead of logistic regression?
Both draw linear boundaries by default. An SVM focuses on the hardest points near the boundary and, with a kernel, handles non-linear patterns well on small to medium datasets. Logistic regression gives calibrated probabilities directly and is easier to interpret. Try both and compare on validation data.
Is Gini or entropy better for decision trees?
In practice they usually produce very similar trees. Gini is slightly faster because it needs no logarithms, which is why CART and scikit-learn use it by default. Entropy, used in ID3 and C4.5, comes from information theory and is the basis of information gain. Exam questions may ask you to compute either.
Next step
Continue with Ensemble Learning, the next topic in HEC's order. You can also return to the AI & ML MCQs hub or test yourself in an NSCT mock test.