chap5_alternative_classification-modified

Download Report

Transcript chap5_alternative_classification-modified

Data Mining
Classification: Alternative Techniques
Lecture Notes for Chapter 5
Introduction to Data Mining
by
Tan, Steinbach, Kumar
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
1
Alternative Techniques
Rule-Based Classifier
– Classify records by using a collection of
“if…then…” rules
 Instance Based Classifiers

© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Rule-based Classifier (Example)
Name
human
python
salmon
whale
frog
komodo
bat
pigeon
cat
leopard shark
turtle
penguin
porcupine
eel
salamander
gila monster
platypus
owl
dolphin
eagle
Blood Type
warm
cold
cold
warm
cold
cold
warm
warm
warm
cold
cold
warm
warm
cold
cold
cold
warm
warm
warm
warm
Give Birth
yes
no
no
yes
no
no
yes
no
yes
yes
no
no
yes
no
no
no
no
no
yes
no
Can Fly
no
no
no
no
no
no
yes
yes
no
no
no
no
no
no
no
no
no
yes
no
yes
Live in Water
no
no
yes
yes
sometimes
no
no
no
no
yes
sometimes
sometimes
no
yes
sometimes
no
no
no
yes
no
Class
mammals
reptiles
fishes
mammals
amphibians
reptiles
mammals
birds
mammals
fishes
reptiles
birds
mammals
fishes
amphibians
reptiles
mammals
birds
mammals
birds
R1: (Give Birth = no)  (Can Fly = yes)  Birds
R2: (Give Birth = no)  (Live in Water = yes)  Fishes
R3: (Give Birth = yes)  (Blood Type = warm)  Mammals
R4: (Give Birth = no)  (Can Fly = no)  Reptiles
R5: (Live in Water = sometimes)  Amphibians
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Application of Rule-Based Classifier

A rule r covers an instance x if the attributes of
the instance satisfy the condition of the rule
R1: (Give Birth = no)  (Can Fly = yes)  Birds
R2: (Give Birth = no)  (Live in Water = yes)  Fishes
R3: (Give Birth = yes)  (Blood Type = warm)  Mammals
R4: (Give Birth = no)  (Can Fly = no)  Reptiles
R5: (Live in Water = sometimes)  Amphibians
Name
hawk
grizzly bear
Blood Type
warm
warm
Give Birth
Can Fly
Live in Water
Class
no
yes
yes
no
no
no
?
?
The rule R1 covers a hawk => Bird
The rule R3 covers the grizzly bear => Mammal
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
How does Rule-based Classifier Work?
R1: (Give Birth = no)  (Can Fly = yes)  Birds
R2: (Give Birth = no)  (Live in Water = yes)  Fishes
R3: (Give Birth = yes)  (Blood Type = warm)  Mammals
R4: (Give Birth = no)  (Can Fly = no)  Reptiles
R5: (Live in Water = sometimes)  Amphibians
Name
lemur
turtle
dogfish shark
Blood Type
warm
cold
cold
Give Birth
Can Fly
Live in Water
Class
yes
no
yes
no
no
no
no
sometimes
yes
?
?
?
A lemur triggers rule R3, so it is classified as a mammal
A turtle triggers both R4 and R5
A dogfish shark triggers none of the rules
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
From Decision Trees To Rules
Classification Rules
(Refund=Yes) ==> No
Refund
Yes
No
NO
Marita l
Status
{Single,
Divorced}
(Refund=No, Marital Status={Single,Divorced},
Taxable Income<80K) ==> No
{Married}
(Refund=No, Marital Status={Single,Divorced},
Taxable Income>80K) ==> Yes
(Refund=No, Marital Status={Married}) ==> No
NO
Taxable
Income
< 80K
NO
> 80K
YES
Rules are mutually exclusive and exhaustive
Rule set contains as much information as the
tree
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Rules Can Be Simplified
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
6
No
Married
7
Yes
Divorced 220K
No
8
No
Single
85K
Yes
9
No
Married
75K
No
10
No
Single
90K
Yes
Refund
Yes
No
NO
{Single,
Divorced}
Marita l
Status
{Married}
NO
Taxable
Income
< 80K
NO
> 80K
YES
60K
Yes
No
10
Initial Rule:
(Refund=No)  (Status=Married)  No
Simplified Rule: (Status=Married)  No
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Instance-Based Classifiers
Set of Stored Cases
Atr1
……...
AtrN
Class
A
• Store the training records
• Use training records to
predict the class label of
unseen cases
B
B
C
A
Unseen Case
Atr1
……...
AtrN
C
B
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Instance Based Classifiers

Examples:
– Rote-learner
Memorizes entire training data and performs
classification only if attributes of record match one of
the training examples exactly

– Nearest neighbor
Uses k “closest” points (nearest neighbors) for
performing classification

© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Nearest Neighbor Classifiers

