Sunteți pe pagina 1din 6

Decision Tree Construction from Training Data - an

Example
Let us take a training set and induce a decision tree using
the training set.
Table 1 gives a training data set with four patterns having
the class
Goes-to-movie=yes and eight patterns having the class
Goes-to-movie=no.
The impurity of this set is
Im(n) = 4/12 log24/128/12 log28/1= 0.9183
We need to now consider all the three attributes for the
first split and chose the one with the most information
gain.

Money
1. Money < 50, has 3 patterns belonging to goes-tomovie=no and 0 pat terns belonging to goes-to-movie=yes.
The entropy for money < 50 is Im(Money < 50) = 0
2. Money 50-150 has 5 patterns belonging to goes-tomovie=no and 1 pattern belonging to goes-to-movie=yes .
Entropy for money 50-150 is Im(Money50 150) = 1/6
log21/ 65/6 log25/6= 0.65
3. Money > 150 has 3 patterns belonging to goes-tomovie=yes and 0 patterns belonging to goes-to-movie=no.
4. The entropy for money > 150 is
Im(Money>150) = 0
4. Gain(Money)
. Gain(money) = 0.9183 3/12* 0 6/12* 0.65 3/12* 0 =
0.5933

Has-exams
1. (Has-exams=yes) e parts < 50, between 50-150 and > 150 . Has a
total of 7 patterns with 2 patterns belonging to goes-to-movie=yes
and five patterns belonging to goes-to-movies=no.
The entropy for has-exams=yes is
Im(has exams = yes) = 2/7 log22/75/7 log25/7= 0.6717
2. (Has exams=no)
Has a total of 5 patterns with 2 patterns belonging to goes-tomovie=yes and 3 patterns belonging to goes-to-movies=no.
The entropy for has-exams=no is
Im(has exams = no) = 2/5 log22/53/5 log23/5= 0.9710
3. Gain for has-exams
Gain(has exams) = 0.9183 7/12* 0.6717 5/12*0. 9710= 0.1219

Weather
1. (Weather=hot)
Has a total of 3 patterns with 1 pattern belonging to goes-tomovie=yeand 2 patterns belonging to goes-to-movie=no. The
entropy for weather=hot is
Im(weather = hot) = 1/3 log21/32/3 log22/3= 0.9183
2. (Weather=fine)
Has a total of 6 patterns with 3 patterns belonging to goes-tomovie=yes
and 3 patterns belonging to goes-to-movie=no.
The entropy for weather=fine is
Im(weather = fine) = 3/6 log23/63/6 log23/6= 1.03.
3 Weather=rainy)
Has a total of 3 patterns with 0 patterns belonging to goes-tomovie=yes and 3 patterns belonging to goes-to-movie=no. The
entropy for weather=rainy is
Im(weather = rainy) = 0/3 log20/33/3 log23/3= 0

All the three attributes have been


investigated and here are the gain
values :
Gain(money) = 0.5933
Gain(has-exams) = 0.1219
Gain(weather) = 0.1887
Since Gain(money) has the maximum
value, money is taken as the first
attribute.

S-ar putea să vă placă și