max
Probabilitas Bersyarat
S
P( X Y )
X
XY
P (Y | X )
Y P( X )
P (Y X )
P( X | Y )
P (Y )
Contoh :
… P ( X k ).P (Y | X k )
X1 X2 Xn P ( X k | Y )
. P (Y )
P ( X k ).P (Y | X k )
P( X k | Y )
Y
P( X i ).P(Y | X i )
i
argmax P( Y | X ) P(X)
P( X | Y ) =
xX P(Y )
argmax
= P( Y | X ) P(X)
xX
HMAP adalah model penyederhanaan dari metode bayes yang disebut dengan Naive
Bayes. HMAP inilah yang digunakan di dalam machine learning sebagai metode untuk
mendapatkan hipotesis untuk suatu keputusan.
HMAP (Naïve Bayes) Dari Data Training
# Cuaca Temperatur Kecepatan Angin Berolah-raga
1 Cerah Normal Pelan Ya
2 Cerah Normal Pelan Ya
3 Hujan Tinggi Pelan Tidak
4 Cerah Normal Kencang Ya
5 Hujan Tinggi Kencang Tidak
6 Cerah Normal Pelan Ya
Asumsi:
Y = berolahraga,
X1 = cuaca,
X2 = temperatur,
X3 = kecepatan angin.
Fakta menunjukkan:
P(Y=ya) = 4/6 P(Y=tidak) = 2/6
HMAP (Naïve Bayes) Dari Data Training
# Cuaca Temperatur Kecepatan Angin Berolah-raga
1 Cerah Normal Pelan Ya Apakah bila cuaca
2 Cerah Normal Pelan Ya cerah dan
3 Hujan Tinggi Pelan Tidak kecepatan angin
4 Cerah Normal Kencang Ya kencang, orang
5 Hujan Tinggi Kencang Tidak akan berolahraga?
6 Cerah Normal Pelan Ya
A new day
outlook temperature humidity windy play
sunny cool high true ?
The weather data, with counts and probabilities
outlook temperature humidity windy play
yes no yes no yes no yes no yes no
A new day
outlook temperature humidity windy play
sunny cool high true ?
Likelihood
of yes
2 3 3 3 9
0.0053
9 9 9 9 14
Likelihoodof no
3 1 4 3 5
0.0206
5 5 5 5 14
Therefore, the prediction is No
Beberapa Contoh Klasifikasi TEXT
22
SMS Spam atau Not Spam
● Beli 6 Gratis 6 Donut dari DUNKIN DONUTS BORMA SETIABUDHI. Tukarkan SMS
ini segera. Hanya berlaku untuk hari ini. Selama persediaan masih ada. Promo
*606#
● 5 HARI LAGI ! EKSTRA Pulsa 50rb dg beli paket internet bulanan di
MyTelkomsel utk pembelian pertama sjk 25Aug-25Sept. Cek detail promo di
tsel.me/mytsel1
● Maaf, pulsa Anda tidak cukup untuk melakukan pembelian paket Flash yang
dipilih. Silahkan isi ulang pulsa Anda.
● Dptkn Free member card Larissa Aesthetic Center, disc 15% high treatment &
asuransi jiwa, tiap isi ulang pulsa Rp 100rb di Galeri Indosat Jateng DIY s.d 31Des
13
23
Penulis Pria atau Wanita
1. By 1925 present-day Vietnam was divided into three parts under French
colonial rule. The southern region embracing Saigon and the Mekong delta
was the colony of Cochin-China; the central area with its imperial capital at
Hue was the protectorate of Annam…
2. Clara never failed to be astonished by the extraordinary felicity of her own
name. She found it hard to trust herself to the mercy of fate, which had
managed over the years to convert her greatest shame into one of her
greatest assets…
S. Argamon, M. Koppel, J. Fine, A. R. Shimoni, 2003. “Gender, Genre, and Writing Style in Formal Written Texts,” Text, volume 23, number 3, pp.
24
321–346
Gender di Tweet
Lima fitur yang paling penting
untuk memisahkan gender:
● kata partikel
● kata asing / daerah
● kata emosi
● kata ganti orang ke-dua
● kata_kerja_khusus.
Wibisono, Yudi, and Naufal Faruqi. "Penentuan gender otomatis berdasarkan isi microblog memanfaatkan
fitur sosiolinguistik." Jurnal Cybermatika 1.1 (2013).
25
Sentimen positif atau negatif
● unbelievably disappointing
● Full of zany characters and richly applied satire,
and some great plot twists
● this is the greatest screwball comedy ever filmed
● It was pathetic. The worst part about it was the
boxing scenes.
26
Sentimen Positif dan Negatif
● Ujan2 gini dsruh lari2 kklinik haha malesin..Org2 bpjs itu ngapa jg gak
drtd dtg nya, nyusahin aja sih
● Org2 mengeluh buruknya layanan BPJS. Kami sangat trbantu ketika ibu
kami didiagnosa menderita kanker stadium 4..
● @astrimeina @mrshananto kalo yg itu gak tau deh. yg pasti udah bbrp
orang yg gw kenal tmsk gw, sepupu n ipar cesar pake BPJS puji Tuhan
Aman
● website BPJS ini aneh. abis registrasi diminta verifikasi email, tapi dicek
gak ada email masuk. bloon.
Implementasi Naïve Bayes Classifier Pada Sistem Analisis Sentimen Twitter, Rachman, Wibisono 2015 27
Berita →
topik apa?
28
Topik Makalah
29
Klasifikasi Teks
• Input:
• dokumen d (bisa juga tweet, sms dsb)
• kelas C = {c1, c2,…, cJ}
31
Metode Klasifikasi: Hand-coded rules
32
Classification:
Supervised Machine Learning
• Input:
• dokumen d
• kelas C = {c1, c2,…, cJ}
• training set m dokumen hand-labeled (d1,c1),....,(dm,cm)
• Output:
• classifier γ:d → c
33
Classification:
Supervised Machine Learning
Jenis classifier
• Naïve Bayes
• Logistic regression
• Support-vector machines
• k-Nearest Neighbors
• Neural Network
• ...
34
Klasifikasi Naive Bayes Untuk Dokumen
• Simple (“naïve”) classification berdasarkan Bayes rule
• Menggunakan representasi paling sederhana dari
dokumen
• Bag of words (BoW)
35
Representasi Bag of Words
36
Some Term Weighting Schemes
1. Term Frequency (TF)
2. Term Frequency-Inverse Document Frequency (TF-IDF)
3. TF-CHI (TF-Chi Square)
4. TF-RF (TF-Relevance Frequency)
5. TF-Prob
6. TF-ICF (TF-Inverse Corpus Frequency)
7. Term Frequency-Inverse Document Frequency- Inverse Class Space Density
Frequency (TF-IDF-ICSDF)
8. Term Frequency-Inverse Gravity Moment (TF-IGM)
9. TF-IGM (Term Frequency - Inverse Gravity Moment)
10. RTF-IGM (Root Term Frequency - Inverse Gravity Moment)
37
Bayes untuk dokumen (lanj)
38
Bayes untuk dokumen (lanj)
MAP: “maximum a
posteriori” = kelas yang
paling mungkin
Bayes Rule
denominator
dibuang karena
sama untuk semua
kelas 39
Bayes untuk dokumen (lanj)
Document d direpsentasikan
dalam seq. kata x1..xn
40
Masalah
O(|X|n•|C|) parameters
42
43
Cara Pertama
doccount(C=cj): jumlah
dokumen kelas cj
Dibagi jumlah
semua kata
dalam class cj
44
Masalah
nol
45
Laplace (add-1) smoothing for Naïve Bayes
46
Example train and test data
Terms
t1 t2 Label
Training Doc D1 3 2 +
D2 7 10 -
D3 8 8 -
D4 1 3 +
D5 4 2 +
Testing Doc D6 5 8 ?
Contoh lain
50
Jumlah data >>
algoritma
52
Analisis Google Product Search
Sentimen
53
Bing Shopping
54
Opini tentang Telkomsel di Twitter
55
Nama lain Analisis Sentimen
• Opinion extraction
• Opinion mining
• Sentiment mining
• Subjectivity analysis
56
Mengapa Analisis Sentimen?
57
Analisis Sentimen: detection of attitudes
“enduring, affectively colored beliefs, dispositions towards
objects or persons”
1. Sumber attitude
2. Target atau aspek attitude
3. Tipe attitude
• Like, love, hate, value, desire, etc.
• simple weighted polarity: positif, negatif, netral
4. Text yang mengandung attitude
• kalimat atau dokumen
58
Analisis Sentimen
• Paling sederhana:
• Apakah attitude pada teks positif atau neg?
• Agak kompleks:
• Beri peringkat attitude dari 1 sd 5 (bintang)
• Kompleks:
• Identifikasi target, source, complex attitude type
59
Baseline Algorithm
• Preprocessing (Tokenisasi, dll)
• Ekstraksi Fitur
• Klasifikasi
• Naïve Bayes
• MaxEnt
• SVM
60
Tokenisasi
61
Ekstraksi Fitur
● Kalimat negatif
○ Saya tidak suka film ini
○ Saya suka film ini, tapi
○ Saya suka film ini.. dalam mimpi hehe
62
Masalah pada Analisis Sentimen
• Tidak eksplisit
• Ambiguitas
63
Evaluation
Confusion Matrix
Actual
Yes No Precision
Predicted Yes TP FP
No FN TN
Recall
Evaluation
Evaluation
Actual
Sport Economy Politic Health Precision
Predicted Sport 5 2 1 5/8
Economy 3 7 2 3/12
Politic 3 3 1 3/7
Health 4 1 1 8 8/14
Recall 5/12 3/4 3/13 8/12