Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Machine Learning_Klasifikasi_Dwina_DT_2021.pptx

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Wird geladen in …3
×

Hier ansehen

1 von 51 Anzeige

Weitere Verwandte Inhalte

Aktuellste (20)

Anzeige

Machine Learning_Klasifikasi_Dwina_DT_2021.pptx

  1. 1. Machine Learning : Klasifikasi Dr.Dra.Dwina Kuswardani M.Kom 28 September 2021
  2. 2. Machine Learning 1 Apa itu Machine Learning 2 Tipe Machine learning 2
  3. 3. Apa itu Machine Learning(Pembelajaran Mesin)  Pembelajaran mesin adalah cabang dari kecerdasan buatan (AI) yang berfokus pada membangun aplikasi yang belajar dari data dan meningkatkan keakuratannya dari waktu ke waktu tanpa diprogram untuk melakukannya.  Contoh. pembelajaran mesin ada di sekitar kita.  Asisten digital mencari web dan memutar musik sebagai respons atas perintah suara kami.  Situs web merekomendasikan produk dan film serta lagu berdasarkan apa yang kita beli, tonton, atau dengarkan sebelumnya.  Robot menyedot lantai  Pendeteksi spam menghentikan email yang tidak diinginkan masuk ke kotak masuk kami.  Sistem analisis citra medis membantu dokter menemukan tumor yang mungkin mereka lewatkan.  mobil self-driving pertama mulai meluncur.
  4. 4. Tipe Machine Learning  Supervised Learning Algoritma ini membangkitkan suatu fungsi yang memetakan input ke output yang diinginkan. Kualitas hasil pembelajaran bergantung pada kesesuaian input dan output yang diberikan.  Unsupervised Learning Algoritma ini memodelkan sekumpulan input secara otomatis tanpa ada panduan (yang berupa output yang diinginkan).  Semi-supervised Learning Algoritma ini mengkombinasikan kedua algoritma di atas, di mana sampel-sampel input yang diberikan ada yang berlabel dan ada yang tidak berlabel  Reinforcement Learning Algoritma ini mempelajari suatu kebijakan bagaimana melakukan aksi berdasarkan hasil pengamatan terhadap lingkungan yang ada.  Transduction Mirip dengan supervised learning, tetapi tidak secara eksplisit membangun suatu fungsi. Algoritma ini justru berlatih memprediksi output baru berdasarkan training inputs, training ouputs, dan testing inputs yang tersedia selama proses pembelajaran (training).  Learning to learn Algoritma ini mempelajari bias induktifnya sendiri berdasarkan pengalaman-pengalaman sebelumnya.
  5. 5. Klasifikasi 1. Apa yang disebut Klasifikasi 2. Bagaimana proses Klasifikasi 3. Metode Klasifikasi 6
  6. 6. Apa itu Klasifikasi ? Seandainya ada data/record baru yang tidak diketahui nilai atribut kelasnya , misal refund, Married , 110 K Tid Refund Marital Status Taxable Income Cheat 1 Yes Single 125K No 2 No Married 100K No 3 No Single 70K No 4 Yes Married 120K No 5 No Divorced 95K Yes 6 No Married 60K No 7 Yes Divorced 220K No 8 No Single 85K Yes 9 No Married 75K No 10 No Single 90K Yes 10 Ada sekumpulan data/record yang terdiri dari sekumpulan atribut dimana salah satunya atribut kelas Bagaimana caranya agar record tersebut masuk kedalam klas (Yes atau No?
  7. 7. Definisi  Suatu pekerjaan menilai objek data untuk memasukkannya ke dalam kelas tertentu dari sejumlah kelas yang tersedia Atau  Klasifikasi dapat didefinisikan sebagai pekerjaan yang melakukan pelatihan/pembelajaran terhadap fungsi target f yang memetakan setiap set atribut (fitur) x ke satu dari sejumlah label kelas y yang tersedia.  Fungsi target f juga dikenal sebagai model klasifikasi
  8. 8. Pembangunan model sebagai prototipe untuk disimpan sebagai memori Penggunaan model tersebut untuk melakukan pengenalan / klasifikasi / prediksi pada suatu objek data lain agar diketahui di kelas mana objek data tersebut dalam model yang sudah disimpannya. Dalam klasifikasi ada dua pekerjaan utama yang dilakukan
  9. 9. Ilustrasi Proses Klasifikasi Apply Model Induction Deduction Learn Model Model Tid Attrib1 Attrib2 Attrib3 Class 1 Yes Large 125K No 2 No Medium 100K No 3 No Small 70K No 4 Yes Medium 120K No 5 No Large 95K Yes 6 No Medium 60K No 7 Yes Large 220K No 8 No Small 85K Yes 9 No Medium 75K No 10 No Small 90K Yes 10 Tid Attrib1 Attrib2 Attrib3 Class 11 No Small 55K ? 12 Yes Medium 80K ? 13 Yes Large 110K ? 14 No Small 95K ? 15 No Large 67K ? 10 Test Set Learning algorithm Training Set
  10. 10. Set Data Vertebrate Fitur apa yang menetapkan sebuah hewan sebgai mammal, reptile, bird, fish atau amphibian Record yang tidak diketahui kelasnya
  11. 11. Metode Klasifikasi Pohon Keputusan (Decision Tree ) 12
  12. 12. Pohon Keputusan (Decision Tree) 13
  13. 13. Decision Tree Induction  Decision tree untuk masalah penetapan jenis hewan :  Root node, tidak memiliki edge yang masuk dan memiliki nol atau lebih edge yang keluar  Internal nodes, setiap node memiliki tepat satu edge yang masuk dan dua atau lebih edge yang keluar  Leaf or terminal nodes, setiap node memiliki tepat satu edge yang masuk dan tidak ada edge yang keluar Sebuah kondisi uji (Blood type?) untuk memisahkan hewan warm-blooded dari hewan cold-blooded
  14. 14. Contoh dari Decion Tree Tid Refund Marital Status Taxable Income Cheat 1 Yes Single 125K No 2 No Married 100K No 3 No Single 70K No 4 Yes Married 120K No 5 No Divorced 95K Yes 6 No Married 60K No 7 Yes Divorced 220K No 8 No Single 85K Yes 9 No Married 75K No 10 No Single 90K Yes 10 Refund MarSt TaxInc YES NO NO NO Yes No Married Single, Divorced < 80K > 80K Splitting Attributes Training Data Model: Decision Tree
  15. 15. Contoh lain dari Decision Tree Tid Refund Marital Status Taxable Income Cheat 1 Yes Single 125K No 2 No Married 100K No 3 No Single 70K No 4 Yes Married 120K No 5 No Divorced 95K Yes 6 No Married 60K No 7 Yes Divorced 220K No 8 No Single 85K Yes 9 No Married 75K No 10 No Single 90K Yes 10 MarSt Refund TaxInc YES NO NO NO Yes No Married Single, Divorced < 80K > 80K Dapat diperoleh lebih dari satu decision tree dari sebuah data
  16. 16. Proses Klasifikasi Decision tree Apply Model Induction Deduction Learn Model Model Tid Attrib1 Attrib2 Attrib3 Class 1 Yes Large 125K No 2 No Medium 100K No 3 No Small 70K No 4 Yes Medium 120K No 5 No Large 95K Yes 6 No Medium 60K No 7 Yes Large 220K No 8 No Small 85K Yes 9 No Medium 75K No 10 No Small 90K Yes 10 Tid Attrib1 Attrib2 Attrib3 Class 11 No Small 55K ? 12 Yes Medium 80K ? 13 Yes Large 110K ? 14 No Small 95K ? 15 No Large 67K ? 10 Test Set Tree Induction algorithm Training Set Decision Tree
  17. 17. Ilustrasi Model diaplikasikan pada data uji Refund MarSt TaxInc YES NO NO NO Yes No Married Single, Divorced < 80K > 80K Refund Marital Status Taxable Income Cheat No Married 80K ? 10 Data Uji Mulai dari root node
  18. 18. Ilustrasi Model diaplikasikan pada data uji Refund MarSt TaxInc YES NO NO NO Yes No Married Single, Divorced < 80K > 80K Refund Marital Status Taxable Income Cheat No Married 80K ? 10 Data Uji
  19. 19. Ilustrasi Model diaplikasikan pada data uji Refund MarSt TaxInc YES NO NO NO Yes No Married Single, Divorced < 80K > 80K Refund Marital Status Taxable Income Cheat No Married 80K ? 10 Data Uji
  20. 20. Ilustrasi Model diaplikasikan pada data uji Refund MarSt TaxInc YES NO NO NO Yes No Married Single, Divorced < 80K > 80K Refund Marital Status Taxable Income Cheat No Married 80K ? 10 Data Uji
  21. 21. Ilustrasi Model diaplikasikan pada data uji Refund MarSt TaxInc YES NO NO NO Yes No Married Single, Divorced < 80K > 80K Refund Marital Status Taxable Income Cheat No Married 80K ? 10 Data Uji
  22. 22. Ilustrasi Model diaplikasikan pada data uji Refund MarSt TaxInc YES NO NO NO Yes No Married Single, Divorced < 80K > 80K Refund Marital Status Taxable Income Cheat No Married 80K ? 10 Data Uji Ditetapkan ke kelas “No”
  23. 23. Decision Tree Induction  Contoh Algoritma Decision Tree :  ID3, C4.5  CART  SLIQ,SPRINT
  24. 24. Tahapan Algoritma Decision Tree 1. Siapkan data training 2. Pilih atribut sebagai akar 3. Buat cabang untuk tiap-tiap nilai 4. Ulangi proses untuk setiap cabang sampai semua kasus pada cabang memiliki kelas yg sama 25     n i pi pi S Entropy 1 2 log * ) ( ) ( * | | | | ) ( ) , ( 1 i n i i S Entropy S S S Entropy A S Gain    
  25. 25. 1. Siapkan data training 26
  26. 26. 2. Pilih atribut sebagai akar  Untuk memilih atribut akar, didasarkan pada nilai Gain tertinggi dari atribut-atribut yang ada. Untuk mendapatkan nilai Gain, harus ditentukan terlebih dahulu nilai Entropy  Rumus Entropy:  S = Himpunan Kasus  n = Jumlah Partisi S  pi = Proporsi dari Si terhadap S  Rumus Gain:  S = Himpunan Kasus  A = Atribut  n = Jumlah Partisi Atribut A  | Si | = Jumlah Kasus pada partisi ke-i  | S | = Jumlah Kasus dalam S 27     n i pi pi S Entropy 1 2 log * ) ( ) ( * | | | | ) ( ) , ( 1 i n i i S Entropy S S S Entropy A S Gain    
  27. 27. Perhitungan Entropy dan Gain Akar 28
  28. 28. Penghitungan Entropy Akar  Entropy Total  Entropy (Outlook)  Entropy (Temperature)  Entropy (Humidity)  Entropy (Windy) 29
  29. 29. Penghitungan Entropy Akar 30 NODE ATRIBUT JML KASUS (S) YA (Si) TIDAK (Si) ENTROP Y GAIN 1 TOTAL 14 10 4 0,86312 OUTLOOK CLOUDY 4 4 0 0 RAINY 5 4 1 0,72193 SUNNY 5 2 3 0,97095 TEMPERATURE COOL 4 0 4 0 HOT 4 2 2 1 MILD 6 2 4 0,91830 HUMADITY HIGH 7 4 3 0,98523 NORMAL 7 7 0 0 WINDY FALSE 8 2 6 0,81128 TRUE 6 4 2 0,91830
  30. 30. Penghitungan Gain Akar 31
  31. 31. Penghitungan Gain Akar 32 NODE ATRIBUT JML KASUS (S) YA (Si) TIDAK (Si) ENTROPY GAIN 1 TOTAL 14 10 4 0,86312 OUTLOOK 0,25852 CLOUDY 4 4 0 0 RAINY 5 4 1 0,72193 SUNNY 5 2 3 0,97095 TEMPERATURE 0,18385 COOL 4 0 4 0 HOT 4 2 2 1 MILD 6 2 4 0,91830 HUMADITY 0,37051 HIGH 7 4 3 0,98523 NORMAL 7 7 0 0 WINDY 0,00598 FALSE 8 2 6 0,81128 TRUE 6 4 2 0,91830
  32. 32. Gain Tertinggi Sebagai Akar  Dari hasil pada Node 1, dapat diketahui bahwa atribut dengan Gain tertinggi adalah HUMIDITY yaitu sebesar 0.37051  Dengan demikian HUMIDITY dapat menjadi node akar  Ada 2 nilai atribut dari HUMIDITY yaitu HIGH dan NORMAL. Dari kedua nilai atribut tersebut, nilai atribut NORMAL sudah mengklasifikasikan kasus menjadi 1 yaitu keputusan-nya Yes, sehingga tidak perlu dilakukan perhitungan lebih lanjut  Tetapi untuk nilai atribut HIGH masih perlu dilakukan perhitungan lagi 33 1. HUMIDIT Y 1.1 ????? Yes High Normal
  33. 33. 2. Buat cabang untuk tiap-tiap nilai  Untuk memudahkan, dataset di filter dengan mengambil data yang memiliki kelembaban HUMADITY=HIGH untuk membuat table Node 1.1 34 OUTLOOK TEMPERATUR E HUMIDITY WINDY PLAY Sunny Hot High FALSE No Sunny Hot High TRUE No Cloudy Hot High FALSE Yes Rainy Mild High FALSE Yes Sunny Mild High FALSE No Cloudy Mild High TRUE Yes Rainy Mild High TRUE No
  34. 34. Perhitungan Entropi Dan Gain Cabang 35 NODE ATRIBUT JML KASUS (S) YA (Si) TIDAK (Si) ENTROPY GAIN 1.1 HUMADITY 7 3 4 0,98523 OUTLOOK 0,69951 CLOUDY 2 2 0 0 RAINY 2 1 1 1 SUNNY 3 0 3 0 TEMPERATURE 0,02024 COOL 0 0 0 0 HOT 3 1 2 0,91830 MILD 4 2 2 1 WINDY 0,02024 FALSE 4 2 2 1 TRUE 3 1 2 0,91830
  35. 35. Gain Tertinggi Sebagai Node 1.1  Dari hasil pada Tabel Node 1.1, dapat diketahui bahwa atribut dengan Gain tertinggi adalah OUTLOOK yaitu sebesar 0.69951  Dengan demikian OUTLOOK dapat menjadi node kedua  Artibut CLOUDY = YES dan SUNNY= NO sudah mengklasifikasikan kasus menjadi 1 keputusan, sehingga tidak perlu dilakukan perhitungan lebih lanjut  Tetapi untuk nilai atribut RAINY masih perlu dilakukan perhitungan lagi 36 1. HUMIDIT Y 1.1 OUTLOO K Yes High Normal Yes No 1.1.2 ????? Cloudy Rainy Sunny
  36. 36. 3. Ulangi proses untuk setiap cabang sampai semua kasus pada cabang memiliki kelas yg sama 37 OUTLOOK TEMPERATURE HUMIDITY WINDY PLAY Rainy Mild High FALSE Yes Rainy Mild High TRUE No NODE ATRIBUT JML KASUS (S) YA (Si) TIDAK (Si) ENTROP Y GAIN 1.2 HUMADITY HIGH & OUTLOOK RAINY 2 1 1 1 TEMPERATURE 0 COOL 0 0 0 0 HOT 0 0 0 0 MILD 2 1 1 1 WINDY 1 FALSE 1 1 0 0 TRUE 1 0 1 0
  37. 37. Gain Tertinggi Sebagai Node 1.1.2  Dari tabel, Gain Tertinggi adalah WINDY dan menjadi node cabang dari atribut RAINY  Karena semua kasus sudah masuk dalam kelas  Jadi, pohon keputusan pada Gambar merupakan pohon keputusan terakhir yang terbentuk 38 1. HUMIDIT Y 1.1 OUTLOO K Yes High Normal Yes No 1.1.2 WINDY Cloudy Rainy Sunny Yes No False True
  38. 38. Decision Tree Induction: An Example  Training data set: Buys_computer 39 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 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
  39. 39. Gain Ratio for Attribute Selection (C4.5)  Information gain measure is biased towards attributes with a large number of values  C4.5 (a successor of ID3) uses gain ratio to overcome the problem (normalization to information gain)  GainRatio(A) = Gain(A)/SplitInfo(A)  Ex.  gain_ratio(income) = 0.029/1.557 = 0.019  The attribute with the maximum gain ratio is selected as the splitting attribute 40 ) | | | | ( log | | | | ) ( 2 1 D D D D D SplitInfo j v j j A     
  40. 40. Gini Index (CART)  If a data set D contains examples from n classes, gini index, gini(D) is defined as where pj is the relative frequency of class j in D  If a data set D is split on A into two subsets D1 and D2, the gini index gini(D) is defined as  Reduction in Impurity:  The attribute provides the smallest ginisplit(D) (or the largest reduction in impurity) is chosen to split the node (need to enumerate all the possible splitting points for each attribute) 41     n j p j D gini 1 2 1 ) ( ) ( | | | | ) ( | | | | ) ( 2 2 1 1 D gini D D D gini D D D giniA   ) ( ) ( ) ( D gini D gini A gini A   
  41. 41. Computation of Gini Index  Ex. D has 9 tuples in buys_computer = “yes” and 5 in “no”  Suppose the attribute income partitions D into 10 in D1: {low, medium} and 4 in D2 Gini{low,high} is 0.458; Gini{medium,high} is 0.450. Thus, split on the {low,medium} (and {high}) since it has the lowest Gini index  All attributes are assumed continuous-valued  May need other tools, e.g., clustering, to get the possible split values  Can be modified for categorical attributes 42 459 . 0 14 5 14 9 1 ) ( 2 2                 D gini ) ( 14 4 ) ( 14 10 ) ( 2 1 } , { D Gini D Gini D gini medium low income               
  42. 42. Comparing Attribute Selection Measures The three measures, in general, return good results but Information gain:  biased towards multivalued attributes Gain ratio:  tends to prefer unbalanced splits in which one partition is much smaller than the others Gini index:  biased to multivalued attributes  has difficulty when # of classes is large  tends to favor tests that result in equal-sized partitions and purity in both partitions 43
  43. 43. Why is decision tree induction popular?  Relatively faster learning speed (than other classification methods)  Convertible to simple and easy to understand classification rules  Can use SQL queries for accessing databases  Comparable classification accuracy with other methods 44
  44. 44. Model Evaluation and Selection 45
  45. 45. Model Evaluation and Selection  Evaluation metrics: How can we measure accuracy? Other metrics to consider?  Use validation test set of class-labeled tuples instead of training set when assessing accuracy  Methods for estimating a classifier’s accuracy:  Holdout method, random subsampling  Cross-validation  Bootstrap  Comparing classifiers:  Confidence intervals  Cost-benefit analysis and ROC Curves 46
  46. 46. Classifier Evaluation Metrics: Confusion Matrix  Given m classes, an entry, CMi,j in a confusion matrix indicates # of tuples in class i that were labeled by the classifier as class j  May have extra rows/columns to provide totals 47 Actual classPredicted class buy_computer = yes buy_computer = no Total buy_computer = yes 6954 46 7000 buy_computer = no 412 2588 3000 Total 7366 2634 10000 Actual classPredicted class C1 ¬ C1 C1 True Positives (TP) False Negatives (FN) ¬ C1 False Positives (FP) True Negatives (TN)
  47. 47. Classifier Evaluation Metrics: Accuracy, Error Rate, Sensitivity and Specificity  Classifier Accuracy or recognition rate: percentage of test set tuples that are correctly classified Accuracy = (TP + TN)/All  Error rate: 1 – accuracy, or Error rate = (FP + FN)/All Class Imbalance Problem:  One class may be rare, e.g. fraud, or HIV-positive  Significant majority of the negative class and minority of the positive class  Sensitivity: True Positive recognition rate  Sensitivity = TP/P  Specificity: True Negative recognition rate  Specificity = TN/N 48 A P C ¬C C TP FN P ¬C FP TN N P’ N’ All
  48. 48. Classifier Evaluation Metrics: Precision and Recall, and F-measures  Precision: exactness – what % of tuples that the classifier labeled as positive are actually positive  Recall: completeness – what % of positive tuples did the classifier label as positive?  Perfect score is 1.0  Inverse relationship between precision & recall  F measure (F1 or F-score): harmonic mean of precision and recall,  Fß: weighted measure of precision and recall  assigns ß times as much weight to recall as to precision 49
  49. 49. Classifier Evaluation Metrics: Example 50 Precision = 90/230 = 39.13% Recall = 90/300 = 30.00% Actual ClassPredicted class cancer = yes cancer = no Total Recognition(%) cancer = yes 90 210 300 30.00 (sensitivity cancer = no 140 9560 9700 98.56 (specificity) Total 230 9770 10000 96.40 (accuracy)
  50. 50. Evaluating Classifier Accuracy: Holdout & Cross-Validation Methods  Holdout method  Given data is randomly partitioned into two independent sets  Training set (e.g., 2/3) for model construction  Test set (e.g., 1/3) for accuracy estimation  Random sampling: a variation of holdout  Repeat holdout k times, accuracy = avg. of the accuracies obtained  Cross-validation (k-fold, where k = 10 is most popular)  Randomly partition the data into k mutually exclusive subsets, each approximately equal size  At i-th iteration, use Di as test set and others as training set  Leave-one-out: k folds where k = # of tuples, for small sized data  *Stratified cross-validation*: folds are stratified so that class dist. in each fold is approx. the same as that in the initial data 51

×