Anda di halaman 1dari 11

Artificial Intelligence - STTS

ID3 : Induksi Decision Tree


Singkatan:
Iterative Dichotomiser 3
Induction of Decision "3" (baca: Tree)
Pembuat: Ross Quinlan, sejak akhir
dekade 70-an.
Pengembangan Lanjut: Cikal bakal
algoritma C4.5, pada tahun 1993.
Features: Tahap belajar yang cepat; time
complexity yang rendah; ketelitian
klasifikasi yang tinggi.
Kategori Learning: Concept Learning, dengan tujuan
mendeskripsikan "Konsep umum apakah yang digunakan?"

x1
x2 FUNGSI
x3 YANG TIDAK y = f (x1,x2,x3, ..... , xn)
: DIKETAHUI
xn

Tujuan Algoritma: mendapatkan decision tree (salah satu


bentuk "Classification Models") yang terbaik.
Problem: Upaya mendapatkan decision tree terbaik (minimal)
yang konsisten dari sekumpulan data, termasuk dalam
kategori algoritma NP-Hard / Completeness.
Mekanisme Konstruksi:
Dilakukan secara top-down, diawali pertanyaan: "Attribute
mana yang harus diperiksa pada root dari decision tree?"
Dibentuk dengan mempartisi training examples.
Kekuatan Algoritma yang Terutama: fungsi heuristik
information gain untuk memilih attribute terbaik.
Overview pada Algoritma: Mewujudkan Greedy Heuristic
Search: Hill-Climbing TANPA Backtracking.
Artificial Intelligence - STTS

Algoritma ID3
PROCEDURE ID3 (Examples, TargetAttribute, Attributes)
Examples are the training examples. Target-attribute is the attribute
whose value is to be predicted by the tree. Attributes is a list of
other attributes that may be tested by the learned decision tree.
Returns a decision tree that correctly classifies the given Examples.
Create a Root node for the tree
IF all Examples are positive, Return the single-node tree
Root, with label = +
IF all Examples are negative, Return the single-node tree
Root, with label = -
IF attributes is empty, Return the single-node tree Root, with
label = most common value of Target_attribute in Examples
Otherwise Begin
A <--- the attribute from Attributes that best* classifies
Examples
The decision attribute for Root <--- A
For each possible value, vi, of A,
- Add a new tree branch below Root, corresponding to
the test A = vi
- Let Examplesvi be the subset of Examples that have
value vi for A
- IF Examplesvi is empty
* THEN below this new branch add a leaf node with label
= most common value of Target_attribute in Examples
* ELSE below this new branch add the subtree
Call ID3(Examples, Target_attribute, Attributes - {A}))
End
Return Root
* The best attribute is the one with highes information gain, as
defined in Equation:

Gain(S, A) = Entropy(S) − Σ
v∈Values(A)
Sv
S
Entropy(S v )
Artificial Intelligence - STTS

Beberapa Terms dan Contoh


14 Minggu Permainan Tenis pada Setiap Sabtu Pagi
Examples (S), adalah training examples yang ditunjukkan
oleh tabel di bawah ini:
Day Outlook Temperature Humidity Wind Play
Tennis
D1 Sunny Hot High Weak No
D2 Sunny Hot High Strong No
D3 Overcast Hot High Weak Yes
D4 Rain Mild High Weak Yes
D5 Rain Cool Normal Weak Yes
D6 Rain Cool Normal Strong No
D7 Overcast Cool Normal Strong Yes
D8 Sunny Mild High Weak No
D9 Sunny Cool Normal Weak Yes
D10 Rain Mild Normal Weak Yes
D11 Sunny Mild Normal Strong Yes
D12 Overcast Mild High Strong Yes
D13 Overcast Hot Normal Weak Yes
D14 Rain Mild High Strong No

Target Attribute adalah PlayTennis yang memiliki value yes


atau no.
Attribute adalah Outlook, Temperature, Humidity, dan Wind.

Tunjukkan Model Klasifikasi Decision Tree untuk


Pengambilan Keputusan: "Bermain tenis atau tidak?",
dari 14 minggu pengalaman seperti ditunjukkan oleh
tabel di atas, dengan menggunakan Algoritma ID3 !
Artificial Intelligence - STTS

Solusi
S adalah koleksi dari 14 contoh dengan 9 contoh positif dan 5
contoh negatif, ditulis dengan notasi [9+,5-].
Entropy dari S adalah:
c
Entropy(S) =Σ − p i log 2 p i
i=1

Entropy([9+,5-]) = - (9/14)log2(9/14) - (5/14)log2(5/14)


= 0.94029
Catatan:
Entropy(S) = 0, jika semua contoh pada S berada dalam
kelas yang sama.
Entropy(S) = 1, jika jumlah contoh positif dan jumlah contoh
negatif dalam S adalah sama.
0 < Entropy(S) < 1, jika jumlah contoh positif dan negatif
dalam S tidak sama.

