Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

BÀI TẬP NHÓM

age income student credit_rating buys_computer


<=30 high no fair no
<=30 high no excellent no
31…40 high no fair yes
>40 medium no fair yes
>40 low yes fair yes
>40 low yes excellent no
31…40 low yes excellent yes
<=30 medium no fair no
<=30 low yes fair yes
>40 medium yes fair yes
<=30 medium yes excellent yes
31…40 medium no excellent yes
31…40 high yes fair yes
>40 medium no excellent no 1

BÀI TẬP
Cho CSDL trên :
a) Sử dụng chỉ mục gini để xây dựng cây quyết định.
b) Áp dụng thuật toán ILA cho tập DL này để tìm tập
luật phân lớp, so sánh kết quả với tập luật rút ra từ
phương pháp cây quyết định trên.

1
Câu a): GINI INDEX
g Lớp P: buys_computer = age pj nj gini(pj, nj)
“Yes” <=30 2 3 0.48
g Lớp N: buys_computer = 31…40 4 0 0
“No”
g gini(D) = 0.459 >40 3 2 0.48
g Tính ch mc gini cho thuc
tính “age” ?
g Suy ra : 2 3
gini ( 2 , 3 ) = 1 − − = 0 . 48
5 5

5 4 5
giniage ( D) = gini(2,3) + gini(4,0) + gini(3,2)
14 14 14
= 0.343 3

Câu a): GINI INDEX


g Thuộc tính “income”
income pj nj gini(pj, nj)
high 2 2 0.5
medium 4 2 0.444
low 3 1 0.375

g Suy ra :

4 6 4
giniincome( D) = gini(2,2) + gini(4,2) + gini(3,1)
14 14 14
= 0.44 4

2
Câu a): GINI INDEX
g Thuộc tính “student”
student pj nj gini(pj, nj)
yes 6 1 0.245
no 3 4 0.49

g Suy ra :

7 7
ginistudent ( D) = gini(6,1) + gini(3,4) = 0.367
14 14
5

Câu a): GINI INDEX


g Thuộc tính “credit_rating”
credit_rating pj nj gini(pj, nj)
fair 6 2 0.375
excellent 3 3 0.5

g Suy ra :

8 6
ginicredit_ rating ( D) = gini(6,2) + gini(3,3) = 0.429
14 14
6

3
Câu a): GINI INDEX
g Sau khi tính độ đo chỉ mục Gini dựa
trên phân chia theo thuộc tính :
g Giniage(D) = 0.343
g Giniincome(D) = 0.44
g Ginistudent(D) = 0.367
g Ginicredit_rating(D) =0.429

g Đ đo ch mc Gini d


a trên phân chia
theo thuc tính “age” là nh nh t nên ta
s chia DL theo thuc tính “age” 7

Câu a): GINI INDEX


age?
Làm Làm
tương tự <=30 31..40 >40 tương tự

income student credit_rating buys_computer income student credit_rating buys_computer


high no fair no medium no fair yes
high no excellent no low yes fair yes
medium no fair no low yes excellent no
low yes fair yes medium yes fair yes
medium yes excellent yes medium no excellent no

income student credit_rating buys_computer


high no fair yes
low yes excellent yes
medium no excellent yes 8

high yes fair yes

4
Câu a): GINI INDEX
age?

<=30 31..40
>40

student? yes credit rating?

no yes excellent fair

no yes no yes
9

Câu b): THUẬT TOÁN ILA


Bảng con 1
age income student credit_rating buys_computer
<=30 high no fair no
<=30 high no excellent no
>40 low yes excellent no
<=30 medium no fair no
>40 medium no excellent no
• B2 : j = 1
• B3 : {[age], [income], [student], [credit_rating]}
• B4 : max-combination = “”
• B5 : j = j +1 =2 và quay lại B3
• B3 : {[age, income], [age, student], [age, credit_rating], [income, student],
10
[income, credit_rating], [student, credit_rating]}

5
Câu b): THUẬT TOÁN ILA
Bảng con 1
age income student credit_rating buys_computer
<=30 high no fair no
<=30 high no excellent no
>40 low yes excellent no
<=30 medium no fair no
>40 medium no excellent no
• B4 : max-combination = “<=30, no” (3 lần)
• B6 : đánh dấu dòng 1,2,4
• B7 : R1 : IF age = “<=30” AND student = “No” THEN buys_computer=“No”
• B8 : quay lại B4
11

Câu b): THUẬT TOÁN ILA


Bảng con 1
age income student credit_rating buys_computer
<=30 high no fair no
<=30 high no excellent no
>40 low yes excellent no
<=30 medium no fair no
>40 medium no excellent no

•B4 : max-combination = “>40, excellent” (2 lần)


• B6 : đánh dấu dòng 3,5
• B7 : R2 : IF age = “>40” AND credit_rating = “excellent” THEN
buys_computer=“No”
•B8 : chuyển qua bảng con 2 và bắt dầu từ B2 12

6
Câu b): THUẬT TOÁN ILA
Bảng con 2
age income student credit_rating buys_computer
31…40 high no fair yes
>40 medium no fair yes
>40 low yes fair yes
31…40 low yes excellent yes
<=30 low yes fair yes
>40 medium yes fair yes
<=30 medium yes excellent yes
31…40 medium no excellent yes
31…40 high yes fair yes 13

Câu b): THUẬT TOÁN ILA


• B2 : j = 1
• B3 : {[age], [income], [student], [credit_rating]}
• B4 : max-combination = “31…40”(4 lần)
• B6 : đánh dấu dòng 1,4,8,9
• B7 : R3 : IF age = “31…40” THEN buys_computer =“Yes”
• B8 : Quay lại B4
• B4 : max-combination = “”
• B5 : j = j +1 =2 và quay lại B3
• B3 : {[age, income], [age, student], [age, credit_rating], [income, student],
[income, credit_rating], [student, credit_rating]}

14

7
Câu b): THUẬT TOÁN ILA
• B4 : max-combination = “>40, fair” (3 lần)
• B6 : đánh dấu dòng 2,3,6
• B7 : R4 : IF age = “>40” AND credit_rating = “fair” THEN
buys_computer=“Yes”
• B8 : quay lại B4
• B4 : max-combination = “<=30, yes” (2 lần)
• B6 : đánh dấu dòng 5,7
• B7 : R5 : IF age = “<=30” AND student = “yes” THEN buys_computer=“Yes”
• B8 : kết thúc

15

Câu b): THUẬT TOÁN ILA


• R1 : IF age = “<=30” AND student = “No” THEN buys_computer=“No”
• R2 : IF age = “>40” AND credit_rating = “excellent” THEN
buys_computer=“No”
• R3 : IF age = “31…40” THEN buys_computer =“Yes”
• R4 : IF age = “>40” AND credit_rating = “fair” THEN
buys_computer=“Yes”
• R5 : IF age = “<=30” AND student = “yes” THEN buys_computer=“Yes”

• Nhận xét : tập luật này trùng với tập luật suy ra từ cây
quyết định

16

You might also like