Basic idea:
– If it walks like a duck, quacks like a duck, then
it’s probably a duck
Compute
Distance
Training
Records
© Tan,Steinbach, Kumar
Test
Record
Choose k of the
“nearest” records
Introduction to Data Mining
4/18/2004
‹#›
Nearest-Neighbor Classifiers
Unknown record

Requires three things
– The set of stored records
– Distance Metric to compute
distance between records
– The value of k, the number of
nearest neighbors to retrieve

To classify an unknown record:
– Compute distance to other
training records
– Identify k nearest neighbors
– Use class labels of nearest
neighbors to determine the
class label of unknown record
(e.g., by taking majority vote)
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Definition of Nearest Neighbor
X
(a) 1-nearest neighbor
X
X
(b) 2-nearest neighbor
(c) 3-nearest neighbor
K-nearest neighbors of a record x are data points
that have the k smallest distance to x
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Nearest Neighbor Classification

Compute distance between two points:
– Euclidean distance
d ( p, q ) 

 ( pi
i
q )
2
i
Determine the class from nearest neighbor list
– take the majority vote of class labels among
the k-nearest neighbors
– Weigh the vote according to distance

weight factor, w = 1/d2
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Nearest Neighbor Classification…

Choosing the value of k:
– If k is too small, sensitive to noise points
– If k is too large, neighborhood may include points from
other classes
X
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Nearest Neighbor Classification…

Scaling issues
– Attributes may have to be scaled to prevent
distance measures from being dominated by
one of the attributes
– Example:
height of a person may vary from 1.5m to 1.8m
 weight of a person may vary from 90lb to 300lb
 income of a person may vary from $10K to $1M

– Solution: Normalize the vectors to unit length
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Nearest neighbor Classification…

k-NN classifiers are lazy learners
– It does not build models explicitly
– Unlike eager learners such as decision tree
induction and rule-based systems
– Classifying unknown records are relatively
expensive
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Artificial Neural Networks (ANN)
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Artificial Neural Networks (ANN)

What is ANN?
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Artificial Neural Networks (ANN)
Dendrites
Axon
Weight
Cell Body
Nucleus
x1 w1
x2 w2
w3
x3
Input (X)
Neuron
S
b
y
Output (Y)
Synapse
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Artificial Neural Networks (ANN)
X1
X2
X3
Y
Input
1
1
1
1
0
0
0
0
0
0
1
1
0
1
1
0
0
1
0
1
1
0
1
0
0
1
1
1
0
0
1
0
X1
Black box
Output
X2
Y
X3
Output Y is 1 if at least two of the three inputs are equal to 1.
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Artificial Neural Networks (ANN)
X1
X2
X3
Y
1
1
1
1
0
0
0
0
0
0
1
1
0
1
1
0
0
1
0
1
1
0
1
0
0
1
1
1
0
0
1
0
Input
nodes
Black box
X1
Output
node
0.3
0.3
X2
X3
0.3
S
Y
t=0.4
Y  I (0.3 X 1  0.3 X 2  0.3 X 3  0.4  0)
1
where I ( z )  
0
© Tan,Steinbach, Kumar
if z is true
otherwise
Introduction to Data Mining
4/18/2004
‹#›
Artificial Neural Networks (ANN)

Model is an assembly of
inter-connected nodes
and weighted links
Input
nodes
Black box
X1
w1
w2
X2


Output node sums up
each of its input value
according to the weights
of its links
Output
node
S
Y
w3
X3
t
Perceptron Model
Compare output node
against some threshold t
Y  I (  wi X i  t )
or
i
Y  sign (  wi X i  t )
i
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
General Structure of ANN
x1
x2
x3
Input
Layer
x4
x5
Input
I1
I2
Hidden
Layer
I3
Neuron i
Output
wi1
wi2
wi3
Si
Activation
function
g(Si )
Oi
Oi
threshold, t
Output
Layer
Training ANN means learning
the weights of the neurons
y
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Algorithm for learning ANN

Initialize the weights (w0, w1, …, wk)

Adjust the weights in such a way that the output
of ANN is consistent with class labels of training
examples
2
– Objective function: E   Yi  f ( wi , X i )
i
– Find the weights wi’s that minimize the above
objective function

e.g., backpropagation algorithm (see lecture notes)
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Support Vector Machines

Find a linear hyperplane (decision boundary) that will separate the data
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Support Vector Machines
B1

One Possible Solution
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Support Vector Machines
B2

Another possible solution
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Support Vector Machines
B2

Other possible solutions
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Support Vector Machines
B1
B2


Which one is better? B1 or B2?
How do you define better?
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Support Vector Machines
B1
B2
b21
b22
margin
b11
b12

Find hyperplane maximizes the margin => B1 is better than B2
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Support Vector Machines
B1
 
w x  b  0
 
w  x  b  1
 
w  x  b  1
b11
 
if w  x  b  1
1

