Chapter 6. Classification: Basic Concepts
1
Supervised vs. Unsupervised Learning (1)
Training Data with class label:
Model
Learning
Positive
Negative
Training
Instances
Test
Instances
Prediction
Model
Outlook | Temp | Humidity | Windy | Play Golf |
Rainy | Hot | High | False | No |
Rainy | Hot | High | True | No |
Overcast | Hot | High | False | Yes |
Sunny | Mild | High | False | Yes |
Sunny | Cool | Normal | False | Yes |
Sunny | Cool | Normal | True | No |
Overcast | Cool | Normal | True | Yes |
Rainy | Mild | High | False | No |
2
Supervised vs. Unsupervised Learning (2)
3
Prediction Problems: Classification vs. Numeric Prediction
4
Classification—Model Construction, Validation and Testing
5
Classification—Model Construction, Validation and Testing
6
Chapter 6. Classification: Basic Concepts
7
Decision Tree Induction: An Example
outlook?
windy?
Humidity?
Sunny
Rainy
Yes
No
No
Overcast
Yes
High
Normal
True
False
Training data set: Play Golf?
Yes
Outlook | Temp | Humidity | Windy | Play Golf |
Rainy | Hot | High | False | No |
Rainy | Hot | High | True | No |
Overcast | Hot | High | False | Yes |
Sunny | Mild | High | False | Yes |
Sunny | Cool | Normal | False | Yes |
Sunny | Cool | Normal | True | No |
Overcast | Cool | Normal | True | Yes |
Rainy | Mild | High | False | No |
Rainy | Cool | Normal | False | Yes |
Sunny | Mild | Normal | False | Yes |
Rainy | Mild | Normal | True | Yes |
Overcast | Mild | High | True | Yes |
Overcast | Hot | Normal | False | Yes |
Sunny | Mild | High | True | No |
https://www.saedsayad.com/decision_tree.htm
8
Decision Tree Induction: Algorithm
9
Decision Tree Induction: Algorithm
10
How to Handle Continuous-Valued Attributes?
11
Pro’s and Con’s
12
Con’s
13
Splitting Measures: Information Gain
m = 2
14
Information Gain: An Attribute Selection Measure
15
Example: Attribute Selection with Information Gain
outlook?
Sunny
Rainy
Overcast
outlook | yes | no | I(yes, no) |
rainy | 2 | 3 | 0.971 |
overcast | 4 | 0 | 0 |
sunny | 3 | 2 | 0.971 |
Outlook | Temp | Humidity | Windy | Play Golf |
Rainy | Hot | High | False | No |
Rainy | Hot | High | True | No |
Overcast | Hot | High | False | Yes |
Sunny | Mild | High | False | Yes |
Sunny | Cool | Normal | False | Yes |
Sunny | Cool | Normal | True | No |
Overcast | Cool | Normal | True | Yes |
Rainy | Mild | High | False | No |
Rainy | Cool | Normal | False | Yes |
Sunny | Mild | Normal | False | Yes |
Rainy | Mild | Normal | True | Yes |
Overcast | Mild | High | True | Yes |
Overcast | Hot | Normal | False | Yes |
Sunny | Mild | High | True | No |
16
Example: Attribute Selection with Information Gain
Temp | Yes | No | I(Yes, No) |
Hot | 2 | 2 | ? |
Mild | 4 | 2 | ? |
Cool | 3 | 1 | ? |
Humidity | Yes | No | I(Yes, No) |
Normal | 6 | 1 | ? |
High | 3 | 4 | ? |
Windy | Yes | No | I(Yes, No) |
True | ? | ? | ? |
False | ? | ? | ? |
Outlook | Temp | Humidity | Windy | Play Golf |
Rainy | Hot | High | False | No |
Rainy | Hot | High | True | No |
Overcast | Hot | High | False | Yes |
Sunny | Mild | High | False | Yes |
Sunny | Cool | Normal | False | Yes |
Sunny | Cool | Normal | True | No |
Overcast | Cool | Normal | True | Yes |
Rainy | Mild | High | False | No |
Rainy | Cool | Normal | False | Yes |
Sunny | Mild | Normal | False | Yes |
Rainy | Mild | Normal | True | Yes |
Overcast | Mild | High | True | Yes |
Overcast | Hot | Normal | False | Yes |
Sunny | Mild | High | True | No |
17
Gain Ratio: A Refined Measure for Attribute Selection
18
Chapter 6. Classification: Basic Concepts
19
Bayes’ Theorem: Basics
posteriori probability
prior probability
likelihood
What we should choose
What we knew previously
What we just see
Prediction can be done based on Bayes’ Theorem:
Classification is to derive the maximum posteriori
20
Bayes’ Theorem Example: Picnic Day
(e.g., P(Rain | Cloud) and P(Cloud | Rain)), tests the reality, which is the most important trick in Bayesian Inference
P(Cloud) = 40%
P(Rain) = 10%
P(Cloud | Rain) = 50%
P(Rain | Cloud) = P(Rain) P(Cloud | Rain) / P(Cloud) = 10% * 50% / 40% = 12.5%
P(Rain | Cloud) = ?
21
Naïve Bayes Classifier: Making a Naïve Bayes Assumption
22
Naïve Bayes Classifier: Categorical vs. Continuous Valued Features
23
Naïve Bayes Classifier Example 1: Training Dataset
Class:
play golf= ‘yes’
play golf = ‘no’
24
Naïve Bayes Classifier Example P(Yes | Sunny)
25
Naïve Bayes Classifier Example: P(No | Sunny)
26
Naïve Bayes Classifier Example: Likelihood Tables
27
Naïve Bayes Classifier Example: Likelihood Tables
P(x) = P( x | yes ) * P (yes) + P( x | no ) * P (no)
/ P(x)
/ P(x)
______________________
P(x)
______________________
P(x)
28
Avoiding the Zero-Probability Problem
income = low (0), income= medium (990), and income = high (10)
Prob(income = low) = 1/(1000 + 3)
Prob(income = medium) = (990 + 1)/(1000 + 3)
Prob(income = high) = (10 + 1)/(1000 + 3)
29
Naïve Bayes Classifier: Strength vs. Weakness
30
Naïve Bayes Classifier: Strength vs. Weakness
Use Bayesian Belief Networks (chapter 7)
31
Chapter 6. Classification: Basic Concepts
32
Lazy vs. Eager Learning
33
Lazy Learner: Instance-Based Methods
34
The k-Nearest Neighbor Algorithm
.
_
+
_
xq
+
_
_
+
_
_
+
.
.
.
.
.
35
Discussion on the k-NN Algorithm
36
Selection of k for kNN
http://scott.fortmann-roe.com/docs/BiasVariance.html
37
Case-Based Reasoning (CBR)
38
Chapter 6. Classification: Basic Concepts
39
Linear Regression Problem: Example
Price of houses
Living Area
40
Linear Regression Problem: Model
41
Linear Regression Model: Solution
(w,b)
42
Logistic Regression: General Ideas
Sigmoid
Function
43
Logistic Regression: An Example
year
6
1 (Tenured)
44
Logistic Regression: Model
45
Logistic Regression: Optimization
46
Gradient Descent
When the gradient is zero, we arrive at the local minimum
Step size
47
Gradient Descent �[footnote: It is gradient ascent for maximizing log likelihood]
48
Note we have switched the index i in the previous slides to l, and use i to refer to different components of weight vector w
Gradient Descent �[footnote: It is gradient ascent for maximizing log likelihood]
49
Gradient Descent �[footnote: It is gradient ascent for maximizing log likelihood]
50
Chapter 6. Classification: Basic Concepts
51
Model Evaluation and Selection
52
Classifier Evaluation Metrics: Confusion Matrix
Actual class\Predicted class | play_golf = yes | play_golf = no | Total |
play_golf = yes | 6954 | 46 | 7000 |
play_golf = no | 412 | 2588 | 3000 |
Total | 7366 | 2634 | 10000 |
Actual class\Predicted class | C1 | ¬ C1 |
C1 | True Positives (TP) | False Negatives (FN) |
¬ C1 | False Positives (FP) | True Negatives (TN) |
53
Classifier Evaluation Metrics: Accuracy, Error Rate, Sensitivity and Specificity
Accuracy = (TP + TN)/All
Error rate = (FP + FN)/All
A\P | C | ¬C | |
C | TP | FN | P |
¬C | FP | TN | N |
| P’ | N’ | All |
Real-world truth
Predictions
54
Classifier Evaluation Metrics: �Precision and Recall, and F-measures
https://en.wikipedia.org/wiki/Precision_and_recall
A\P | C | ¬C | |
C | TP | FN | P |
¬C | FP | TN | N |
| P’ | N’ | All |
55
Classifier Evaluation Metrics: �Precision and Recall, and F-measures
Assigning β times as much weight to recall as to precision
56
Classifier Evaluation Metrics: Example
Actual Class\Predicted class | cancer = yes | cancer = no | Total |
cancer = yes | 90 | 210 | 300 |
cancer = no | 140 | 9560 | 9700 |
Total | 230 | 9770 | 10000 |
57
Classifier Evaluation Metrics: Example
Actual Class\Predicted class | cancer = yes | cancer = no | Total |
cancer = yes | 90 | 210 | 300 |
cancer = no | 140 | 9560 | 9700 |
Total | 230 | 9770 | 10000 |
58
Training Error VS Testing Error
59
overfitting
underfitting
59
Classifier Evaluation: Holdout
60
Classifier Evaluation: Cross-Validation
61
Model Selection: ROC Curves
False positive rate
True positive rate
62
Chapter 6. Classification: Basic Concepts
63
Techniques to Improve Classification Accuracy
64
Ensemble Methods: Increasing the Accuracy
65
Ensemble Methods: Increasing the Accuracy
| x1 | x2 | x3 |
M1 | ✓ | ✓ | ✗ |
M2 | ✗ | ✓ | ✓ |
M3 | ✓ | ✗ | ✓ |
Voting Ensemble | ✓ | ✓ | ✓ |
| x1 | x2 | x3 |
M1 | ✓ | ✓ | ✗ |
M2 | ✓ | ✓ | ✗ |
M3 | ✓ | ✓ | ✗ |
Voting Ensemble | ✓ | ✓ | ✗ |
| x1 | x2 | x3 |
M1 | ✓ | ✗ | ✗ |
M2 | ✗ | ✓ | ✗ |
M3 | ✗ | ✗ | ✓ |
Voting Ensemble | ✗ | ✗ | ✗ |
Base model performance
Ensemble performance
Case 1:
Ensemble has positive effect
Case 2:
Ensemble has no effect
Case 3:
Ensemble has negative effect
66
Ensemble Methods: Increasing the Accuracy
Bagging
Boosting
67
Bagging: Bootstrap Aggregation
68
Boosting
69
Adaboost (Freund and Schapire, 1997)
{wn(1)}
{wn(2)}
{wn(k)}
M1
M2
Mk
…
…
1. Assign initial weights to each training tuple
2. Train base classifier on weighted dataset
3. Update weights based on current model
4. After base classifiers are trained, they are combined to give the final classifier
Two ‘weighting’ strategy:
70
Adaboost (Freund and Schapire, 1997)
71
Gradient Boosting
Previous model
New weak learner
72
Random Forest: Basic Concepts
Advantage of decision trees – more diversity
73
Random Forest
74
Ensemble Methods Recap
75
Classification of Class-Imbalanced Data Sets
is usually performed on a large population of people
without the condition, to detect a small minority
with it (e.g., HIV prevalence in the USA is ~0.4%)
are defrauded per year. (Most fraud detection domains are heavily imbalanced.)
76
Classification of Class-Imbalanced Data Sets
77
Classification of Class-Imbalanced Data Sets
Threshold-moving
78
Evaluate imbalanced data classifier
79
Summary
80
References (1)
81
References (2)
82
References (3)
83