Gain(S,A) adalah Information Gain dari sebuah attribute A pada


koleksi contoh S:

Gain(S, A) = Entropy(S) − Σ
v∈Values(A)
Sv
S
Entropy(S v )
Artificial Intelligence - STTS

Values(Wind) = Weak, Strong


SWeak = [6+,2-]
SStrong = [3+,3-]
Gain(S,Wind) = Entropy(S) - (8/14)Entropy(SWeak) - 6/14)Entropy(SStrong)
= 0.94029 - (8/14)0.81128 - (6/14)1.0000
= 0.04813
Values(Humidity) = High, Normal
SHigh = [3+,4-]
SNormal = [6+,1-]
Gain(S,Humidity) = Entropy(S) - (7/14)Entropy(SHigh) -
(7/14)Entropy(SNormal)
= 0.94029 - (7/14)0.98523 - (7/14)0.59167
= 0.15184
Values(Temperature) = Hot, Mild, Cool
SHot = [2+,2-]
SMild = [4+,2-]
SCool = [3+,1-]
Gain(S,Temperature) = Entropy(S) - (4/14)Entropy(SHot) -
(6/14)Entropy(SMild) - (4/14)Entropy(SCool)
= 0.94029 - (4/14)1.00000 -
(6/14)0.91830 - (4/14)0.81128
= 0.02922
Values(Outlook) = Sunny, Overcast, Rain
SSunny = [2+,3-]
SOvercast = [4+,0-]
SRain = [3+,2-]
Gain(S,Outlook) = Entropy(S) - (5/14)Entropy(SSunny) -
(4/14)Entropy(SOvercast) - (5/14)Entropy(SRain)
= 0.94029 - (5/14)0.97075 - (4/14)1.000000 - (5/14)0.97075
= 0.24675
Jadi, information gain untuk 4 atribut yang ada adalah:
Gain(S,Wind) = 0.04813
Gain(S,Humidity) = 0.15184
Gain(S,Temperature) = 0.02922
Gain(S,Outlook) = 0.24675
Tampak bahwa attribute Outlook akan menyediakan prediksi
terbaik untuk target attribute PlayTennis.
Artificial Intelligence - STTS

[D1, D2, ... D14]


[9+,5-]

Outlook

Sunny Over cast Rain

? Yes ?
[D1, D2, D8, D9, D11] [D3, D7, D12, D13] [D4, D5, D6, D10, D14]
[2+,3-] [4+,0-] [3+,2-]

Untuk branch node Outlook=Sunny,


SSunny = [D1, D2, D8, D9, D11]
Day Outlook Temperature Humidity Wind Play
Tennis
D1 Sunny Hot High Weak No
D2 Sunny Hot High Strong No
D8 Sunny Mild High Weak No
D9 Sunny Cool Normal Weak Yes
D11 Sunny Mild Normal Strong Yes
Values(Temperature) = Hot, Mild, Cool
SHot = [0+,2-]
SMild = [1+,1-]
SCool = [1+,0-]
Gain(SSunny, Temperature)
= Entropy(SSunny) - (2/5)Entropy(SHot) -
(2/5)Entropy(SMild) - (1/5)Entropy(SCold)
= 0.97075 - (2/5)0.00000 -
(2/5)1.00000 - (1/5)0.00000
= 0.57075
Artificial Intelligence - STTS

Values(Humidity) = High, Normal


SHigh = [0+,3-]
SNormal = [2+,0-]
Gain(SSunny, Humidity)
= Entropy(SSunny) - (3/5)Entropy(SHigh) -
(2/5)Entropy(SNormal)
= 0.97075 - (3/5)0.00000 - (2/5)1.00000
= 0.97075

Values(Wind) = Weak, Strong


SWeak = [1+,2-]
SStrong = [1+,1-]
Gain(SSunny, Wind) = Entropy(SSunny) - (3/5)Entropy(SWeak) -
(2/5)Entropy(SStrong)
= 0.97075 - (3/5)0.91830 - (2/5)1.00000
= 0.01997

Attribute Humidity menyediakan prediksi terbaik pada level ini.

[D1, D2, ... D14]


[9+,5-]

Outlook

Sunny Over cast Rain


[D1, D2, D8, D9, D11] [D4, D5, D6, D10, D14]
[2+,3-] [3+,2-]

Humidity Yes ?
[D3, D7, D12, D13]
[4+,0-]
High Normal

No Yes
[D1, D2, D8] [D9, D11]
[0+,3-] [2+,0-]
Artificial Intelligence - STTS

Untuk branch node Outlook=Rain,