f ( x)  
 
 1 if w  x  b  1
© Tan,Steinbach, Kumar
Introduction to Data Mining
b12
2
Margin   2
|| w ||
4/18/2004
‹#›
Support Vector Machines

We want to maximize:
2
Margin   2
|| w ||
 2
|| w ||
– Which is equivalent to minimizing: L( w) 
2
– But subjected to the following constraints:
 
if w  x i  b  1
1

f ( xi )  
 
 1 if w  x i  b  1

This is a constrained optimization problem
– Numerical approaches to solve it (e.g., quadratic programming)
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Support Vector Machines

What if the problem is not linearly separable?
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Support Vector Machines

What if the problem is not linearly separable?
– Introduce slack variables
 2
 Need to minimize:
|| w ||
 N k
L( w) 
 C   i 
2
 i 1 

Subject to:
 
if w  x i  b  1 - i
1

f ( xi )  
 
 1 if w  x i  b  1  i
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Nonlinear Support Vector Machines

What if decision boundary is not linear?
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Nonlinear Support Vector Machines

Transform data into higher dimensional space
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Ensemble Methods

Construct a set of classifiers from the training
data

Predict class label of previously unseen records
by aggregating predictions made by multiple
classifiers
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
General Idea
D
Step 1:
Create Multiple
Data Sets
Step 2:
Build Multiple
Classifiers
D1
D2
C1
C2
Step 3:
Combine
Classifiers
© Tan,Steinbach, Kumar
....
Original
Training data
Dt-1
Dt
Ct -1
Ct
C*
Introduction to Data Mining
4/18/2004
‹#›
Why does it work?

Suppose there are 25 base classifiers
– Each classifier has error rate,  = 0.35
– Assume classifiers are independent
– Probability that the ensemble classifier makes
a wrong prediction:
 25  i
25i

(
1


)
 0.06



 i 
i 13 

25
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Examples of Ensemble Methods

How to generate an ensemble of classifiers?
– Bagging
– Boosting
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Bagging

Sampling with replacement
Original Data
Bagging (Round 1)
Bagging (Round 2)
Bagging (Round 3)
1
7
1
1
2
8
4
8
3
10
9
5
4
8
1
10
5
2
2
5
6
5
3
5
7
10
2
9
8
10
7
6
9
5
3
3
10
9
2
7

Build classifier on each bootstrap sample

Each sample has probability (1 – 1/n)n of being
selected
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Boosting

An iterative procedure to adaptively change
distribution of training data by focusing more on
previously misclassified records
– Initially, all N records are assigned equal
weights
– Unlike bagging, weights may change at the
end of boosting round
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Boosting
Records that are wrongly classified will have their
weights increased
 Records that are classified correctly will have
their weights decreased

Original Data
Boosting (Round 1)
Boosting (Round 2)
Boosting (Round 3)
1
7
5
4
2
3
4
4
3
2
9
8
4
8
4
10
5
7
2
4
6
9
5
5
7
4
1
4
8
10
7
6
9
6
4
3
10
3
2
4
• Example 4 is hard to classify
• Its weight is increased, therefore it is more
likely to be chosen again in subsequent rounds
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Example: AdaBoost

Base classifiers: C1, C2, …, CT

Error rate:
1
i 
N

 w  C ( x )  y 
N
j 1
j
i
j
j
Importance of a classifier:
1  1  i 

i  ln 
2  i 
© Tan,Steinbach, Kumar
Introduction to Data Mining
4/18/2004
‹#›
Example: AdaBoost

Weight update:
 j

if C j ( xi )  yi
w exp
( j 1)
wi


j
Zj 
exp
if C j ( xi )  yi

where Z j is the normalizat ion factor
( j)
i
If any intermediate rounds produce error rate
higher than 50%, the weights are reverted back
to 1/n and the resampling procedure is repeated
 Classification:
T

C * ( x )  arg max  j C j ( x )  y 
y
© Tan,Steinbach, Kumar
Introduction to Data Mining
j 1
4/18/2004
‹#›
Illustrating AdaBoost
Initial weights for each data point
Original
Data
0.1
0.1
0.1
+++
- - - - -
++
Data points
for training
B1
0.0094
Boosting
Round 1
+++
© Tan,Steinbach, Kumar
0.0094
0.4623
- - - - - - -
Introduction to Data Mining
 = 1.9459
4/18/2004
‹#›
Illustrating AdaBoost
B1
0.0094
Boosting
Round 1
0.0094
+++
0.4623
- - - - - - -
 = 1.9459
B2
Boosting
Round 2
0.0009
0.3037
- - -
- - - - -
0.0422
++
 = 2.9323
B3
0.0276
0.1819
0.0038
Boosting
Round 3
+++
++ ++ + ++
Overall
+++
- - - - -
© Tan,Steinbach, Kumar
Introduction to Data Mining
 = 3.8744
++
4/18/2004
‹#›