Sources: 5_Classification.pdf; past questions: QP_DM_SEM_25.pdf, pqy26.pdf. Slide numbers refer to PDF pages.
Learn the labelled-data workflow, k-NN, decision-tree induction and splitting calculations, then confusion matrices and evaluation. The supplied lecture emphasizes classification; numeric prediction is included briefly to distinguish it from classification.
Important: Study all classification algorithms in the slides, especially k-NN and decision trees. Practise decision-tree calculations, confusion matrices, accuracy, precision, recall, F1 score and ROC-curve calculations.
Not explicitly mentioned: Prediction/regression and testing methods are not individually named in the guidance. They are retained as context, not declared excluded. General classification approaches remain relevant because the guidance says all algorithms.
1. Classification and prediction — ⭐ IMPORTANT CLASSIFICATION; prediction not explicitly mentioned
Classification is supervised learning: use records with known class labels to learn a model that predicts the discrete label of a new record. Examples are spam/not spam, fraud/not fraud or benign/malignant. Numeric prediction/regression estimates a continuous quantity such as house price. Some authors use “prediction” broadly to include class prediction.
A useful classifier must generalize to unseen cases, rather than memorize training data. Classification methods include decision trees, nearest neighbours, Bayesian classifiers, neural networks, support vector machines and rule-based methods. Data preparation, appropriate features, missing values and class imbalance influence performance.
Give the system labelled email examples; it learns a rule and predicts whether a new email is spam. By contrast, clustering groups emails without first being given category labels.
Explain classification and clustering with examples; distinguish classification from regression.
Classification learns categorical labels, e.g. spam/not spam; clustering groups unlabeled records by similarity; regression predicts a numerical value such as house price.
2. Distance-based classification: k nearest neighbours — ⭐ IMPORTANT ALGORITHM + NUMERICAL
k-NN stores labelled training examples. For an unseen point :
- Choose , the distance measure and any scaling.
- Compute distances from to training points and find the nearest.
- Predict the majority class; optionally weight closer neighbours more. Specify a tie rule.
For two numeric attributes, Euclidean distance is ; Manhattan distance is . Normalize features when their scales differ, otherwise a large-unit feature dominates. Categorical features need a suitable dissimilarity measure.
Example: training points A=(1,1), class Red; B=(2,1), Red; C=(4,4), Blue. Query Q=(2,2) has distances . For , two of the three neighbours are Red, so predict Red. With , the nearest is B, also Red.
Small can be sensitive to noise; large gives smoother decisions but can hide small classes. Choose using validation, not the final test set. k-NN is a lazy learner: little model fitting, but prediction and storage can be expensive. Irrelevant features and high dimensionality degrade distance quality.
2025 CO4(a) (3+7 marks): Explain different classification techniques. Explain k-nearest neighbor algorithm with an example.
2026 CO4(b)(i): What are centroid and medoid? Discuss any distance based classification algorithm with example.
Classification learns a model from records whose class labels are known and uses that model to assign a label to a new record. Common techniques include:
- Decision trees: Apply a sequence of attribute tests; the reached leaf gives the predicted class.
- k-nearest neighbours (k-NN): Assign the majority label among the closest labelled training records.
- Bayesian classification: Use probabilities to estimate the most likely class given the attributes.
- Neural networks: Learn a function from inputs to class predictions by adjusting connection weights during training.
k-NN algorithm: Store the labelled training data. Choose and a distance function. For a new object, calculate its distance to each training object, select the closest, and assign their majority class. If a tie occurs, use a stated tie-breaking rule. Numeric attributes should be scaled when their units would otherwise dominate the distance.
For example, take A=(1,1), Red, B=(2,1), Red and C=(4,4), Blue. For the new point Q=(2,2), Euclidean distances are , and . With , two neighbours are Red and one is Blue, so Q is classified as Red.
A centroid is the coordinate-wise mean of the points in a cluster; it need not be a data object. A medoid is an actual object selected to represent a cluster, commonly by minimizing total distance to its members.
2024 CT2 Q2: Explain the k-nearest-neighbour classification algorithm with an example.
Choose a value of and a distance measure. Calculate the distance from the new record to each labeled training record, select the smallest distances, and predict the majority class among those neighbors. Scale features when their units would otherwise dominate the distance.
For example, with , suppose the three nearest neighbors of a new customer have labels buys, buys, and does not buy. The majority vote predicts buys. A tie-breaking rule should be specified where a tie is possible.
3. Decision trees and induction — ⭐ IMPORTANT ALGORITHM
A decision tree represents a sequence of tests. An internal node tests an attribute, a branch is an outcome, and a leaf gives a class label. To classify a record, follow its test outcomes from root to leaf.
Hunt’s recursive idea: at node , let be the records reaching it. If all have the same class, make a leaf. If records have mixed labels and a useful test exists, choose a good split and recurse on its nonempty children. If no usable split remains, use the node’s majority class; handle an empty branch using the parent’s majority or a specified default.
build(D):
if D is pure: return leaf(its class)
if no useful split or stopping rule applies: return leaf(majority class)
choose the best attribute/test
split D into children and recursively build each childDecision trees use greedy local choices; a locally best split need not produce a globally smallest tree. Nominal attributes can use multiway or binary subset tests; ordinal splits should respect order; numeric features can use thresholds such as age ≤ 30 versus > 30, chosen between sorted values. Stop when nodes are pure, too small, sufficiently shallow, or improvement is negligible. Pre-pruning stops early; post-pruning removes branches after training to reduce overfitting.
Advantages: interpretable, handles mixed feature types, little scaling needed. Limitations: unstable to small training changes, greedy splits, overfitting, and potential bias of some split criteria.
4. Selecting the best split — ⭐ IMPORTANT NUMERICAL
Let be the proportion of class at a node with records. Impurity is zero at a pure node.
Treat as zero. Entropy is maximized at equal proportions; for two balanced classes it is 1 bit. Gini for two balanced classes is 0.5. Classification error ignores changes to non-majority classes and can be less sensitive during splitting.
For a split producing children :
Choose the candidate with highest information gain, or equivalently lowest weighted child entropy. For Gini, select the split with lowest weighted child Gini (or highest decrease). Information gain tends to favour attributes with many values; gain ratio divides gain by split information:
Gain ratio is undefined if split information is zero; implementations also guard against choosing a tiny-gain split merely because its denominator is small. CART commonly uses Gini; ID3 uses information gain and C4.5 uses gain ratio.
Worked split: parent has 6 Yes and 4 No, . An attribute splits into (4 Yes, 0 No) and (2 Yes, 4 No). Weighted entropy is ; information gain is bits. Compare this value with every other candidate; do not select a split without comparison.
2025 CO4(c) (4+6 marks): Explain about the measures for selecting the best split. In the above dataset ‘Object Table’, calculate the entropy of the ‘Target Location’ attribute in the entire dataset?
The Object Table is shown in the original question image below; it belongs to CO4(b) and is reused in CO4(c).
2026 CO4(b)(iii): Discuss the relationship between entropy and information gain.
A decision tree selects splits that make the resulting nodes as pure as possible. Let be the fraction of records belonging to class .
- Entropy: . A pure node has entropy zero. For a candidate attribute, calculate the weighted entropy of its child nodes.
- Information gain: . It is the reduction in uncertainty caused by splitting on A. The candidate with the highest gain is preferred.
- Gini index: . Calculate the weighted Gini of the children and prefer the split with the smallest weighted value.
- Gain ratio: Divide information gain by the split information of the attribute. This helps address information gain’s preference for attributes with many distinct values.
For the 2025 Object Table, the target counts are: Shelf 1 = 2, Shelf 2 = 3, Shelf 3 = 3 and Shelf 4 = 2, out of 10 records. Therefore:
To find information gain for a particular attribute, subtract its weighted child entropy from this parent entropy.
Build a decision tree from the employee table using information gain, gain ratio or Gini index, as specified in each. The 2022 paper asks for Gini, gain ratio and information gain after the specified age and salary discretization, and asks about pre/post-pruning, repetition, replication, coverage, accuracy and overfitting. The 2024 class test asks for the class of <0.7, 0.4, red traffic light, no pedestrian crossing> from its traffic table. State the split criterion and numeric threshold choices: the paper does not specify them, so a unique tree is not guaranteed.
2024 CT2 Q3: Use information gain and treat each distinct traffic-control device as a categorical branch. There are 3 Slow down, 4 Stop and 3 Go records, so the initial entropy is approximately . Splitting by traffic-control device gives gain approximately ; the best binary thresholds for speed and distance each give approximately , and pedestrian presence gives approximately . Thus the device is the root under these choices.
The two Red traffic light examples are both labeled Go. The new sample has a red traffic light, so the resulting branch predicts Go. This follows the training labels, even though it is counterintuitive for real-world driving. The tree’s other mixed No traffic sign branch needs an additional split to classify all training rows.
2022 employee table: Discretize age and salary as the question specifies. The 14 rows contain 6 seniors and 8 juniors, so and . For multiway splits the results are:
| Attribute | Information gain | Gain ratio | Weighted Gini |
|---|---|---|---|
| Department | 0.0202 | 0.0102 | 0.4762 |
| Age | 0.6385 | 0.4171 | 0.1714 |
| Salary | 0.3219 | 0.2156 | 0.3112 |
Age wins under all three criteria. Low-aged has six juniors, high-aged has three seniors, and middle-aged has three seniors and two juniors. For middle-aged, salary has gain , gain ratio , and weighted Gini ; it beats department. Thus the tree is:
age
├─ low-aged → junior
├─ high-aged → senior
└─ middle-aged → salary
├─ low → junior
├─ high → senior
└─ medium → department
├─ sales → senior
└─ marketing → senior / junior tieThe two marketing/middle-aged/medium-salary rows have identical predictors but opposite labels. No tree using these attributes can separate them; use an explicitly stated tie rule, e.g. parent majority senior. The stated results treat categorical values as multiway branches; a binary-only Gini tree may have a different shape.
Pre-pruning stops splitting early; post-pruning removes branches after growing the tree. Repetition is repeated testing of an attribute along a path; replication is duplication of a subtree on different branches. Rule coverage is the proportion of records satisfying its condition; accuracy is the proportion of covered records correctly classified.
5. Decision-tree PYQs worked — ⭐ IMPORTANT NUMERICAL PRACTICE
2025 CO4(b) (3+7 marks): Discuss the significance of information gain in decision tree. In the above dataset ‘Object Table’, there are five discrete attributes: Object Shape, Object Size, Object Weight, Object Color, and Target Location, and the Target Location is the target variable we want to predict. Apply Decision Tree based method to identify class label (Target Location) to a new sample <Triangle, Medium, Light, Blue>.
The target has four classes with counts Shelf 1: 2, Shelf 2: 3, Shelf 3: 3, Shelf 4: 2. Its initial entropy is approximately 1.971 bits.
Consider splitting on Color. The Red branch has four records: two Shelf 1 and two Shelf 4, so its entropy is 1 bit. All three Blue records are Shelf 2 and all three Green records are Shelf 3, so those branches have entropy zero. The weighted child entropy is
Therefore bits. Comparing candidate attributes shows that Color gives the largest information gain, so it is selected as the root. The mixed Red branch can be split by Weight:
Color
├─ Blue → Shelf 2
├─ Green → Shelf 3
└─ Red → Weight
├─ Light → Shelf 1
└─ Heavy → Shelf 4For <Triangle, Medium, Light, Blue>, follow Color = Blue directly to Shelf 2. Information gain measures the reduction in class entropy produced by a split; a larger gain means the child nodes are purer on average.
2026 CO4(a) (4+10+6 marks): Briefly explain classification problems and general approaches to solve them. The following table consists of training data from an employee database. Assuming “buys_computer” as class label attribute, select appropriate splitting attribute and draw the decision tree. How can you measures that your selected splitting attribute is the best?
The question starts at the bottom of page 1; its table and continuation appear at the top of page 2.
Classification learns from examples with known class labels and predicts a discrete class for a new record. A general approach is to prepare labelled data, train a model such as a decision tree, k-nearest-neighbour, Bayesian classifier or neural network, and evaluate its predictions on unseen test data.
The paper contains eight labelled records: four Yes and four No. Thus the class entropy before splitting is
For age, the senior branch contains 3 Yes and 0 No, the middle branch contains 0 Yes and 2 No, and the youth branch contains 1 Yes and 2 No. The first two branches have zero entropy; youth has entropy . Hence
Applying the same calculation to the other attributes gives Gain(income) ≈ 0.3113, Gain(student) = 0 and Gain(credit_rating) = 0. Age has the largest gain and is selected as the root. In the youth subset, income separates the single Yes record from the two No records:
age
├─ senior → buys_computer = Yes
├─ middle → buys_computer = No
└─ youth → income
├─ medium → Yes
├─ low → No
└─ high → NoThe best split is measured by calculating the weighted entropy after each candidate split and selecting the greatest information gain. This tree fits the given training records; a separate test set is needed to assess its performance on new records.
Select an attribute and construct the tree from each set’s employee table: Set 1 uses information gain, Set 2 gain ratio, and Sets 3 and 4 Gini index.
Treat categorical attributes as multiway splits. For information gain and gain ratio select the largest value; for Gini select the smallest weighted child impurity. Abbreviations: M = middle-aged, Y = youth, S = senior, E = excellent, F = fair.
Sets 1 and 2 use the same nine rows, with 3 yes and 6 no, so parent entropy is .
| Attribute | Information gain | Gain ratio |
|---|---|---|
| Age | 0.2516 | 0.1644 |
| Income | 0.0294 | 0.0192 |
| Student | 0.2516 | 0.2740 |
| Credit rating | 0.0183 | 0.0185 |
Set 1: Age and student tie for maximum gain; choose age. For senior predict no. For youth split by income: high and low → no; medium → split on student, no → yes and yes → no. For middle-aged split by income: high → yes; low contains one yes and one no with identical predictors, so no available split can distinguish them; use a stated tie rule.
Set 2: Student has maximum gain ratio. Student = yes → no. Student = no → split by age: senior → no; youth → income low: no, medium: yes; middle-aged → income high: yes, low: the same unresolved yes/no tie. A tie rule is required because the records have identical attribute values and contradictory labels.
Set 3: Parent has four yes and four no. Weighted Gini for age, income, student and credit rating is , respectively. Choose age: senior → yes, middle-aged → no, youth → income; youth income medium → yes and low/high → no.
Set 4: Parent has five yes and five no. The corresponding weighted Gini values are ; choose student. For student = yes, split income: high → no, medium/low → yes. For student = no, split income: low/medium → no; high has two records with identical predictors and opposite labels. Use a stated tie rule at that leaf. A binary-only Gini convention may produce a different tree.
6. Confusion matrix and evaluation — ⭐ IMPORTANT NUMERICAL: ACCURACY / PRECISION / RECALL / F1
| Actual \ Predicted | Positive | Negative |
|---|---|---|
| Positive | TP | FN |
| Negative | FP | TN |
When a denominator is zero, the corresponding metric needs an explicit convention and may be undefined. Precision asks how many predicted positives were correct; recall asks how many actual positives were found. High accuracy can be misleading on imbalanced data: always predicting “not fraud” gives 99% accuracy if only 1% are fraud, but detects no fraud.
2026 CO4(b)(iv): What is a confusion matrix? Explain with one example.
A confusion matrix compares actual class labels with the labels predicted by a classifier. For a binary classifier:
| Actual / predicted | Positive | Negative |
|---|---|---|
| Positive | True positive (TP) | False negative (FN) |
| Negative | False positive (FP) | True negative (TN) |
Suppose a disease test on 100 people has TP = 40, FN = 10, FP = 5 and TN = 45. It correctly identifies 40 people with the disease, misses 10, incorrectly flags 5 healthy people and correctly identifies 45 healthy people.
Accuracy measures overall correctness, precision measures the correctness of positive predictions, and recall measures the fraction of actual positives detected. The matrix reveals whether errors are false positives or false negatives.
7. Reliable testing and ROC — ⭐ IMPORTANT: ROC CALCULATIONS; testing methods not explicitly mentioned
A holdout set separates training and test data; use a separate validation set for hyperparameters. In k-fold cross-validation, divide training data into k folds, repeatedly train on k−1 and validate on the remaining fold, then average. Stratification preserves class proportions when appropriate. Avoid leakage: fit preprocessing only on each training fold. Keep the final test set untouched until model selection is complete.
An ROC curve plots TPR against FPR as the classification threshold varies. Each threshold yields a point; the diagonal represents random ranking and the upper-left is ideal. AUC summarizes ranking across thresholds; a single threshold and class-sensitive metrics remain important, particularly for rare positives. Crossing curves mean that the preferred model can depend on the operating point/cost.
For a tree numerical: write class counts → entropy → each candidate’s weighted entropy → information gain → chosen root → recurse → prediction. For confusion matrices label actual/predicted axes before calculating metrics.























