S1 Teknik Informatika
Fakultas Teknologi Informasi
Universitas Kristen Maranatha
Pendahuluan
Classification
Decision tree induction
Bayesian classification
2 DM-MA/S1IF/FTI/UKM/2010
Classification :
◦
klasifikasi data berdasarkan training set and nilai-nilai (class labels)
dalam klasifikasi atribut, dan menggunakannya dalam klasifikasi data
baru
◦
memprediksi label kelas secara kategorikal (diskrit/nominal)
Prediction memodelkan fungsi kontinyu, mis. prediksi nilai hilang
atau tidak diketahui
atau tidak diketahui
Contoh aplikasi
◦
Credit approval : pinjaman aman atau beresiko
◦
Target marketing : customer potensial
◦
Medical diagnosis
◦
Fraud detection
Teknik-teknik :
◦
Classification : decision tree induction, Bayesian classification,
Bayesian belief network, neural network, k-nearest neighbour
classifier, CBR, algoritma genetic, rough set, fuzzy logic
Model construction: describing a set of predetermined classes
◦
Setiap sample diasumsikan termasuk predefined class, ditentukan oleh class label
attribute
◦
Kumpulan sample yang dipakai untuk model construction : training set
◦
Model direpresentasikan sebagai classification rules, decision trees, atau l formula
matematis
Model usage: classifying future or unknown objects
◦
Estimasi keakuratan model
◦
Estimasi keakuratan model
Label yang diketahui dari test sample dibandingkan dengan hasil klasifikasi dari
model
Accuracy rate = persentase dari kumpulan test sample yang diklasifikasikan
dengan benar oleh model
Test set bersifat independen terhadap training set
◦
Jika accuracy rate dapat diterima, pakai model untuk klasifikasi sample data yang
class labelnya belum diketahui
4 DM-MA/S1IF/FTI/UKM/2010
Training
Data
Classification
Algorithms
N A M E R A N K
Y E A R S T E N U R E D
M ike
Assistant Prof
3
no
M ary
Assistant Prof
7
yes
Bill
Professor
2
yes
Jim
Associate Prof
7
yes
Dave
Assistant Prof
6
no
Anne
Associate Prof
3
no
IF rank = ‘professor’
OR years > 6
THEN tenured = ‘yes’
Classifier
Classifier
Testing
Testing
Data
N A M E
R A N K
Y E A R S T E N U R E D
Tom
Assistant Prof
2
no
M erlisa Associate Prof
7
no
G eorge Professor
5
yes
Joseph Assistant Prof
7
yes
Unseen Data
(Jeff, Professor, 4)
Tenured?
6 DM-MA/S1IF/FTI/UKM/2010
Predictive accuracy :
◦
kemampuan model untuk memprediksi secara benar class label untuk
data baru
Speed :
◦
biaya komputasi untuk menghasilkan dan menggunakan model
Robustness :
Robustness :
◦
kemampuan model untuk membuat prediksi yang benar jika terdapat
noise atau missing data
Scalability :
◦
kemampuan membangun model secara efisien dalam data yang
berjumlah sangat besar
Interpretability :
Decision tree : struktur pohon, tiap internal node menyatakan sebuah
test pada suatu atribut, tiap cabang menyatakan hasil test, dan node
daun menyatakan class. Node paling atas adalah node akar (root).
Algoritma pembentukan tree :
(top down recursive, divide and conquer)◦
Tree mulai dengan node akar
◦
Jika seluruh sample ada di class yang sama, maka node tsb menjadi leaf dan
diberi label dengan class tsb.
◦
Jika tidak, gunakan information gain untuk memilih atribut yang paling baik
◦
Jika tidak, gunakan information gain untuk memilih atribut yang paling baik
dalam memisahkan sample ke class.
◦
Buat cabang untuk tiap nilai dari atribut test
◦
Ulangi proses pembuatan tree sampai :
Seluruh sample masuk ke class yang sama, atau
Tidak terdapat lagi atribut yang dapat memisahkan data sample
Tidak terdapat sample untuk cabang test atribut
8 DM-MA/S1IF/FTI/UKM/2010
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 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
age?
overcast
<=30
>40
31..40
DM-MA/S1IF/FTI/UKM/2010 10student?
credit rating?
no
yes
yes
yes
fair
excellent
yes
no
Attribute Selection Measure:
Information Gain (ID3/C4.5)
Pilih atribut dengan information gain tertinggi
Bila
p
i
: probabilitas sembarang tuple dalam D termasuk
class C
i, diestimasi sbg |C
i
, D|/|D|
Expected information
(entropy) untuk klasifikasi suatu
tuple dalam D:
m∑
−
=
tuple dalam D:
Information
(setelah memakai A utk membagi D ke dlm v
partisi) utk klasifikasi D:
Information gained
dengan pencabangan pada atribut A
)
(
log
)
(
2 1 i m i ip
p
D
Info
∑
=−
=
)
(
|
|
|
|
)
(
1 j v j j AI
D
D
D
D
Info
=
∑
×
=(D)
Info
Info(D)
Gain(A)
=
−
A
g
Class P: buys_computer = “yes”
g
Class N: buys_computer = “no”
means “age <=30” has 5 out of 14
samples, with 2 yes’es and 3 no’s.
age
p
in
iI(p
i, n
i)
<=30
2
3
0.971
694
.
0
)
2
,
3
(
14
5
)
0
,
4
(
14
4
)
3
,
2
(
14
5
)
(
=
+
+
=
I
I
I
D
Info
age)
3
,
2
(
14
5
I
940 . 0 ) 14 5 ( log 14 5 ) 14 9 ( log 14 9 ) 5 , 9 ( ) (D = I = − 2 − 2 = Infosamples, with 2 yes’es and 3 no’s.
Hence
Similarly,
<=30
2
3
0.971
31…40
4
0
0
>40
3
2
0.971
048
.
0
)
_
(
151
.
0
)
(
029
.
0
)
(
=
=
=
rating
credit
Gain
student
Gain
income
Gain
246
.
0
)
(
)
(
)
(
age
=
Info
D
−
Info
D
=
Gain
ageage 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
Classification— problem klasik yang diteliti secara ekstensif oleh ahli
statistik dan peneliti machine learning
Scalability: klasifikasi kumpulan data dengan jutaan contoh dan ratusan
atribut dengan reasonable speed
Mengapa memakai decision tree induction dalam data mining?
◦
Kecepatan belajar relatif lebih tinggi (dibandingkan cara classification yang
◦
Kecepatan belajar relatif lebih tinggi (dibandingkan cara classification yang
lain)
◦
Mudah diubah menjadi rule dan mudah dipahami
◦
Dapat memakai SQL query utk mengakses database
◦
Tingkat akurasinya dapat dibandingkan (comparable) dengan metoda
classification yang lain
Bayesian classifier : statistical classifier.
Dapat memprediksikan kemungkinan keanggotaan
class, misalnya probabilitas suatu sample menjadi
anggota suatu class tertentu.
Bayesian classification didasari oleh teorema Bayes
Bayesian classification didasari oleh teorema Bayes
P(X|H) P(H)
P(H|X) =
---P(X)
14 DM-MA/S1IF/FTI/UKM/2010
X : data sample yang label classnya belum diketahui
H : hipotesis, misalnya data sample X anggota class C.
Untuk classification, kita ingin menentukan P(H|X), yaitu
probabilitas hipotesis H dipenuhi terhadap sample data X.
P(H|X) : posterior probability / posteriori probability untuk H
sesuai kondisi X.
sesuai kondisi X.
Misalnya Buah, digambarkan dengan color dan shape.
Jika X : red,round ; H : X adalah apel maka
P(H|X) : keyakinan bahwa X adalah apel karena X adalah red dan
round
P(H) : prior probability / probability awal dari H.
Mis. probabilitas bahwa data sample adalah apel,
tanpa peduli bagaimana wujud sample
P(X|H) : posterior probability untuk X, probabilitas
observasi sample X, bila hipotesis dipenuhi
observasi sample X, bila hipotesis dipenuhi
Mis. probabilitas X adalah red & round jika kita tahu
bahwa X adalah apel.
P(X) : prior probability dari X, yaitu probability bahwa
sample data diobservasi
Mis. probabilitas bahwa data sample adalah red &
round.
16 DM-MA/S1IF/FTI/UKM/2010
Cara kerja naive Bayesian :
Tiap data sample dengan n atribut disajikan dalam
bentuk n-dimensional feature vector,
X = (x
1
,x
2
,….,x
n
)
Misalkan terdapat m class, C ,C , … C .
Misalkan terdapat m class, C
1
,C
2
, … C
m
.
Dengan data sample X, classifier akan memprediksi
bahwa X adalah anggota class yang memiliki posterior
probability tertinggi dengan kondisi X.
Sesuai teorema Bayes:
Karena P(X) konstan untuk seluruh class, maka hanya P(X|Ci) P(Ci)
P(X|Ci) P(Ci)
P(Ci|X) =
---P(X)
Karena P(X) konstan untuk seluruh class, maka hanya P(X|Ci) P(Ci)
yang perlu dimaksimalkan.
P(Ci) = Si/S, dengan Si adalah jumlah training sample dari class Ci,
dan S adalah jumlah seluruh training sample.
Karena menghitung P(X|Ci) memerlukan komputasi mahal, maka
dibuat asumsi yaitu bahwa tidak ada hubungan ketergantungan
antar atribut.
Hitung P(Xk|Ci) = Sik/Si. Sik adalah jumlah training sample class Ci
yang mempunyai nilai Xk, Si adalah jumlah training sample dari
class Ci.
18 DM-MA/S1IF/FTI/UKM/2010
age
income
student credit_rating buys_c
<=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
Class:
C1:buys_computer = ‘yes’
C2:buys_computer = ‘no’
>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
Data sample
X = (age <=30,
Income = medium,
Student = yes
Credit_rating = Fair)
P(C
i):
P(buys_computer = “yes”) = 9/14 = 0.643 P(buys_computer = “no”) = 5/14= 0.357
Compute P(X|C
i) for each class
P(age = “<=30” | buys_computer = “yes”) = 2/9 = 0.222 P(age = “<= 30” | buys_computer = “no”) = 3/5 = 0.6
P(income = “medium” | buys_computer = “yes”) = 4/9 = 0.444 P(income = “medium” | buys_computer = “no”) = 2/5 = 0.4 P(student = “yes” | buys_computer = “yes) = 6/9 = 0.667 P(student = “yes” | buys_computer = “yes) = 6/9 = 0.667 P(student = “yes” | buys_computer = “no”) = 1/5 = 0.2
P(credit_rating = “fair” | buys_computer = “yes”) = 6/9 = 0.667 P(credit_rating = “fair” | buys_computer = “no”) = 2/5 = 0.4
X = (age <= 30 , income = medium, student = yes, credit_rating = fair)
P(X|Ci) : P(X|buys_computer = “yes”) = 0.222 x 0.444 x 0.667 x 0.667 = 0.044 P(X|buys_computer = “no”) = 0.6 x 0.4 x 0.2 x 0.4 = 0.019
P(X|Ci)*P(Ci) : P(X|buys_computer = “yes”) * P(buys_computer = “yes”) = 0.028 (MAX)
P(X|buys_computer = “no”) * P(buys_computer = “no”) = 0.007 Therefore, X belongs to class (“buys_computer = yes”)
20 DM-MA/S1IF/FTI/UKM/2010
Naïve Bayesian prediction memerlukan setiap conditional prob. harus
non-zero. Jika tidak, predicted probability akan bernilai 0
Mis. Terdapat dataset dengan 1000 tuples, income=low (0), income=
∏
=
=
n
k
xk
Ci
P
Ci
X
P
1
)
|
(
)
|
(
Mis. Terdapat dataset dengan 1000 tuples, income=low (0), income=
medium (990), and income = high (10),
Memakai Laplacian correction ( Laplacian estimator)
◦
Tambahkan 1 pada setiap kasus
Prob(income = low) = 1/1003
Prob(income = medium) = 991/1003 Prob(income = high) = 11/1003
Keuntungan
◦
Mudah diimplementasikan
◦
Memberikan hasil cukup baik pada banyak kasus
Kerugian
◦
Asumsi: class conditional independence => kehilangan akurasi
◦
Secara Praktis, dependency ada di antara variabel
Mis., hospitals: patients: Profile: age, family history, dll
Mis., hospitals: patients: Profile: age, family history, dll
Symptoms: fever, cough , dll Disease: lung cancer, diabetes, dll
Dependency antara variabel tidak dapat dimodelkan dengan Naïve Bayesian Classifier
Bagaimana menangani dependency?
◦
Bayesian Belief Networks
22 DM-MA/S1IF/FTI/UKM/2010
Representasi pengetahuan dalam bentuk
IF-THEN
rules
R: IF age = youth AND student = yes THEN buys_computer = yes
◦ Rule antecedent/precondition vs. rule consequent
Penilaian rule: coverage and accuracy
◦ ncovers = # of tuples covered by R◦ ncorrect = # of tuples correctly classified by R coverage(R) = ncovers /|D| /* D: training data set */ coverage(R) = ncovers /|D| /* D: training data set */ accuracy(R) = ncorrect / ncovers
Jika lebih dari satu rule ditrigger, maka perlu conflict resolution
◦ Size ordering: berikan prioritas tinggi untuk rules yang bersifat “toughest” (mis., rule dengan most attribute test)
◦ Class-based ordering: mengurangi order dari prevalence atau misclassification cost per class
◦ Rule-based ordering (decision list): rules diorganisasi menjadi satu daftar prioritas, mengikuti ukuran kualitas rule atau saran pakar.
age?
student? credit rating?
<=30 >40 no yes yes yes 31..40 fair excellent yes no
•
Rules lebih mudah dipahami dibandingkan tree
•
Satu rule diciptakan untuk setiap jalur dari akar
ke daun
•
Setiap pasang attribute-value dalam suatu jalur
membentuk conjunction: daun adalah class
prediction
Example: Rule extraction from our buys_computer decision-tree
IF age = young AND student = no THEN buys_computer = no IF age = young AND student = yes THEN buys_computer = yes IF age = mid-age THEN buys_computer = yes
IF age = old AND credit_rating = excellent THEN buys_computer = yes IF age = young AND credit_rating = fair THEN buys_computer = no
prediction
•
Rules bersifat mutually exclusive dan exhaustive
24 DM-MA/S1IF/FTI/UKM/2010
id member age student income class:buys_funky_tshirt 1 no <=20 n high n 2 yes <=20 n high n 3 no 21 .. 25 n high y 4 no 26 .. 30 n medium y 5 no 26 .. 30 y low y 5 no 26 .. 30 y low y 6 yes 26 .. 30 y low n 7 yes 21 .. 25 y low y 8 no <=20 n medium n 9 no <=20 y low y 10 no 26 .. 30 y medium y 11 yes <=20 y medium y 12 yes 21 .. 25 n medium y
Dengan training data set tersebut, buatlah decision
tree-nya. Jangan lupa sertakan langkah-langkah,
perhitungan, serta pertimbangan untuk menghilangkan
node tertentu (jika ada).
Cari prediksi dengan naïve Bayesian classifier untuk
Cari prediksi dengan naïve Bayesian classifier untuk
sample X = (member=yes, age=26..30, student=no,
income=high),
sertakan langkah-langkah dan perhitungannya.
26 DM-MA/S1IF/FTI/UKM/2010