contoh perhitungan data mining (c4.5 dan naive bayer)

Upload: ecko-anto

Post on 13-Jan-2016

258 views

Category:

Documents


4 download

DESCRIPTION

Contoh perhitungan Data Mining (C4.5 dan Naive Bayer)

TRANSCRIPT

  • Algoritma C4.5 dan Nave Bayes

    Tugas

    SPK dan BI

    (Lizda Iswari, M.Sc.)

    di susun oleh :

    EKO YUNIANTO

    NIM. 14917208

    PROGRAM PASCASARJANA MAGISTER INFORMATIKA

    FAKULTAS TEKNOLOGI INDUSTRI

    UNIVERSITAS ISLAM INDONESIA

    YOGYAKARTA

    2015

  • Magister Teknik Informatika Fakultas Teknologi Industri Universitas Islam Indonesia

    LEMBAR TUGAS DATA MINING Algoritma C4.5 dan Nave Bayes

    Materi : Data MiningMatakuliah : Sistem Pendukung KeputusanDosen : Lizda Iswari, M.Sc.

    Nama Mahasiswa : Eko YuniantoNIM : 14917208

    Diketahui sepuluh data tentang rekomendasi jenis lensa untuk kacamata sebagai berikut:

    Tabel 1. Data Klasifikasi Jenis Lensa

    Tugas 1: Buatlah model pohon keputusan berdasarkan 10 data latih seperti di Tabel 1 menggunakan algoritma C4.5. Sertakan pembagian klasifikasi dalam bentuk tabel untuk setiap level dan visualisasi bentuk pohonnya.

    Tugas 2: Tentukan klasifikasi data berikut menggunakan algoritma Naive Bayes: Jenis Mata: Pre-presbyopic Jenis Kacamata: Hypermetrope Astigmatisme: Tidak Jenis Airmata: Reduced

    Sertakan komputasi klasifikasi tanpa Laplacian Correction dan menggunakan Laplacian Correction!

    Tabel 1. Data Klasifikasi Jenis Lensa

    Jenis Mata Jenis Kacamata Astigmatisme Jenis Airmata Rekomendasi Lensa

    Muda Myope Ya Reduced None Muda Myope Tidak Normal Soft Muda Hypermetrope Ya Reduced None Pre-presbyopic Myope Tidak Reduced None Pre-presbyopic Myope Tidak Normal Soft Pre-presbyopic Hypermetrope Ya Reduced None Presbyopic Myope Ya Reduced None Presbyopic Myope Tidak Normal None Presbyopic Hypermetrope Tidak Normal Soft Presbyopic Hypermetrope Ya Normal Soft

  • Jawab

    Tugas 1

    1. Menghitung jumlah data untuk setiap klasifikasi.

    2. Mentukan atribut akar pohon.1. Hitung Entropy Level 1

    1. Entropy(Total) = ( - 610

    * log2(6

    10)) + ( - 4

    10* log2(

    410

    )) = 0.971

    2. Entropy(JenisMata, Muda) = ( - 23

    * log2(23

    )) + ( - 13

    * log2(13

    )) = 0.918

    3. Entropy(JenisMata, Pre-Presbyopic) = ( - 23

    * log2(23

    )) + ( - 13

    * log2(13

    )) =

    0.918

    4. Entropy(JenisMata, Presbyopic) = ( - 24

    * log2(24

    )) + ( - 24

    * log2(24

    )) = 1

    5. Entropy(JenisKacaMata, Myope) = ( - 46

    * log2(46

    )) + ( - 26

    * log2(26

    )) =

    0.918

    6. Entropy(JenisKacaMata, Hypermetrope) = ( - 24

    * log2(24

    )) + ( - 24

    * log2(24

    )) = 1

    7. Entropy(Astigmatisme, Ya) = ( - 45

    * log2(45

    )) + ( - 15

    * log2(15

    )) = 0.722

    8. Entropy(Astigmatisme, Tidak) = ( - 25

    * log2(25

    )) + ( - 35

    * log2(35

    )) = 0.971

    9. Entropy(JenisAirmata, Reduced) = ( - 55

    * log2(55

    )) + ( - 05

    * log2(05

    )) = 0

    10. Entropy(JenisAirmata, Normal) = ( - 15

    * log2(15

    )) + ( - 45

    * log2(45

    )) = 0.722

    Tabel 2. Tabel Pohon Level 1

    Level Atribut Partisi Entropy Gain

    1 Total 10 6 4Jenis Mata

    Muda 3 2 1Pre-presbyopic 3 2 1

    Presbyopic 4 2 2Jenis Kacamata

    Myope 6 4 2Hypermetrope 4 2 2

    Astigmatisme Ya 5 4 1

    Tidak 5 2 3Jenis Airmata

    Reduced 5 5 0Normal 5 1 4

    Jml Kasus (S)

    Kelas None (S1)

    Kelas Soft (S2)

  • 2. Hitung Gain Level 1

    1. Gain(Total, JenisMata) = 0.971 - (( 310

    * 0.918) + ( 310

    * 0.918) + ( 410

    * 1)) =

    0.020

    2. Gain(Total, JenisKacamata) = 0.971 - (( 610

    * 0.918) + ( 410

    * 1)) = 0.020

    3. Gain(Total, Astigmatisme) = 0.971 - (( 510

    * 0.722) + ( 510

    * 0.971)) = 0.125

    4. Gain(Total, JenisAirmata) = 0.971 - (( 510

    * 0) + ( 510

    * 0.722)) = 0.610

    Sesuai dengan Tabel 3 dapat diambil atribut akar yaitu Jenis Airmata karena mempunyai Gain tertinggi dari atribut-atribut yang ada. Sedangkan nilai Entropy(JenisAirmata, Reduced) bernilai 0, maka sudah menemukan titik akhir.

    3. Bentuk Pohon Level 1

    Tabel 3. Tabel Pohon dengan perhitungan Entropy dan Gain (Level 1)

    Atribut Partisi Entropy Gain

    Total 10 6 4 0.971Jenis Mata 0.020

    Muda 3 2 1 0.918Pre-presbyopic 3 2 1 0.918

    Presbyopic 4 2 2 1.000Jenis Kacamata 0.020

    Myope 6 4 2 0.918Hypermetrope 4 2 2 1.000

    Astigmatisme 0.125Ya 5 4 1 0.722

    Tidak 5 2 3 0.971Jenis Airmata 0.610

    Reduced 5 5 0 0.000Normal 5 1 4 0.722

    Jml Kasus

    (S)

    Kelas None (S1)

    Kelas Soft (S2)

    Gambar 1. Pohon Level 1

    Jenis Airmata

    None ???

    Reduced Normal

  • 4. Menghitung jumlah data untuk setiap klasifikasi level 2

    5. Mentukan atribut akar pohon level 21. Hitung Entropy Level 2

    1. Entropy(JenisAirmata, Normal) = ( - 15

    * log2(15

    )) + ( - 45

    * log2(45

    )) = 0.722

    2. Entropy(JenisMata, Muda) = ( - 01

    * log2(01

    )) + ( - 11

    * log2(11

    )) = 0

    3. Entropy(JenisMata, Pre-Presbyopic) = ( - 01

    * log2(01

    )) + ( - 11

    * log2(11

    )) =

    0

    4. Entropy(JenisMata, Presbyopic) = ( - 13

    * log2(13

    )) + ( - 23

    * log2(23

    )) = 0.918

    5. Entropy(JenisKacaMata, Myope) = ( - 13

    * log2(13

    )) + ( - 23

    * log2(23

    )) =

    0.918

    6. Entropy(JenisKacaMata, Hypermetrope) = ( - 02

    * log2(02

    )) + ( - 22

    * log2(22

    ))

    = 0

    7. Entropy(Astigmatisme, Ya) = ( - 01

    * log2(01

    )) + ( - 11

    * log2(11

    )) = 0

    8. Entropy(Astigmatisme, Tidak) = ( - 14

    * log2(14

    )) + ( - 34

    * log2(34

    )) = 0.811

    2. Hitung Gain Level 2

    1. Gain(JenisAirmata-Normal, JenisMata) = 0.722 - (( 15

    * 0) + ( 15

    * 0) + ( 35

    *

    0.918)) = 0.171

    2. Gain(JenisAirmata-Normal, JenisKacamata) = 0.722 - (( 35

    * 0.918) + ( 25

    * 0)) =

    0.171

    3. Gain(JenisAirmata-Normal, Astigmatisme) = 0.722 - (( 15

    * 0) + ( 45

    * 0.811)) =

    0.073

    Tabel 4. Tabel Pohon Level 2

    Level Atribut Partisi Entropy Gain

    2 Jenis Airmata Normal 5 1 4Jenis Mata

    Muda 1 0 1Pre-presbyopic 1 0 1

    Presbyopic 3 1 2Jenis Kacamata

    Myope 3 1 2Hypermetrope 2 0 2

    Astigmatisme

    Jml Kasus (S)

    Kelas None (S1)

    Kelas Soft (S2)

  • Sesuai dengan Tabel 5 dapat diambil atribut akar yaitu Jenis Mata karena mempunyai Gain tertinggi dari atribut-atribut yang ada bersama dengan Jenis Kacamata. Sedangkan nilai Entropy(JenisMata, Muda),Entropy(JenisMata, Pre-Presbyopic) bernilai 0, maka sudah menemukan titik akhir.

    6. Bentuk Pohon Level 2

    7. Menghitung jumlah data untuk setiap klasifikasi level 3

    Tabel 5. Tabel Pohon dengan perhitungan Entropy dan Gain (Level 2)

    Level Atribut Partisi Entropy Gain

    2 Jenis Airmata Normal 5 1 4 0.722Jenis Mata 0.171

    Muda 1 0 1 0.000Pre-presbyopic 1 0 1 0.000

    Presbyopic 3 1 2 0.918Jenis Kacamata 0.171

    Myope 3 1 2 0.918Hypermetrope 2 0 2 0.000

    Astigmatisme 0.073Ya 1 0 1 0.000

    Tidak 4 1 3 0.811

    Jml Kasus

    (S)

    Kelas None (S1)

    Kelas Soft (S2)

    Gambar 2. Pohon Level 2

    Jenis Airmata

    None Jenis Mata

    Reduced Normal

    Soft ???

    Muda Pre-Presbyopic

    Soft

    Tabel 6. Tabel Pohon Level 3

    Level Atribut Partisi Entropy Gain

    3 Jenis Mata Presbyopic 3 1 2Jenis Kacamata

    Myope 1 1 0Hypermetrope 2 0 2

    Astigmatisme Ya 1 0 1

    Tidak 2 1 1

    Jml Kasus (S)

    Kelas None (S1)

    Kelas Soft (S2)

  • 8. Mentukan atribut akar pohon level 31. Hitung Entropy Level 3

    1. Entropy(JenisMata, Presbyopic) = ( - 13

    * log2(13

    )) + ( - 23

    * log2(23

    )) = 0.918

    2. Entropy(JenisKacaMata, Myope) = ( - 11

    * log2(11

    )) + ( - 01

    * log2(01

    )) = 0

    3. Entropy(JenisKacaMata, Hypermetrope) = ( - 02

    * log2(02

    )) + ( - 22

    * log2(22

    ))

    = 0

    4. Entropy(Astigmatisme, Ya) = ( - 01

    * log2(01

    )) + ( - 11

    * log2(11

    )) = 0

    5. Entropy(Astigmatisme, Tidak) = ( - 12

    * log2(12

    )) + ( - 12

    * log2(12

    )) = 1

    2. Hitung Gain Level 3

    1. Gain(JenisAirmata-Normal-JenisMata-Presbyopic, JenisKacamata) = 0.918 - (( 13

    * 0)

    + ( 23

    * 0) = 0.171

    2. Gain(JenisAirmata-Normal-JenisMata-Presbyopic, Astigmatisme) = 0.918 - (( 13

    * 0)

    + ( 23

    * 1)) = 0.252

    Tabel 7. Tabel Pohon Level 3

    Level Atribut Partisi Entropy Gain

    3 Jenis Mata Presbyopic 3 1 2Jenis Kacamata

    Myope 1 1 0Hypermetrope 2 0 2

    Astigmatisme Ya 1 0 1

    Tidak 2 1 1

    Jml Kasus (S)

    Kelas None (S1)

    Kelas Soft (S2)

    Tabel 8. Tabel Pohon dengan perhitungan Entropy dan Gain (Level 3)

    Level Atribut Partisi Entropy Gain

    2 Jenis Mata Presbyopic 3 1 2 0.918Jenis Kacamata 0.918

    Myope 1 1 0 0.000Hypermetrope 2 0 2 0.000

    Astigmatisme 0.252Ya 1 0 1 0.000

    Tidak 2 1 1 1.000

    Jml Kasus

    (S)

    Kelas None (S1)

    Kelas Soft (S2)

  • Sesuai dengan Tabel 8 dapat diambil atribut akar yaitu Jenis Kacamata karena mempunyai Gain tertinggi dari atribut-atribut yang ada. Sedangkan nilai Entropy(JenisKacaMata, Myope), Entropy(JenisKacamata, Pre-Hypermetrope) bernilai 0, maka sudah menemukan titik akhir.

    9. Bentuk Pohon Level 3

    Karena selesai maka Gambar 3 merupakan Pohon Keputusan yang didapatkan dengan menggunakan algoritma C4.5

    Gambar 3. Pohon Level 3

    Jenis Airmata

    None Jenis Mata

    Reduced Normal

    Soft Jenis Kacamata

    Muda Pre-Presbyopic

    Soft

    None

    Myope

    Soft

    Hypermetrope

  • Jawab

    Tugas 2

    Menentukan klasifikasi data berikut menggunakan algoritma Naive Bayes: Jenis Mata: Pre-presbyopic Jenis Kacamata: Hypermetrope Astigmatisme: Tidak Jenis Airmata: Reduced

    Hasil Perhitungan dengan algoritma Naive Bayes1. Tanpa Laplacian Correction

    Menentukan himpunan atribut X dan nilai kelas Y Himpunan atribut X = {Jenis Mata, Jenis Kacamata, Astigmatisme, Jenis Airmata} Nilai Kelas Y = Rekomendasi Lensa

    Membuat Tabel hubungan setiap atribut dengan kelas

    Menghitung Probabilitas P1 = P(None | JenisMata=Pre-presbyopic, JenisKacamata=Hypermetrope,

    Astigmatisme=Tidak, Jenis Airmata=Reduced)= P(None) * P(JenisMata=Pre-presbyopic | None) * P(JenisKacamata=Hypermetrope | None) * P( Astigmatisme=Tidak | None) * P( Jenis Airmata=Reduced | None)

    P2 = P(Soft | JenisMata=Pre-presbyopic, JenisKacamata=Hypermetrope, Astigmatisme=Tidak, Jenis Airmata=Reduced)= P(Soft) * P(JenisMata=Pre-presbyopic | Soft) * P(JenisKacamata=Hypermetrope | Soft) * P( Astigmatisme=Tidak | Soft) * P( Jenis Airmata=Reduced | Soft)

    Membandingkan P1 dan P2.

    Tabel 9. Tabel Hubungan

    Level Atribut Partisi

    1 Total 10 6 4Jenis Mata

    Muda 3 2 1Pre-presbyopic 3 2 1

    Presbyopic 4 2 2Jenis Kacamata

    Myope 6 4 2Hypermetrope 4 2 2

    Astigmatisme Ya 5 4 1

    Tidak 5 2 3Jenis Airmata

    Reduced 5 5 0Normal 5 1 4

    Jml Kasus

    (S)

    Kelas None (S1)

    Kelas Soft (S2)

  • IFP1>P2 Rekomendasi Lensa None

    ELSERekomendasi Lensa Soft

    Perhitungan Naive Bayes P1

    P(None) = Jumlah Rekomendasi Lensa None / Jumlah keseluruhan data = 6/10 = 0.6

    P(JenisMata=Pre-presbyopic | None) = Jumlah Jenis Mata Pre-Presbyopic dan Rekomendasi Lensa None / Jumlah Rekomendasi Lensa None = 2/6 = 0.33

    P(JenisKacamata=Hypermetrope | None) = Jumlah Jenis Kacamata Hypermetrope dan Rekomendasi Lensa None / Jumlah Rekomendasi Lensa None

    = 2/6 = 0.33 P( Astigmatisme=Tidak | None) = Jumlah Astigmatisme Tidak dan Rekomendasi Lensa

    None / Jumlah Rekomendasi Lensa None= 2/6 = 0.33

    P( Jenis Airmata=Reduced | None) = Jumlah Jenis Airmata Reduced dan Rekomendasi Lensa None / Jumlah Rekomendasi Lensa None

    = 5/6 = 0.83 P2

    P(Soft) = Jumlah Rekomendasi Lensa Soft / Jumlah keseluruhan data = 4/10 = 0.4

    P(JenisMata=Pre-presbyopic | Soft) = Jumlah Jenis Mata Pre-Presbyopic dan Rekomendasi Lensa None / Jumlah Rekomendasi Lensa Soft

    = = 0.25 P(JenisKacamata=Hypermetrope | Soft) = Jumlah Jenis Kacamata Hypermetrope dan

    Rekomendasi Lensa None / Jumlah Rekomendasi Lensa Soft= 2/4 = 0.5

    P( Astigmatisme=Tidak | Soft) = Jumlah Astigmatisme Tidak dan Rekomendasi Lensa None / Jumlah Rekomendasi Lensa None

    = = 0.75 P( Jenis Airmata=Reduced | Soft) = Jumlah Jenis Airmata Reduced dan Rekomendasi

    Lensa None / Jumlah Rekomendasi Lensa None = 0/4 = 0

  • Membandingkan nilai P1 dan P2 P1 = P(None | JenisMata=Pre-presbyopic, JenisKacamata=Hypermetrope,

    Astigmatisme=Tidak, Jenis Airmata=Reduced)= 0.6 * 0.33 * 0.33 * 0.33 * 0.83 = 0.018

    P2 = P(Soft | JenisMata=Pre-presbyopic, JenisKacamata=Hypermetrope, Astigmatisme=Tidak, Jenis Airmata=Reduced)= 0.4 * 0.25 * 0.5 * 0.75 * 0 = 0

    Kesimpulan : P1 > P2 Rekomendasi Lensa None2. Dengan Laplacian Correction

    Perhitungan Naive Bayes P1

    P(None) = Jumlah Rekomendasi Lensa None+1 / Jumlah keseluruhan data+2 = (6+1)/(10+2) = 7/12 = 0.58

    P(JenisMata=Pre-presbyopic | None) = Jumlah Jenis Mata Pre-Presbyopic dan Rekomendasi Lensa None+1 / Jumlah Rekomendasi Lensa None+3 = (2+1)/(6+3) = 3/9 = 0.33

    P(JenisKacamata=Hypermetrope | None) = Jumlah Jenis Kacamata Hypermetrope dan Rekomendasi Lensa None+1 / Jumlah Rekomendasi Lensa None+2

    = (2+1)/(6+2) = 3/8 = 0.375 P( Astigmatisme=Tidak | None) = Jumlah Astigmatisme Tidak dan Rekomendasi Lensa

    None+1 / Jumlah Rekomendasi Lensa None+2= (2+1)/(6+2) = 3/8 = 0.375

    P( Jenis Airmata=Reduced | None) = Jumlah Jenis Airmata Reduced dan Rekomendasi Lensa None+1 / Jumlah Rekomendasi Lensa None+2

    = (5+1)/(6+2) = 6/8 = 0.75 P2

    P(Soft) = Jumlah Rekomendasi Lensa Soft+1 / Jumlah keseluruhan data+2 = (4+1)/(10+1) = 5/12 = 0.417

    P(JenisMata=Pre-presbyopic | Soft) = Jumlah Jenis Mata Pre-Presbyopic dan Rekomendasi Lensa None+1 / Jumlah Rekomendasi Lensa Soft+3

    = (1+1)/(4+3) = 2/7 = 0.286 P(JenisKacamata=Hypermetrope | Soft) = Jumlah Jenis Kacamata Hypermetrope dan

    Rekomendasi Lensa None+1 / Jumlah Rekomendasi Lensa Soft+2= (2+1)/(4+2) = 3/6 = 0.5

    P( Astigmatisme=Tidak | Soft) = Jumlah Astigmatisme Tidak dan Rekomendasi Lensa None+1 / Jumlah Rekomendasi Lensa None+2 = (3+1)/(4+2) = 4/6 = 0.67

  • P( Jenis Airmata=Reduced | Soft) = Jumlah Jenis Airmata Reduced dan Rekomendasi Lensa None+1 / Jumlah Rekomendasi Lensa None+2

    = (0+1)/(4+2) = 1/6 = 0.167 Membandingkan nilai P1 dan P2

    P1 = P(None | JenisMata=Pre-presbyopic, JenisKacamata=Hypermetrope, Astigmatisme=Tidak, Jenis Airmata=Reduced)= 0.58 * 0.33 * 0.375 * 0.375 * 0.75 = 0.02

    P2 = P(Soft | JenisMata=Pre-presbyopic, JenisKacamata=Hypermetrope, Astigmatisme=Tidak, Jenis Airmata=Reduced)= 0.417 * 0.286 * 0.5 * 0.67 * 0.167 = 0.006

    Kesimpulan : P1 > P2 Rekomendasi Lensa None

    Dari kedua perhitungan menggunakan Naive Bayes dengan dan tanpa Laplacian Correction sama-sama menghasilkan Rekomendasi Lensa None, pada klasifikasi yang sudah di tentukan. Hanya saja dengan menggunakan Laplacian Correction akan terhindar dari nilai 0.