IF-UTAMA 1
Decision Tree
Sesi 09
Dosen Pembina : Danang Junaedi
IF-UTAMA 2
Classification
IF-UTAMA 3
Konsep Decision Tree
• Mengubah data menjadi pohon keputusan (decision tree) dan aturan-aturan
keputusan (rule)
IF-UTAMA 4
Decision Tree
When To Consider Decision Tree?
Penggunaan Decision Tree
• Diagnosa penyakit tertentu, seperti hipertensi, kanker, stroke dan lain-lain
• Pemilihan produk seperti rumah, kendaraan, komputer dan lain-lain
• Pemilihan pegawai teladan sesuai dengan kriteria tertentu
• Deteksi gangguan pada komputer atau jaringan komputer seperti Deteksi Entrusi, deteksi virus (trojan dan varians)
• dll
IF-UTAMA 7
Gambaran Pemakaian Decision Tree
IF-UTAMA 8
Sample
IF-UTAMA 9
Information Theory
IF-UTAMA 10
Information Theory (contd)
Information Theory (contd)
Konsep Data dalam Decision Tree• Data dinyatakan dalam bentuk tabel dengan atribut dan record.
• Atribut menyatakan suatu parameter yang dibuat sebagai kriteria dalam pembentukan tree. Misalkan untuk menentukan main tenis, kriteria yang diperhatikan adalah cuaca, angin dan temperatur. Salah satu atribut
IF-UTAMA 13
Proses Dalam Decision Tree
1. Mengubah bentuk data (tabel) menjadi model tree.
– ID3 Algorithm – C.45 Algorithm – etc
2. Mengubah model tree menjadi rule – Disjunction (v Æ OR)
– Conjunction (^ Æ AND)
3. Menyederhanakan Rule (Pruning)
IF-UTAMA 14
Mengubah Data Î Tree
IF-UTAMA 15
Tree Æ Rule
IF-UTAMA 16
Tree Æ Rule (contd)
Decision Tree Induction For Classification
How
IF-UTAMA 19
ID3 Algorithm
IF-UTAMA 20
ID3 Algorithm (contd)
IF-UTAMA 21
ID3 Algorithm
Given a set of examples, S, categorised in categories ci, then:
1. Choose the root node to be the attribute, A, which scores the highest for information gain relative to S.
2. For each value v that A can possibly take, draw a branch from the node.
3. For each branch from A corresponding to value v, calculate Sv.
Then:
– If Sv is empty, choose the category cdefault which contains the most examples from S, and put this as the leaf node category which ends that branch.
– If Sv contains only examples from a category c, then put c as the leaf node category which ends that branch.
– Otherwise, remove A from the set of attributes which can be put into nodes. Then put a new node in the decision tree, where the new attribute being tested in the node is the one which scores highest for information gain relative to Sv (note: not relative to S). This new node starts the cycle again (from 2), with S replaced by Sv in the calculations and the tree gets built iteratively like this.
• The algorithm terminates either when all the attributes have been exhausted, or the decision tree perfectly classifies the examples.
IF-UTAMA 22
ID3 Algorithm Ilustration Diagram
Pembentukan Tree
• Spesifikasikan masalahÎmenentukan Atribut dan Target Atribut berdasarkan data yang ada
• Hitung nilai Entropy dari setiap kriteria dengan data sample yang ditentukan.
• Hitung Information Gain dari setiap kriteria
Entropy
• Entropy(S) adalah jumlah bit yang diperkirakan dibutuhkan untuk dapat mengekstrak suatu kelas (+
atau -) dari sejumlah data acak pada ruang sample S.
• Entropy bisa dikatakan sebagai kebutuhan bit untuk menyatakan suatu kelas. Semakin kecil nilai Entropy
IF-UTAMA 25
Entropy (contd)
IF-UTAMA 26
Entropy (contd)
IF-UTAMA 27
Information Gain
IF-UTAMA 28
Example
Training Data Set
Example (contd) Example (contd)
IF-UTAMA 31
Example (contd)
IF-UTAMA 32
Example (contd)
IF-UTAMA 33
Example (contd)
IF-UTAMA 34
Example (contd)
Example (contd) Example (contd)
IF-UTAMA 37
Extracting Classification Rule Form Tree
IF-UTAMA 38
Data Mentah
Decision Tree??
Sample Atribut Target Atribut
IF-UTAMA 39
Entropy Awal
• Jumlah instance = 8
• Jumlah instance positif = 3
• Jumlah instance negatif = 5
(Hipertensi) Pins cepositif Pins cepositif Pins cenegatif Pins cenegatif
Entropy =− tan _ log2 tan _ − tan _ log2 tan _
( ) ( )
( ) ( )
0,955 0,424 0,531
0.678 - 625 . 0 -1.415 375 . 0
625 . 0 log 625 . 0 375 . 0 log 375 . 0
8 log 5 8 5 8 log 3 8 3
2 2
2 2
= +
=
×
−
×
−
=
×
−
×
−
=
⎟⎟⎠
⎜⎜ ⎞
⎝
⎛ ⎟
⎠
⎜ ⎞
⎝
× ⎛
⎟⎠
⎜ ⎞
⎝
− ⎛
⎟⎟⎠
⎜⎜ ⎞
⎝
⎛ ⎟
⎠
⎜ ⎞
⎝
× ⎛
⎟⎠
⎜ ⎞
⎝
−⎛
=
IF-UTAMA 40
Entropy Usia
• Jumlah instance = 8
• Instance Usia – Muda
• Instance positif = 1
• Instance negatif = 3 – Tua
• Instance positif = 2
• Instance negatif = 2
• Entropy Usia
– Entropy(muda) = 0.906 – Entropy(tua) = 1
( )
( ) ins cepositif ins cepositif ins cenegatif ins cenegatif
negatif ce ins negatif ce ins positif ce ins positif ce ins
P P
P P
Tua Entropy
P P
P P
Muda Entropy
_ tan 2 _ tan _ tan 2 _ tan
_ tan 2 _ tan _ tan 2 _ tan
log log
log log
−
−
=
−
−
=
Gain Usia
( ) ( ) ( )
( ) ( ) ( )
( ) ( ) ( )
002 . 0
5 . 0 453 . 0 955 . 0
81 906 4 . 8 0 955 4 . 0
,
,
=
−
−
=
−
−
=
−
−
=
−
= ∑
∈
Tua Tua
Muda Muda
v Tua
Muda v
v
S Entropy S
S S Entropy S
S S Entropy
S Entropy S S S
Entropy Usia
S Gain
Entropy Berat
• Jumlah instance = 8
• Intance Berat – Overweight
• Instance positif = 3
• Instance negatif = 1 – Average
• Instance positif = 0
• Instance negatif = 2 – Underweight
• Instance positif = 0
• Instance negatif = 2
– Entropy(Overweight)=0.906
( )
( )
( ) ins cepositif ins cepositif ins cenegatif ins cenegatif
negatif ce ins negatif ce ins positif ce ins positif ce ins
negatif ce ins negatif ce ins positif ce ins positif ce ins
P P
P P
t Underweigh Entropy
P P
P P
Average Entropy
P P
P P
Overweight Entropy
_ tan 2 _ tan _ tan 2 _ tan
_ tan 2 _ tan _ tan 2 _ tan
_ tan 2 _ tan _ tan 2 _ tan
log log
log log
log log
−
−
=
−
−
=
−
−
=
IF-UTAMA 43
Gain Usia
( ) ( ) ( )
( ) ( ) ( ) ( )
( ) ( ) ( ) ( )
0,252
125 . 0 125 . 0 453 . 0 955 . 0
5 . 80 5 2 . 80 906 2 . 80 955 4 . 0 ,
, ,
=
−
−
−
=
−
−
−
=
−
−
−
=
−
= ∑
∈
t Underweigh t
Underweigh average Average
Overweight Overweight
v t Underweigh Average Overwight v
v
S Entropy S S S Entropy S S S Entropy S S S Entropy
S Entropy S S S
Entropy Berat S Gain
IF-UTAMA 44
Entropy Jenis Kelamin
• Jumlah instance = 8
• Intance Jenis Kelamin – Pria
• Instance positif = 2
• Instance negatif = 4 – Wanita
• Instance positif = 1
• Instance negatif = 1
– Entropy(Pria)=1 – Entropy(Wanita)=0.75
( )
( ) ins cepositif ins cepositif ins cenegatif ins cenegatif
negatif ce ins negatif ce ins positif ce ins positif ce ins
P P
P P
Wanita Entropy
P P
P P
ia Entropy
_ tan 2 _ tan _ tan 2 _ tan
_ tan 2 _ tan _ tan 2 _ tan
log log
log log
Pr
−
−
=
−
−
=
IF-UTAMA 45
Gain Usia
( ) ( ) ( )
( ) ( ) ( )
( ) ( ) ( )
0,017
188 . 0 75 . 0 955 . 0
75 . 8 0 1 2 8 955 6 . 0
min ,
Pr Pr
, Pr
=
−
−
=
−
−
=
−
−
=
−
= ∑
∈
Wanita Wanita
ia ia
v Wanita
ia v
v
S Entropy S
S S Entropy S S S Entropy
S Entropy S S S
Entropy JenisKela
S Gain
IF-UTAMA 46
• Atribut yang dipilih adalah atribut berat karena nilai Information Gainnya paling tinggi
• Jumlah Instance untuk Overweight = 4
• Jumlah Instance untuk Average = 2
• Jumlah Instance untuk Underweight = 2
• Hitung Gain paling tinggi untuk dijadikan cabang berikutnya
Berat
Overweight
Average
Underweight
Node untuk cabang Overweight
• Jumlah instance = 4
• Instance (Berat = Overwight ) & Usia = – Muda
• Instance positif = 1
• Instance negatif = 0 – Tua
Decision Tree yang dihasilkan
IF-UTAMA 49
Strength of Decision Tree
IF-UTAMA 50
Weakness of Decision Tree
IF-UTAMA 51
Studi Kasus
IF-UTAMA 52
Studi Kasus
Referensi
1. Dr. Mourad YKHLEF.2009. Decision Tree Induction System.King Saud University 2. Achmad Basuki, Iwan Syarif. 2003. Decision
Tree. Politeknik Elektronika Negeri Surabaya (PENS) – ITS
3. Simon Colton.2004. Decision Tree Learning.- 4. Tom M. Mitchell. 1997. Machine Learning.
Mc-Graw Hill