SRain = [D4, D5, D6, D10, D14]
Day Outlook Temperature Humidity Wind Play
Tennis
D4 Rain Mild High Weak Yes
D5 Rain Cool Normal Weak Yes
D6 Rain Cool Normal Strong No
D10 Rain Mild Normal Weak Yes
D14 Rain Mild High Strong No
Values(Temperature) = Mild, Cool
{Perhatikan: Tidak ada lagi temperature=hot saat ini}
SMild = [2+,1-]
SCool = [1+,1-]
Gain(SRain, Temperature) = Entropy(SRain) - (3/5)Entropy(SMild) -
(2/5)Entropy(SCold)
= 0.97075 - (3/5)0.91830 - (2/5)1.00000
= 0.01997

Values(Humidity) = High, Normal


SHigh = [1+,1-]
SNormal = [2+,1-]
Gain(SRain, Humidity) = Entropy(SRain) - (2/5)Entropy(SHigh) -
(3/5)Entropy(SNormal)
= 0.97075 - (2/5)1.00000 - (3/5)0.91830
= 0.01997

Values(Wind) = Weak, Strong


SWeak = [3+,0-]
SStrong = [0+,2-]
Gain(SRain, Wind) = Entropy(SRain) -(3/5)Entropy(SWeak) -
(2/5)Entropy(SStrong)
= 0.97075 - (3/5)0.00000 - (2/5)0.00000
= 0.97075

Attribute Wind menyediakan prediksi terbaik pada level ini.


Artificial Intelligence - STTS

[D1, D2, ... D14]


[9+,5-]

Outlook

Sunny Over cast Rain


[D1, D2, D8, D9, D11] [D4, D5, D6, D10, D14]
[2+,3-] [3+,2-]

Humidity Yes Wind


[D3, D7, D12, D13]
[4+,0-]

High Normal Weak Strong

No Yes Yes No
[D1, D2, D8] [D9, D11] [D4, D5, D10] [D6, D14]
[0+,3-] [2+,0-] [3+,0-] [0+,2-]

Rule-Rule yang telah Dipelajari:

IF Outlook = Sunny AND Humidity = High


THEN PlayTennis = No

IF Outlook = Sunny AND Humidity = Normal


THEN PlayTennis = Yes

IF Outlook = Overcast
THEN PlayTennis = Yes

IF Outlook = Rain AND Wind = Strong


THEN PlayTennis = No

IF Outlook = Rain AND Wind = Weak


THEN PlayTennis = Yes
Artificial Intelligence - STTS

Studi Kasus
Komite ujian untuk sebuah kampus bertemu mendiskusikan
hasil ujian sejumlah mahasiswanya.
Terdapat 3 (tiga) kemungkinan hasil evaluasi, mahasiswa bisa:
lulus (P=Pass);
diberi kesempatan mengulang (R=Resit); atau
gagal (F=Fail).
Beberapa pertemuan untuk memberikan hasil evaluasi sering
kali memakan waktu yang lama. Sering pula membutuhkan
penasihat ahli (pakar) pendidikan yang telah memiliki
pengalaman luas dari banyak pengambilan keputusan serupa.
Para pakar ini diminta untuk merumuskan sebuah petunjuk
(guidelines), dan mereka kemudian menyusun sekumpulan
contoh dari berbagai kasus pengambilan keputusan.
Target Attribute-nya adalah hasil evaluasi (Pass, Resit, dan
Fail), sedangkan attributes-nya adalah:
NFails : Jumlah ujian yang gagal
NMarg : Jumlah ujian yang gagal, dengan nilai
pada batas berhasil / gagal
Att : Catatan kehadiran mahasiswa
Ext : Ada / tidaknya kondisi yang
meringankan, misalnya kondisi sakit yang
menyebabkan kegagalan yang tak
diinginkan.
Ant : Hasil yang telah diantisipasi.
Induksi decision treenya dilakukan. Setelah pemeriksaan lanjut
model pengambilan keputusan ini, para ahli memutuskan untuk
menambahkan sejumlah contoh lagi pada kumpulan kasus,
sebab mereka merasa bahwa aturan-aturan untuk sekitar 2 atau
3 hasil yang gagal belumlah cukup. Mereka juga memutuskan
untuk memodifikasi contoh untuk nomor 8.
Artificial Intelligence - STTS

Tabel contoh mula-mula:


Example NFails NMarg Att Ext Ant Result
Number
1 0 0 good no P P
2 0 0 poor yes F P
3 0 0 good yes F P
4 3 0 good no F F
5 3 1 poor no F F
6 3 0 good no P F
7 3 2 good yes P R
8 2 1 poor no F R
9 2 2 good yes P R
10 1 0 poor yes P R
11 1 1 good yes F R
12 1 1 good no F R
13 1 0 poor no F F

Penambahan dan modifikasinya adalah sebagai berikut:

Example NFails NMarg Att Ext Ant Result


Number
8 2 1 poor no F F
14 3 2 good no P F
15 2 2 good no F R
16 2 1 good yes P R
17 2 0 poor no F F

Anda mungkin juga menyukai