Data Warehousing and Data Mining ยท Unit 6 ยท 10 hrs
Classification and Prediction
Exam-focused notes for Classification and Prediction (Data Warehousing and Data Mining, CSC420): what the TU syllabus asks and how it has actually been tested, with 11 solved past questions from this unit.
Classification and Prediction in short
Classification and prediction both build a model from labelled training data and then use that model to say something about a new, unseen case. This unit builds a decision tree by hand with information gain, computes a Naive Bayes posterior, works through rule based classifiers, support vector machines and backpropagation, and finishes with the tools used to judge whether a classifier is actually any good: confusion matrix metrics, cross validation, and a test for comparing two classifiers.
What this unit covers
- Definition (Classification, Prediction)
- Learning and testing of classification
- Classification by decision tree induction
- ID3 as attribute selection algorithm
- Bayesian classification
- Laplace smoothing
- Classification by backpropagation
- Rule based classifier (Decision tree to rules, rule coverage and accuracy, efficient of rule simplification)
- Support vector machine
- Evaluating accuracy (precision, recall, f-measure)
- Issues in classification
- Overfitting and underfitting
- K-fold cross validation
- Comparing two classifier (McNemar's test)
ID3 as attribute selection algorithm
2081 ยท 10 marks
Decision Tree Classification with ID3 Algorithm
Show solved answerHide answer
Overfitting and Underfitting + ID3 Decision Tree
Given
| TID | Age | Car Type | Class |
|---|---|---|---|
| 1 | โค30 | Family | High |
| 2 | โค30 | Sports | High |
| 3 | >30 | Sports | High |
| 4 | >30 | Family | Low |
| 5 | >30 | Truck | Low |
| 6 | โค30 | Family | High |
- Total tuples = 6
- Class High: TID 1, 2, 3, 6 โ 4 tuples
- Class Low: TID 4, 5 โ 2 tuples
- Attributes: Age (โค30, >30), Car Type (Family, Sports, Truck)
Part 1: Definitions
Overfitting
Overfitting occurs when a model learns the training data too well, capturing noise and random fluctuations rather than the underlying pattern. It shows high accuracy on training data but poor accuracy on unseen/test data. In decision trees, this happens when the tree grows too deep.
Underfitting
Underfitting occurs when a model is too simple to capture the underlying structure of the data. It shows poor accuracy on both training and test data. In decision trees, this happens when the tree is too shallow.
Part 2: ID3 Algorithm
Step 1: Entropy of the whole dataset
$$Entropy(S) = -\frac{4}{6}\log_2\frac{4}{6} - \frac{2}{6}\log_2\frac{2}{6}$$
$$= -\tfrac{2}{3}(-0.585) - \tfrac{1}{3}(-1.585) = 0.390 + 0.528 = 0.918$$
Step 2: Gain for Age
Age = โค30: TID 1, 2, 6 โ High:3, Low:0 โ $Entropy = 0$
Age = >30: TID 3, 4, 5 โ High:1, Low:2
$$Entropy(>30) = -\tfrac{1}{3}\log_2\tfrac{1}{3} - \tfrac{2}{3}\log_2\tfrac{2}{3} = 0.528 + 0.390 = 0.918$$
$$Info_{Age}(S) = \tfrac{3}{6}(0) + \tfrac{3}{6}(0.918) = 0.459$$
$$Gain(Age) = 0.918 - 0.459 = 0.459$$
Step 3: Gain for Car Type
Family: TID 1, 4, 6 โ High:2, Low:1 โ $Entropy = 0.918$ Sports: TID 2, 3 โ High:2, Low:0 โ $Entropy = 0$ Truck: TID 5 โ High:0, Low:1 โ $Entropy = 0$
$$Info_{CarType}(S) = \tfrac{3}{6}(0.918) + \tfrac{2}{6}(0) + \tfrac{1}{6}(0) = 0.459$$
$$Gain(CarType) = 0.918 - 0.459 = 0.459$$
Step 4: Select Root
| Attribute | Gain |
|---|---|
| Age | 0.459 |
| Car Type | 0.459 |
Both are tied at 0.459. Selecting Age as root (either is valid).
Step 5: Split on Age
Age
/ \
โค30 >30
[1,2,6] [3,4,5]
H:3,L:0 H:1,L:2
PUREโHigh impure
- Age โค30: all High โ leaf Class = High
- Age >30: TID 3 (High), 4 (Low), 5 (Low) โ not pure, split further.
Step 6: Split the (Age > 30) subset
Remaining attribute: Car Type. Subset = {3, 4, 5}.
- Sports: TID 3 โ High โ pure โ High
- Family: TID 4 โ Low โ pure โ Low
- Truck: TID 5 โ Low โ pure โ Low
Entropy of each subset = 0, so Car Type perfectly classifies this subset.
Final Decision Tree
Age
/ \
โค30 >30
| |
[High] Car Type
/ | \
Sports Family Truck
| | |
[High] [Low] [Low]
Classification Rules
- If Age โค 30 โ High
- If Age > 30 AND Car = Sports โ High
- If Age > 30 AND Car = Family โ Low
- If Age > 30 AND Car = Truck โ Low
This tree classifies all 6 training tuples correctly.
The completed tree splits the (Age > 30) subset on Car Type, with entropy = 0.918, both gains = 0.459 and Age chosen as the root, the left branch being pure High.
2080 ยท 10 marks
How Classification Differs from Regression. Train ID3 Classifier
Show solved answerHide answer
Classification vs Regression and ID3 Decision Tree
Part 1: Classification vs Regression
| Aspect | Classification | Regression |
|---|---|---|
| Output | Discrete class label (e.g. Up/Down) | Continuous numeric value |
| Goal | Assign a tuple to a predefined category | Predict a numeric quantity |
| Example | Loan = "safe"/"risky" | Predicting house price |
| Algorithms | ID3, Naive Bayes, KNN | Linear/Polynomial Regression |
| Evaluation | Accuracy, Precision, Recall | RMSE, MAE |
Classification predicts a discrete categorical label; regression predicts a continuous ordered value.
Part 2: ID3 Classifier
Given data
9 tuples: Class Up = 5, Down = 4.
Step 1: Entropy of dataset
$$E(D) = -\tfrac{5}{9}\log_2\tfrac{5}{9} - \tfrac{4}{9}\log_2\tfrac{4}{9} = 0.4711 + 0.5200 = 0.9911$$
Step 2: Information Gain
Age: old(3): 0Up,3Down; mid(3): 2Up,1Down; new(3): 3Up,0Down
$$E(\text{old})=0,\quad E(\text{new})=0$$ $$E(\text{mid}) = -\tfrac{2}{3}\log_2\tfrac{2}{3}-\tfrac{1}{3}\log_2\tfrac{1}{3}=0.9183$$ $$E_{\text{Age}} = \tfrac{3}{9}(0)+\tfrac{3}{9}(0.9183)+\tfrac{3}{9}(0)=0.3061$$ $$\text{Gain(Age)} = 0.9911 - 0.3061 = 0.6850$$
Competition: Yes(4): 2Up,2Down; No(5): 3Up,2Down
$$E(\text{Yes})=1.0,\quad E(\text{No})=0.9710$$ $$E_{\text{Comp}} = \tfrac{4}{9}(1.0)+\tfrac{5}{9}(0.9710)=0.9838$$ $$\text{Gain(Competition)} = 0.9911-0.9838 = 0.0073$$
Type: SW(5): 2Up,3Down; HW(4): 3Up,1Down
$$E(\text{SW})=0.9710,\quad E(\text{HW})=0.8113$$ $$E_{\text{Type}} = \tfrac{5}{9}(0.9710)+\tfrac{4}{9}(0.8113)=0.5394+0.3606=0.9000$$ $$\text{Gain(Type)} = 0.9911-0.9000 = 0.0911$$
Root = Age (highest gain 0.6850).
Step 3: Split on Age
- Age = old โ all Down โ leaf Down
- Age = new โ all Up โ leaf Up
- Age = mid โ mixed, needs further split.
Step 4: Subtree for Age = mid
| Competition | Type | Profit |
|---|---|---|
| Yes | SW | Down |
| No | HW | Up |
| Yes | HW | Up |
Subset: 3 tuples (2 Up, 1 Down). $$E(D_{mid}) = -\tfrac{2}{3}\log_2\tfrac{2}{3}-\tfrac{1}{3}\log_2\tfrac{1}{3}=0.9183$$
Competition: Yes(2): 1Up,1Down โ E=1.0; No(1): 1Up โ E=0 $$E_{\text{Comp}} = \tfrac{2}{3}(1.0)+\tfrac{1}{3}(0)=0.6667$$ $$\text{Gain} = 0.9183-0.6667 = 0.2516$$
Type: SW(1): 0Up,1Down โ E=0; HW(2): 2Up โ E=0 $$E_{\text{Type}} = 0 \Rightarrow \text{Gain} = 0.9183 ;(\text{maximum})$$
Split on Type:
- Type = SW โ Down
- Type = HW โ Up
Final Decision Tree
Age?
โโโ old โ Down
โโโ new โ Up
โโโ mid โ Type?
โโโ SW โ Down
โโโ HW โ Up
Step 5: Prediction for [Age = Mid, Competition = Yes, Type = HW]
Age = mid โ check Type โ Type = HW โ Up
$$\boxed{\text{Predicted Profit = Up}}$$
Support vector machine
2081 ยท 5 marks
What is support vector? How do you evaluate the accuracy of a classifier? Describe. [5]
Show solved answerHide answer
Support Vector and Classifier Accuracy Evaluation
Part 1: What is a Support Vector?
A Support Vector Machine (SVM) is a supervised learning algorithm used primarily for classification problems. It works by finding the optimal hyperplane that best separates data points belonging to different classes.
Support Vectors are the data points that lie closest to the decision boundary (hyperplane). These are the critical points that directly influence the position and orientation of the hyperplane.
Key points about support vectors:
- They are the boundary data points from each class
- The margin is defined as the distance between the hyperplane and the nearest support vectors from each class
- SVM aims to maximize this margin to achieve the best separation
- Removing support vectors would change the position of the hyperplane
- SVM takes input data points and outputs the hyperplane (decision boundary) that separates the classes
Example: If the hyperplane equation is 2x - 2 = 0, the support vectors are the points that satisfy the margin constraints on either side of this boundary.
Part 2: Evaluating the Accuracy of a Classifier
Confusion Matrix
A Confusion Matrix is an N x N matrix used to evaluate the performance of a classification model, where N is the number of target classes.
For a binary classification, it is a 2 x 2 matrix:
| Predicted: Positive | Predicted: Negative | |
|---|---|---|
| Actual: Positive | TP (True Positive) | FN (False Negative) |
| Actual: Negative | FP (False Positive) | TN (True Negative) |
Definitions:
- TP (True Positive): Both actual and predicted classes are positive (correctly classified positive)
- TN (True Negative): Both actual and predicted classes are negative (correctly classified negative)
- FP (False Positive): Predicted positive but actually negative -- called Type I Error
- FN (False Negative): Predicted negative but actually positive -- called Type II Error
Four Performance Measures
1. Accuracy
$$\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}$$ Measures the overall proportion of correctly classified instances.
2. Precision
$$\text{Precision} = \frac{TP}{TP + FP}$$ Measures how many of the predicted positives are actually positive.
3. Recall (Sensitivity)
$$\text{Recall} = \frac{TP}{TP + FN}$$ Measures how many of the actual positives were correctly identified.
4. F1-Score
$$\text{F1-Score} = \frac{2 \times \text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}}$$ The harmonic mean of Precision and Recall; useful when there is a class imbalance.
Summary Table
| Measure | Formula | What it tells |
|---|---|---|
| Accuracy | (TP+TN)/(TP+TN+FP+FN) | Overall correctness |
| Precision | TP/(TP+FP) | Quality of positive predictions |
| Recall | TP/(TP+FN) | Coverage of actual positives |
| F1-Score | 2PR/(P+R) | Balance between precision and recall |
These four measures together provide a comprehensive evaluation of a classifier's performance beyond simple accuracy.
2080 ยท 5 marks
Write down short notes on: a. Support Vector Machine b. Multi-dimensional Data Model [5]
Classification by backpropagation
2080 ยท 5 marks
Which algorithm is used for training multi-layer perceptron? Discuss the algorithm in detail. [5]
2079 ยท 10 marks
When Multilayer Perceptron is Better Choice Over Other Classification Algorithms
Consider a multilayer feed-forward neural network given below. Let the learning rate be 0.5. Assume initial values of weights and biases as given in the table below. Train the network for the training tuples (1, 1, 0) and (0, 1, 1), where last number is target output. Show weight and bias updates by using back-propagation algorithm. Assume that sigmoid activation function is used in the network.
$$\begin{array}{c|c|c|c|c|c|c|c|c} w_{13} & w_{14} & w_{23} & w_{24} & w_{35} & w_{45} & b_3 & b_4 & b_5 \ \hline 0.5 & 0.2 & -0.3 & 0.5 & 0.1 & 0.3 & 0.6 & -0.4 & 0.8 \ \end{array}$$
[10]
Evaluating accuracy
2079 ยท 5 marks
What is confusion matrix? Discuss various classification measures along with their mathematical formulae. [5]
Bayesian classification
2078 ยท 5 marks
Consider the following data set. Find out whether the object with attribute Confident = Yes, Sick = No will Fail or Pass using Bayesian classification.
| Confident | Studied | Sick | Result |
|---|---|---|---|
| Yes | No | No | Fail |
| Yes | No | No | Pass |
| No | Yes | Yes | Fail |
| No | Yes | Yes | Pass |
| Yes | Yes | Yes | Pass |
[5]
K-fold cross validation
2078 ยท 5 marks
How do you evaluate the accuracy of a classifier? Discuss the advantages of using K-fold cross validation. [5]
Definition
2076 ยท 5 marks
How classification plays significance role in data mining? Explain. [5]
Classification by decision tree induction
2076 ยท 5 marks
Write short notes on (Any Two): a. Evolution analysis b. Decision trees c. Text mining d.Classification using Regression [5]
Make Unit 6 stick
Practice CSC420 with flashcards & quizzes