Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification:...
Transcript of Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification:...
![Page 1: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/1.jpg)
1
Classification: Basic Concepts and Decision Trees
![Page 2: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/2.jpg)
Classification: Definition Given a collection of records (training set )
Each record contains a set of attributes, one of the attributes is the class.
Find a model for class attribute as a function of the values of other attributes.
Goal: previously unseen records should be assigned a class as accurately as possible.
A test set is used to determine the accuracy of the model. Usually, the given data set is divided into training and test sets, with training set used to build the model and test set used to validate it.
![Page 3: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/3.jpg)
Illustrating Classification Task
Apply
Model
Induction
Deduction
Learn
Model
Model
Tid Attrib1 Attrib2 Attrib3 Class
1 Yes Large 125K No
2 No Medium 100K No
3 No Small 70K No
4 Yes Medium 120K No
5 No Large 95K Yes
6 No Medium 60K No
7 Yes Large 220K No
8 No Small 85K Yes
9 No Medium 75K No
10 No Small 90K Yes 10
Tid Attrib1 Attrib2 Attrib3 Class
11 No Small 55K ?
12 Yes Medium 80K ?
13 Yes Large 110K ?
14 No Small 95K ?
15 No Large 67K ? 10
Test Set
Learning
algorithm
Training Set
![Page 4: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/4.jpg)
Examples of Classification Task
Predicting tumor cells as benign or malignant
Classifying credit card transactions as legitimate or fraudulent
Classifying secondary structures of protein as alpha-helix, beta-sheet, or random coil
Categorizing news stories as finance, weather, entertainment, sports, etc
![Page 5: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/5.jpg)
Example of a Decision Tree
Tid Refund MaritalStatus
TaxableIncome Cheat
1 Yes Single 125K No
2 No Married 100K No
3 No Single 70K No
4 Yes Married 120K No
5 No Divorced 95K Yes
6 No Married 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes10
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Splitting Attributes
Training Data Model: Decision Tree
![Page 6: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/6.jpg)
Another Example of Decision Tree
Tid Refund MaritalStatus
TaxableIncome Cheat
1 Yes Single 125K No
2 No Married 100K No
3 No Single 70K No
4 Yes Married 120K No
5 No Divorced 95K Yes
6 No Married 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes10
MarSt
Refund
TaxInc
YES NO
NO
NO
Yes No
Married Single,
Divorced
< 80K > 80K
There could be more than one tree that fits the same data!
![Page 7: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/7.jpg)
Decision Tree Classification Task
Apply
Model
Induction
Deduction
Learn
Model
Model
Tid Attrib1 Attrib2 Attrib3 Class
1 Yes Large 125K No
2 No Medium 100K No
3 No Small 70K No
4 Yes Medium 120K No
5 No Large 95K Yes
6 No Medium 60K No
7 Yes Large 220K No
8 No Small 85K Yes
9 No Medium 75K No
10 No Small 90K Yes 10
Tid Attrib1 Attrib2 Attrib3 Class
11 No Small 55K ?
12 Yes Medium 80K ?
13 Yes Large 110K ?
14 No Small 95K ?
15 No Large 67K ? 10
Test Set
Tree
Induction
algorithm
Training Set
Decision Tree
![Page 8: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/8.jpg)
Apply Model to Test Data
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Refund Marital Status
Taxable Income Cheat
No Married 80K ? 10
Test Data Start from the root of tree.
![Page 9: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/9.jpg)
Apply Model to Test Data
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Refund Marital Status
Taxable Income Cheat
No Married 80K ? 10
Test Data
![Page 10: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/10.jpg)
Apply Model to Test Data
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Refund Marital Status
Taxable Income Cheat
No Married 80K ? 10
Test Data
![Page 11: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/11.jpg)
Apply Model to Test Data
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Refund Marital Status
Taxable Income Cheat
No Married 80K ? 10
Test Data
![Page 12: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/12.jpg)
Apply Model to Test Data
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Refund Marital Status
Taxable Income Cheat
No Married 80K ? 10
Test Data
![Page 13: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/13.jpg)
Apply Model to Test Data
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Refund Marital Status
Taxable Income Cheat
No Married 80K ? 10
Test Data
Assign Cheat to “No”
![Page 14: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/14.jpg)
Decision Tree Classification Task
Apply
Model
Induction
Deduction
Learn
Model
Model
Tid Attrib1 Attrib2 Attrib3 Class
1 Yes Large 125K No
2 No Medium 100K No
3 No Small 70K No
4 Yes Medium 120K No
5 No Large 95K Yes
6 No Medium 60K No
7 Yes Large 220K No
8 No Small 85K Yes
9 No Medium 75K No
10 No Small 90K Yes 10
Tid Attrib1 Attrib2 Attrib3 Class
11 No Small 55K ?
12 Yes Medium 80K ?
13 Yes Large 110K ?
14 No Small 95K ?
15 No Large 67K ? 10
Test Set
Tree
Induction
algorithm
Training Set
Decision Tree
![Page 15: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/15.jpg)
Confusion Matric
A confusion matrix (Kohavi and Provost, 1998) contains information about actual and predicted classifications done by a classification system. Performance of such systems is commonly evaluated using the data in the matrix.
![Page 16: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/16.jpg)
Confusion matrix
a is the number of correct predictions that an instance is negative,
b is the number of incorrect predictions that an instance is positive,
c is the number of incorrect of predictions that an instance negative, and
d is the number of correct predictions that an instance is positive.
![Page 17: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/17.jpg)
Confusion Matrix Predicted
Negative Positive
Actual Negative a b
Positive c d
![Page 18: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/18.jpg)
Confusion matrix Several standard terms have been defined for
the 2 class matrix:
The accuracy (AC) is the proportion of the total number of predictions that were correct. It is determined using the equation:
The recall or true positive rate (TP) is the proportion of positive cases that were correctly identified, as calculated using the equation:
![Page 19: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/19.jpg)
The false positive rate (FP) is the proportion of negatives cases that were incorrectly classified as positive, as calculated using the equation:
The true negative rate (TN) is defined as the proportion of negatives cases that were classified correctly, as calculated using the equation:
![Page 20: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/20.jpg)
The false negative rate (FN) is the proportion of positives cases that were incorrectly classified as negative, as calculated using the equation:
Finally, precision (P) is the proportion of the predicted positive cases that were correct, as calculated using the equation:
![Page 21: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/21.jpg)
Decision Tree Induction
Many Algorithms:
Hunt’s Algorithm (one of the earliest)
SLIQ
![Page 22: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/22.jpg)
General Structure of Hunt’s Algorithm
Let Dt be the set of training records that reach a node t
General Procedure: If Dt contains records that belong
the same class yt, then t is a leaf node labeled as yt
If Dt is an empty set, then t is a leaf node labeled by the default class, yd
If Dt contains records that belong to more than one class, use an attribute test to split the data into smaller subsets. Recursively apply the procedure to each subset.
Tid Refund Marital Status
Taxable Income Cheat
1 Yes Single 125K No
2 No Married 100K No
3 No Single 70K No
4 Yes Married 120K No
5 No Divorced 95K Yes
6 No Married 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes 10
Dt
?
![Page 23: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/23.jpg)
Hunt’s Algorithm
Don’t
Cheat
Refund
Don’t
Cheat
Don’t
Cheat
Yes No
Refund
Don’t
Cheat
Yes No
Marital
Status
Don’t
Cheat
Cheat
Single, Divorced
Married
Taxable
Income
Don’t
Cheat
< 80K >= 80K
Refund
Don’t
Cheat
Yes No
Marital
Status
Don’t
Cheat Cheat
Single, Divorced
Married
Tid Refund MaritalStatus
TaxableIncome Cheat
1 Yes Single 125K No
2 No Married 100K No
3 No Single 70K No
4 Yes Married 120K No
5 No Divorced 95K Yes
6 No Married 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes10
![Page 24: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/24.jpg)
Tree Induction
Greedy strategy.
Split the records based on an attribute test that optimizes certain criterion.
Issues
Determine how to split the records
How to specify the attribute test condition?
How to determine the best split?
Determine when to stop splitting
![Page 25: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/25.jpg)
Tree Induction
Greedy strategy.
Split the records based on an attribute test that optimizes certain criterion.
Issues
Determine how to split the records
How to specify the attribute test condition?
How to determine the best split?
Determine when to stop splitting
![Page 26: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/26.jpg)
How to Specify Test Condition?
Depends on attribute types
Nominal
Ordinal
Continuous
Depends on number of ways to split
2-way split
Multi-way split
![Page 27: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/27.jpg)
Splitting Based on Nominal Attributes
Multi-way split: Use as many partitions as distinct values.
Binary split: Divides values into two subsets. Need to find optimal partitioning.
CarType Family
Sports
Luxury
CarType {Family, Luxury} {Sports}
CarType {Sports, Luxury} {Family}
OR
![Page 28: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/28.jpg)
Multi-way split: Use as many partitions as distinct values.
Binary split: Divides values into two subsets. Need to find optimal partitioning.
What about this split?
Splitting Based on Ordinal Attributes
Size Small
Medium
Large
Size {Medium,
Large} {Small}
Size {Small,
Medium} {Large} OR
Size {Small, Large} {Medium}
![Page 29: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/29.jpg)
Splitting Based on Continuous Attributes
Different ways of handling
Discretization to form an ordinal categorical attribute
Static – discretize once at the beginning
Dynamic – ranges can be found by equal interval bucketing, equal frequency bucketing (percentiles), or clustering.
Binary Decision: (A < v) or (A v)
consider all possible splits and finds the best cut
can be more compute intensive
![Page 30: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/30.jpg)
Splitting Based on Continuous Attributes
Taxable
Income
> 80K?
Yes No
Taxable
Income?
(i) Binary split (ii) Multi-way split
< 10K
[10K,25K) [25K,50K) [50K,80K)
> 80K
![Page 31: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/31.jpg)
Tree Induction
Greedy strategy.
Split the records based on an attribute test that optimizes certain criterion.
Issues
Determine how to split the records
How to specify the attribute test condition?
How to determine the best split?
Determine when to stop splitting
![Page 32: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/32.jpg)
How to determine the Best Split
Own
Car?
C0: 6
C1: 4
C0: 4
C1: 6
C0: 1
C1: 3
C0: 8
C1: 0
C0: 1
C1: 7
Car
Type?
C0: 1
C1: 0
C0: 1
C1: 0
C0: 0
C1: 1
Student
ID?
...
Yes No Family
Sports
Luxury c1
c10
c20
C0: 0
C1: 1...
c11
Before Splitting: 10 records of class 0, 10 records of class 1
Which test condition is the best?
![Page 33: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/33.jpg)
How to determine the Best Split
Greedy approach:
Nodes with homogeneous class distribution are preferred
Need a measure of node impurity:
C0: 5
C1: 5
C0: 9
C1: 1
Non-homogeneous,
High degree of impurity
Homogeneous,
Low degree of impurity
![Page 34: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/34.jpg)
Measures of Node Impurity
Gini Index
Entropy
Misclassification error
![Page 35: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/35.jpg)
How to Find the Best Split
B?
Yes No
Node N3 Node N4
A?
Yes No
Node N1 Node N2
Before Splitting:
C0 N10
C1 N11
C0 N20
C1 N21
C0 N30
C1 N31
C0 N40
C1 N41
C0 N00
C1 N01
M0
M1 M2 M3 M4
M12
M34 Gain = M0 – M12 vs M0 – M34
![Page 36: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/36.jpg)
Measure of Impurity: GINI Gini Index for a given node t :
(NOTE: p( j | t) is the relative frequency of class j at node t).
Maximum (1 - 1/nc) when records are equally distributed among all classes, implying least interesting information
Minimum (0.0) when all records belong to one class, implying most interesting information
j
tjptGINI 2)]|([1)(
C1 0
C2 6
Gini=0.000
C1 2
C2 4
Gini=0.444
C1 3
C2 3
Gini=0.500
C1 1
C2 5
Gini=0.278
![Page 37: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/37.jpg)
Examples for computing GINI
C1 0
C2 6
C1 2
C2 4
C1 1
C2 5
P(C1) = 0/6 = 0 P(C2) = 6/6 = 1
Gini = 1 – P(C1)2 – P(C2)2 = 1 – 0 – 1 = 0
j
tjptGINI 2)]|([1)(
P(C1) = 1/6 P(C2) = 5/6
Gini = 1 – (1/6)2 – (5/6)2 = 0.278
P(C1) = 2/6 P(C2) = 4/6
Gini = 1 – (2/6)2 – (4/6)2 = 0.444
![Page 38: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/38.jpg)
Splitting Based on GINI Used in CART, SLIQ, SPRINT.
When a node p is split into k partitions (children), the quality of split is computed as,
where, ni = number of records at child i,
n = number of records at node p.
k
i
isplit iGINI
n
nGINI
1
)(
![Page 39: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/39.jpg)
Binary Attributes: Computing GINI Index Splits into two partitions
Effect of Weighing partitions:
Larger and Purer Partitions are sought for.
B?
Yes No
Node N1 Node N2
Parent
C1 6
C2 6
Gini = 0.500
N1 N2
C1 5 1
C2 2 4
Gini=0.333
Gini(N1) = 1 – (5/6)2 – (2/6)2 = 0.194
Gini(N2) = 1 – (1/6)2 – (4/6)2 = 0.528
Gini(Children) = 7/12 * 0.194 + 5/12 * 0.528 = 0.333
![Page 40: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/40.jpg)
Categorical Attributes: Computing Gini Index
For each distinct value, gather counts for each class in the dataset
Use the count matrix to make decisions
CarType
{Sports,Luxury}
{Family}
C1 3 1
C2 2 4
Gini 0.400
CarType
{Sports}{Family,Luxury}
C1 2 2
C2 1 5
Gini 0.419
CarType
Family Sports Luxury
C1 1 2 1
C2 4 1 1
Gini 0.393
Multi-way split Two-way split
(find best partition of values)
![Page 41: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/41.jpg)
Continuous Attributes: Computing Gini Index Use Binary Decisions based on one
value
Several Choices for the splitting value Number of possible splitting values
= Number of distinct values
Each splitting value has a count matrix associated with it Class counts in each of the partitions, A
< v and A v
Simple method to choose best v For each v, scan the database to
gather count matrix and compute its Gini index
Computationally Inefficient! Repetition of work.
Tid Refund Marital Status
Taxable Income Cheat
1 Yes Single 125K No
2 No Married 100K No
3 No Single 70K No
4 Yes Married 120K No
5 No Divorced 95K Yes
6 No Married 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes 10
Taxable
Income
> 80K?
Yes No
![Page 42: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/42.jpg)
Continuous Attributes: Computing Gini Index...
For efficient computation: for each attribute, Sort the attribute on values
Linearly scan these values, each time updating the count matrix and computing gini index
Choose the split position that has the least gini index
Cheat No No No Yes Yes Yes No No No No
Taxable Income
60 70 75 85 90 95 100 120 125 220
55 65 72 80 87 92 97 110 122 172 230
<= > <= > <= > <= > <= > <= > <= > <= > <= > <= > <= >
Yes 0 3 0 3 0 3 0 3 1 2 2 1 3 0 3 0 3 0 3 0 3 0
No 0 7 1 6 2 5 3 4 3 4 3 4 3 4 4 3 5 2 6 1 7 0
Gini 0.420 0.400 0.375 0.343 0.417 0.400 0.300 0.343 0.375 0.400 0.420
Split Positions
Sorted Values
![Page 43: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/43.jpg)
Alternative Splitting Criteria based on INFO
Entropy at a given node t:
(NOTE: p( j | t) is the relative frequency of class j at node t).
Measures homogeneity of a node.
Maximum (log nc) when records are equally distributed among all classes implying least information
Minimum (0.0) when all records belong to one class, implying most information
Entropy based computations are similar to the GINI index computations
j
tjptjptEntropy )|(log)|()(
![Page 44: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/44.jpg)
Examples for computing Entropy
C1 0
C2 6
C1 2
C2 4
C1 1
C2 5
P(C1) = 0/6 = 0 P(C2) = 6/6 = 1
Entropy = – 0 log 0 – 1 log 1 = – 0 – 0 = 0
P(C1) = 1/6 P(C2) = 5/6
Entropy = – (1/6) log2 (1/6) – (5/6) log2 (1/6) = 0.65
P(C1) = 2/6 P(C2) = 4/6
Entropy = – (2/6) log2 (2/6) – (4/6) log2 (4/6) = 0.92
j
tjptjptEntropy )|(log)|()(2
![Page 45: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/45.jpg)
Splitting Based on INFO... Information Gain:
Parent Node, p is split into k partitions;
ni is number of records in partition i
Measures Reduction in Entropy achieved because of the split. Choose the split that achieves most reduction (maximizes GAIN)
Used in ID3 and C4.5
Disadvantage: Tends to prefer splits that result in large number of partitions, each being small but pure.
k
i
i
splitiEntropy
n
npEntropyGAIN
1
)()(
![Page 46: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/46.jpg)
Splitting Based on INFO... Gain Ratio:
Parent Node, p is split into k partitions
ni is the number of records in partition i
Adjusts Information Gain by the entropy of the partitioning (SplitINFO). Higher entropy partitioning (large number of small partitions) is penalized!
Used in C4.5
Designed to overcome the disadvantage of Information Gain
SplitINFO
GAINGainRATIO Split
split
k
i
ii
n
n
n
nSplitINFO
1
log
![Page 47: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/47.jpg)
Splitting Criteria based on Classification Error
Classification error at a node t :
Measures misclassification error made by a node.
Maximum (1 - 1/nc) when records are equally distributed among all classes, implying least interesting information
Minimum (0.0) when all records belong to one class, implying most interesting information
)|(max1)( tiPtErrori
![Page 48: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/48.jpg)
Examples for Computing Error
C1 0
C2 6
C1 2
C2 4
C1 1
C2 5
P(C1) = 0/6 = 0 P(C2) = 6/6 = 1
Error = 1 – max (0, 1) = 1 – 1 = 0
P(C1) = 1/6 P(C2) = 5/6
Error = 1 – max (1/6, 5/6) = 1 – 5/6 = 1/6
P(C1) = 2/6 P(C2) = 4/6
Error = 1 – max (2/6, 4/6) = 1 – 4/6 = 1/3
)|(max1)( tiPtErrori
![Page 49: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/49.jpg)
Comparison among Splitting Criteria
For a 2-class problem:
![Page 50: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/50.jpg)
Misclassification Error vs Gini A?
Yes No
Node N1 Node N2
Parent
C1 7
C2 3
Gini = 0.42
N1 N2
C1 3 4
C2 0 3
Gini(N1) = 1 – (3/3)2 – (0/3)2 = 0
Gini(N2) = 1 – (4/7)2 – (3/7)2 = 0.489
Gini(Children) = 3/10 * 0 + 7/10 * 0.489 = 0.342
![Page 51: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/51.jpg)
Tree Induction
Greedy strategy.
Split the records based on an attribute test that optimizes certain criterion.
Issues
Determine how to split the records
How to specify the attribute test condition?
How to determine the best split?
Determine when to stop splitting
![Page 52: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/52.jpg)
Stopping Criteria for Tree Induction
Stop expanding a node when all the records belong to the same class
Stop expanding a node when all the records have similar attribute values
Early termination (to be discussed later)
![Page 53: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/53.jpg)
53
Why Decision Tree Model?
Relatively fast compared to other classification models
Obtain similar and sometimes better accuracy compared to other models
Simple and easy to understand
Can be converted into simple and easy to understand classification rules
![Page 54: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/54.jpg)
54
A Decision Tree
Age < 25
Car Type in {sports}
High
High Low
![Page 55: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/55.jpg)
55
Decision Tree Classification
A decision tree is created in two phases:
Tree Building Phase
Repeatedly partition the training data until all the examples in each partition belong to one class or the partition is sufficiently small
Tree Pruning Phase
Remove dependency on statistical noise or variation that may be particular only to the training set
![Page 56: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/56.jpg)
56
Tree Building Phase
General tree-growth algorithm (binary tree)
Partition(Data S)
If (all points in S are of the same class) then return;
for each attribute A do
evaluate splits on attribute A;
Use best split to partition S into S1 and S2;
Partition(S1);
Partition(S2);
![Page 57: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/57.jpg)
57
Tree Building Phase (cont.)
The form of the split depends on the type of the attribute
Splits for numeric attributes are of the form A v, where v is a real number
Splits for categorical attributes are of the form A S’, where S’ is a subset of all possible values of A
![Page 58: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/58.jpg)
58
Splitting Index
Alternative splits for an attribute are compared using a splitting index
Examples of splitting index:
Entropy ( entropy(T) = - pj x log2(pj) )
Gini Index ( gini(T) = 1 - pj2 )
(pj is the relative frequency of class j in T)
![Page 59: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/59.jpg)
59
The Best Split
Suppose the splitting index is I(), and a split partitions S into S1 and S2
The best split is the split that maximizes the following value:
I(S) - |S1|/|S| x I(S1) + |S2|/|S| x I(S2)
![Page 60: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/60.jpg)
60
Tree Pruning Phase
Examine the initial tree built
Choose the subtree with the least estimated error rate
Two approaches for error estimation:
Use the original training dataset (e.g. cross –validation)
Use an independent dataset
![Page 61: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/61.jpg)
61
SLIQ - Overview
Capable of classifying disk-resident datasets
Scalable for large datasets
Use pre-sorting technique to reduce the cost of evaluating numeric attributes
Use a breath-first tree growing strategy
Use an inexpensive tree-pruning algorithm based on the Minimum Description Length (MDL) principle
![Page 62: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/62.jpg)
62
Data Structure
A list (class list) for the class label Each entry has two fields: the class label
and a reference to a leaf node of the decision tree
Memory-resident
A list for each attribute Each entry has two fields: the attribute
value, an index into the class list
Written to disk if necessary
![Page 63: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/63.jpg)
63
An illustration of the Data Structure
Age Class List Index
Car Type
Class List Index
Class Leaf
23 1 Family 1 1 High N1
17 2 Sports 2 2 High N1
43 3 Sports 3 3 High N1
68 4 Family 4 4 Low N1
32 5 Truck 5 5 Low N1
20 6 Family 6 6 High N1
![Page 64: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/64.jpg)
64
Pre-sorting
Sorting of data is required to find the split for numeric attributes
Previous algorithms sort data at every node in the tree
Using the separate list data structure, SLIQ only sort data once at the beginning of the tree building phase
![Page 65: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/65.jpg)
65
After Pre-sorting
Age Class List Index
Car Type
Class List Index
Class Leaf
17 2 Family 1 1 High N1
20 6 Sports 2 2 High N1
23 1 Sports 3 3 High N1
32 5 Family 4 4 Low N1
43 3 Truck 5 5 Low N1
68 4 Family 6 6 High N1
![Page 66: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/66.jpg)
66
Node Split
SLIQ uses a breath-first tree growing strategy
In one pass over the data, splits for all the leaves of the current tree can be evaluated
SLIQ uses gini-splitting index to evaluate split
Frequency distribution of class values in data partitions is required
![Page 67: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/67.jpg)
67
Class Histogram
A class histogram is used to keep the frequency distribution of class values for each attribute in each leaf node
For numeric attributes, the class histogram is a list of <class, frequency>
For categorical attributes, the class histogram is a list of <attribute value, class, frequency>
![Page 68: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/68.jpg)
68
Evaluate Split
for each attribute A
traverse attribute list of A
for each value v in the attribute list
find the corresponding class and leaf node
update the class histogram in the leaf l
if A is a numeric attribute then
compute splitting index for test (Av) for leaf l
if A is a categorical attribute then
for each leaf of the tree do
find subset of A with the best split
![Page 69: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/69.jpg)
69
Subsetting for Categorical Attributes
If cardinality of S is less than a threshold
all of the subsets of S are evaluated
else
start an empty subset S’
repeat
adds the element of S to S’ which gives the best split
until there is no improvement
![Page 70: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/70.jpg)
70
Partition the data
Partition can be done by updating the leaf reference of each entry in the class list
Algorithm:
for each attribute A used in a split
traverse attribute list of A
for each value v in the list
find corresponding class label and leaf l
find the new node, n, to which v belongs by applying the splitting test at l
update the leaf reference to n
![Page 71: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/71.jpg)
71
Example of Evaluating Splits
Initial Histogram H L
L 0 0
R 4 2 Age Index
17 2
20 6
23 1
32 5
43 3
68 4
H L
L 1 0
R 3 2
H L
L 3 1
R 1 1
Evaluate split (age 17)
Evaluate split (age 32)
Class Leaf
1 High N1
2 High N1
3 High N1
4 Low N1
5 Low N1
6 High N1
![Page 72: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/72.jpg)
72
Example of Updating Class List
Age Index
17 2
20 6
23 1
32 5
43 3
68 4
Class Leaf
1 High N2
2 High N2
3 High N1
4 Low N1
5 Low N1
6 High N2
Age 23
N1
N2 N3
N3 (New value)
![Page 73: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/73.jpg)
73
MDL Principle
Given a model, M, and the data, D
MDL principle states that the best model for encoding data is the one that minimizes Cost(M,D) = Cost(D|M) + Cost(M) Cost (D|M) is the cost, in number of bits,
of encoding the data given a model M
Cost (M) is the cost of encoding the model M
![Page 74: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/74.jpg)
74
MDL Pruning Algorithm
The models are the set of trees obtained by pruning the initial decision T
The data is the training set S
The goal is to find the subtree of T that best describes the training set S (i.e. with the minimum cost)
The algorithm evaluates the cost at each decision tree node to determine whether to convert the node into a leaf, prune the left or the right child, or leave the node intact.
![Page 75: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/75.jpg)
75
Encoding Scheme
Cost(S|T) is defined as the sum of all classification errors
Cost(M) includes The cost of describing the tree
number of bits used to encode each node
The costs of describing the splits
For numeric attributes, the cost is 1 bit
For categorical Attributes, the cost is ln(nA), where nA is the total number of tests of the form A S’ used
![Page 76: Classification: Basic Concepts and Decision Treesbspanda/ds.pdf · 2017. 3. 9. · Classification: Definition Given a collection of records (training set ) Each record contains a](https://reader035.fdocuments.in/reader035/viewer/2022062510/6146a5437599b83a5f005aca/html5/thumbnails/76.jpg)
76
Performance (Scalability)