Naïve Bayes Classifier merupakan sebuah metoda klasifikasi yang berakar pada teorema Bayes . Metode pengklasifikasian dg menggunakan metode probabilitas dan statistik yg dikemukakan oleh ilmuwan Inggris Thomas Bayes , yaitu memprediksi peluang di masa depan berdasarkan pengalaman di masa sebelumnya sehingga dikenal sebagai Teorema Bayes . Ciri utama dr Naïve Bayes Classifier ini adalah asumsi yg sangat kuat (naïf) akan independensi dari masing-masing kondisi / kejadian.
Menurut Olson Delen (2008) menjelaskan Naïve Bayes unt setiap kelas keputusan, menghitung probabilitas dg syarat bahwa kelas keputusan adalah benar, mengingat vektor informasi obyek. Algoritma ini mengasumsikan bahwa atribut obyek adalah independen. Probabilitas yang terlibat dalam memproduksi perkiraan akhir dihitung sebagai jumlah frekuensi dr ” master ” tabel keputusan.
Daftar Isi
Contoh Kasus Perhitungan Naive Bayes
#01 Data Atribut
Berikut adalah atribut yang digunakan dalam perhitungan naive bayes.
Kode | Nama |
---|---|
A1 | OUTLOOK |
A2 | TEMPERATURE |
A3 | HUMIDITY |
A4 | WINDY |
A5 | PLAY |
Atribut PLAY merupakan label/klasifikasi yang akan dicari berdasarkan dari data atribut yang diketahui.
#02 Data Nilai Atribut
Data nilai atribut merupakan pilihan nilai yang mungkin untuk masing-masing atribut.
Kode | Nama | Nilai |
---|---|---|
A1 | OUTLOOK | cloudy |
A1 | OUTLOOK | rainy |
A1 | OUTLOOK | sunny |
A2 | TEMPERATURE | cold |
A2 | TEMPERATURE | hot |
A2 | TEMPERATURE | mild |
A3 | HUMIDITY | high |
A3 | HUMIDITY | normal |
A4 | WINDY | false |
A4 | WINDY | true |
A5 | PLAY | yes |
A5 | PLAY | no |
#03 Data Latih
Data latih (Data Training) merupakan data aktual sebagai acuan untuk melakukan perhitungan naive bayes. Berikut adalah 14 data latih yang diketahui.
Nomor | OUTLOOK | TEMPERATURE | HUMIDITY | WINDY | PLAY |
---|---|---|---|---|---|
1 | sunny | hot | high | false | no |
2 | sunny | hot | high | true | no |
3 | cloudy | hot | high | false | yes |
4 | rainy | mild | high | false | yes |
5 | rainy | cool | normal | false | yes |
6 | rainy | cool | normal | true | yes |
7 | cloudy | cool | high | true | yes |
8 | sunny | mild | high | false | no |
9 | sunny | cool | normal | false | yes |
10 | rainy | mild | normal | false | yes |
11 | sunny | mild | normal | true | yes |
12 | cloudy | mild | high | true | yes |
13 | cloudy | hot | normal | false | yes |
14 | rainy | mild | high | true | no |
#04 Data Uji
Sebelum melakukan proses algoritma naive bayes, berikut adalah data uji yang akan dicari klasifikasinya.
OUTLOOK: rainy
TEMPERATURE: hot
HUMIDITY: high
WINDY: true
PLAY: ?
#05 Mencari Probabilitas
Langkah pertama dalam perhitungan naive bayes adalah mencari probabilitas setiap nilai atribut sesuai data latih.
Berikut probabilitas kemunculan nilai atribut label:
- P(no) = (4/14) = 0.2857
- P(yes) = (10/14) = 0.7143
Berikut probabilitas kemunculan nilai atribut diketahui:
- OUTLOOK
- P(sunny | no) = (OUTLOOK: sunny berlabel no/ jumlah label no) (3/4) = 0.75
- P(sunny | yes) = (OUTLOOK: sunny berlabel yes/ jumlah label yes) (2/10) = 0.2
- P(cloudy | yes) = (OUTLOOK: cloudy berlabel yes/ jumlah label yes) (4/10) = 0.4
- P(rainy | yes) = (OUTLOOK: rainy berlabel yes/ jumlah label yes) (4/10) = 0.4
- P(rainy | no) = (OUTLOOK: rainy berlabel no/ jumlah label no) (1/4) = 0.25
- TEMPERATURE
- P(hot | no) = (TEMPERATURE: hot berlabel no/ jumlah label no) (2/4) = 0.5
- P(hot | yes) = (TEMPERATURE: hot berlabel yes/ jumlah label yes) (2/10) = 0.2
- P(mild | yes) = (TEMPERATURE: mild berlabel yes/ jumlah label yes) (4/10) = 0.4
- P(mild | no) = (TEMPERATURE: mild berlabel no/ jumlah label no) (2/4) = 0.5
- P(cool | yes) = (TEMPERATURE: cool berlabel yes/ jumlah label yes) (4/10) = 0.4
- HUMIDITY
- P(high | no) = (HUMIDITY: high berlabel no/ jumlah label no) (4/4) = 1
- P(high | yes) = (HUMIDITY: high berlabel yes/ jumlah label yes) (4/10) = 0.4
- P(normal | yes) = (HUMIDITY: normal berlabel yes/ jumlah label yes) (6/10) = 0.6
- WINDY
- P(false | no) = (WINDY: false berlabel no/ jumlah label no) (2/4) = 0.5
- P(false | yes) = (WINDY: false berlabel yes/ jumlah label yes) (6/10) = 0.6
- P(true | no) = (WINDY: true berlabel no/ jumlah label no) (2/4) = 0.5
- P(true | yes) = (WINDY: true berlabel yes/ jumlah label yes) (4/10) = 0.4
Jika disusun dalam bentuk tabel, maka hasilnya seperti berikut:
Atribut | Nilai | no(0.2857) | yes(0.7143) |
---|---|---|---|
OUTLOOK | sunny | 0.2 | 0.75 |
OUTLOOK | cloudy | 0.4 | 0 |
OUTLOOK | rainy | 0.4 | 0.25 |
TEMPERATURE | hot | 0.2 | 0.5 |
TEMPERATURE | mild | 0.4 | 0.5 |
TEMPERATURE | cool | 0.4 | 0 |
HUMIDITY | high | 0.4 | 1 |
HUMIDITY | normal | 0.6 | 0 |
WINDY | false | 0.6 | 0.5 |
WINDY | true | 0.4 | 0.5 |
#06 Perhitungan Data Uji
Pada tahap ini, setiap nilai label akan dihitung propabilitasnya berdasarkan tabel probabilitas dan nilai data uji.
-
Perhitungan Label no (0.2857)
OUTLOOK(rainy) = 0.25
TEMPERATURE(hot) = 0.5
HUMIDITY(high) = 1
WINDY(true) = 0.5
Nilai no = 0.2857 * 0.25 * 0.5 * 1 * 0.5 = 0.0179
-
Perhitungan Label yes (0.7143)
OUTLOOK(rainy) = 0.4
TEMPERATURE(hot) = 0.2
HUMIDITY(high) = 0.4
WINDY(true) = 0.4
Nilai yes = 0.7143 * 0.4 * 0.2 * 0.4 * 0.4 = 0.0091
Berdasarkan perhitungan label yang paling tinggi adalah no dengan nilai 0.0179. Sehingga hasil klasifikasi untuk data uji adalah no.
Source Code Algoritma Naïve Bayes
Berikut adalah beberapa source-code yang menggunakan metode Naive Bayes baik berbasis web maupun desktop.
- Source Code Text Mining Metode Naive Bayes Classifier PHP
- Source Code Sistem Pakar Metode Naive Bayes Classifier VB
- Source Code Naive Bayes Classifier PHP
- Source Code Naive Bayes Classifier Codeigniter
- Source Code Sistem Pakar Metode NBC VB.Net
- Source Code Data Mining Metode NBC Laravel
- Source Code SPK Metode NBC SAW PHP
- Source Code Data Mining Metode C45 dan NBC PHP
- Source Code Apriori NBC PHP
- Source Code Klasifikasi Metode SVM NBC PHP
- Source Code Text Mining Klasifikasi Metode KNN NBC PHP
- Source Code Chi Square NBC PHP
- Source Code Naive Bayes Classifier VB.Net
- Source Code Sistem Pakar Metode Naive Bayes Certainty Factor PHP
- Source Code Data Mining Klasifikasi metode NBC SVM PHP