(700 Instances, 9 Attributes, 2 Classes)
Sumber: UCI Machine Learning Repository, yaitu: PIMA Indians Diabetes Dataset.
No preg plas pres Skin insu mass pedi age Class 1 6 148 72 35 0 33,6 0,627 50 tested_positive 2 1 85 66 29 0 26,6 0,351 31 tested_negative 3 8 183 64 0 0 23,3 0,672 32 tested_positive 4 1 89 66 23 94 28,1 0,167 21 tested_negative 5 0 137 40 35 168 43,1 2,288 33 tested_positive 6 5 116 74 0 0 25,6 0,201 30 tested_negative
7 3 78 50 32 88 31 0,248 26 tested_positive
8 10 115 0 0 0 35,3 0,134 29 tested_negative 9 2 197 70 45 543 30,5 0,158 53 tested_positive
10 8 125 96 0 0 0 0,232 54 tested_positive
11 4 110 92 0 0 37,6 0,191 30 tested_negative
12 10 168 74 0 0 38 0,537 34 tested_positive
13 10 139 80 0 0 27,1 1,441 57 tested_negative 14 1 189 60 23 846 30,1 0,398 59 tested_positive 15 5 166 72 19 175 25,8 0,587 51 tested_positive
16 7 100 0 0 0 30 0,484 32 tested_positive
17 0 118 84 47 230 45,8 0,551 31 tested_positive 18 7 107 74 0 0 29,6 0,254 31 tested_positive 19 1 103 30 38 83 43,3 0,183 33 tested_negative 20 1 115 70 30 96 34,6 0,529 32 tested_positive 21 3 126 88 41 235 39,3 0,704 27 tested_negative
22 8 99 84 0 0 35,4 0,388 50 tested_negative
23 7 196 90 0 0 39,8 0,451 41 tested_positive
24 9 119 80 35 0 29 0,263 29 tested_positive
671 6 165 68 26 168 33,6 0,631 49 tested_negative 672 1 99 58 10 0 25,4 0,551 21 tested_negative 673 10 68 106 23 49 35,5 0,285 47 tested_negative 674 3 123 100 35 240 57,3 0,88 22 tested_negative
675 8 91 82 0 0 35,6 0,587 68 tested_negative
676 6 195 70 0 0 30,9 0,328 31 tested_positive
677 9 156 86 0 0 24,8 0,23 53 tested_positive
678 0 93 60 0 0 35,3 0,263 25 tested_negative
679 3 121 52 0 0 36 0,127 25 tested_positive
680 2 101 58 17 265 24,2 0,614 23 tested_negative 681 2 56 56 28 45 24,2 0,332 22 tested_negative 682 0 162 76 36 0 49,6 0,364 26 tested_positive 683 0 95 64 39 105 44,6 0,366 22 tested_negative 684 4 125 80 0 0 32,3 0,536 27 tested_positive
685 5 136 82 0 0 0 0,64 69 tested_negative
686 2 129 74 26 205 33,2 0,591 25 tested_negative 687 3 130 64 0 0 23,1 0,314 22 tested_negative 688 1 107 50 19 0 28,3 0,181 29 tested_negative 689 1 140 74 26 180 24,1 0,828 23 tested_negative 690 1 144 82 46 180 46,1 0,335 46 tested_positive 691 8 107 80 0 0 24,6 0,856 34 tested_negative 692 13 158 114 0 0 42,3 0,257 44 tested_positive 693 2 121 70 32 95 39,1 0,886 23 tested_negative 694 7 129 68 49 125 38,5 0,439 43 tested_positive
695 2 90 60 0 0 23,5 0,191 25 tested_negative
696 7 142 90 24 480 30,4 0,128 43 tested_positive 697 3 169 74 19 125 29,9 0,268 31 tested_positive
698 0 99 0 0 0 25 0,253 22 tested_negative
<div class="md-card">
<div class="md-card-content"> <div class="uk-grid">
<div class="uk-width-1-1">
<div id="file_upload-drop" class="uk-file-upload">
<p class="uk-text">Penentuan Klasifikasi Penyakit Diabetes dengan K-Means dan KNN</p>
</div> </div> </div> </div> </div> </div> </div> <?php
include 'koneksi.php'; error_reporting(0);
$page = "index.php?page=k_means"; $sec = "10";
?>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'"> <?php
$time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $start = $time;
$sql_cek_iterasi = mysql_query("SELECT * FROM iterasi"); if(mysql_num_rows($sql_cek_iterasi) == 0){
$sql_akumulasi_jarak = mysql_query("SELECT * FROM akumulasi_jarak"); $array_akumulasi_jarak = mysql_fetch_array($sql_akumulasi_jarak);
1");
$array_akhir = mysql_fetch_array($sql_akhir); $iterasi = $array_akhir['iterasi'] + 1;
$iterasi_tampil=$iterasi;
mysql_query("INSERT INTO iterasi SET iterasi='$iterasi'") or die(mysql_error()); }
$delete_jarak = mysql_query("DELETE FROM jarak");
$delete_akumulasi_jarak = mysql_query("DELETE FROM akumulasi_jarak"); //menentukan jumlah euclide distance
$sql_acak = mysql_query("SELECT * FROM nilai_acak ORDER BY id_nilai_acak ASC"); $i=1;
while($array_nilai_acak = mysql_fetch_array($sql_acak)){ $k = $i-1;
$sql_sampel = mysql_query("SELECT * FROM sampel ORDER BY id_sampel ASC"); while($array_sampel = mysql_fetch_array($sql_sampel)){
$cluser = sqrt(pow(($array_sampel['sampel_1'] - $array_nilai_acak['x1']),2) + pow(($array_sampel['sampel_2'] - $array_nilai_acak['x2']),2)
+ pow(($array_sampel['sampel_3'] - $array_nilai_acak['x3']),2) + pow(($array_sampel['sampel_4'] - $array_nilai_acak['x4']),2)
+ pow(($array_sampel['sampel_5'] - $array_nilai_acak['x5']),2) + pow(($array_sampel['sampel_6'] - $array_nilai_acak['x6']),2)
+ pow(($array_sampel['sampel_7'] - $array_nilai_acak['x7']),2) + pow(($array_sampel['sampel_8'] - $array_nilai_acak['x8']),2)) ;
$insert_jarak = mysql_query("INSERT INTO jarak VALUES ('','$array_sampel[id_sampel]','$cluser','$k')");
}
$i++; }
//menentukan jumlah euclide distanc
$sql_max_jarak = mysql_query("SELECT MIN(hasil) AS hasil_max, urutan, id_sampel FROM jarak WHERE id_sampel='$array_sampel[id_sampel]'");
$array_max_jarak = mysql_fetch_array($sql_max_jarak); if($array_max_jarak['hasil_max'] == $array_sampel['hasil']){
$insert_jarak = mysql_query("INSERT INTO akumulasi_jarak VALUES ('','$array_sampel[id_sampel]','$array_max_jarak[hasil_max]',$array_sampel[urutan])"); $insert_jarak = mysql_query("INSERT INTO akumulasi_jarak2 VALUES ('','$array_sampel[id_sampel]','$array_max_jarak[hasil_max]',$array_sampel[urutan])"); }
}
//perhitungan euclidean distancet terhadap centroid pada sampel //proses perpindahan centroids
$sql_num_sampel1 = mysql_query("SELECT a.*,b.* FROM sampel a, akumulasi_jarak b where a.id_sampel=b.id_sampel and b.urutan=0 ORDER BY a.id_sampel ASC");
$num_sampel1 = mysql_num_rows($sql_num_sampel1);
$sql_sampel_urutan_1 = mysql_query("SELECT SUM(a.sampel_1) AS nilai_1,SUM(a.sampel_2) AS nilai_2,
SUM(a.sampel_3) AS nilai_3,SUM(a.sampel_4) AS nilai_4,SUM(a.sampel_5) AS nilai_5,SUM(a.sampel_6) AS nilai_6,SUM(a.sampel_7) AS nilai_7
,SUM(a.sampel_8) AS nilai_8 FROM sampel a, akumulasi_jarak b where a.id_sampel=b.id_sampel and b.urutan=0 ORDER BY a.id_sampel ASC");
$array_sampel_urutan_1 = mysql_fetch_array($sql_sampel_urutan_1) or die(mysql_error()); $sampel1_urutan_1 = $array_sampel_urutan_1['nilai_1'] / $num_sampel1;
$sql_sampel_urutan_2 = mysql_query("SELECT SUM(a.sampel_1) AS nilai_1,SUM(a.sampel_2) AS nilai_2,
SUM(a.sampel_3) AS nilai_3,SUM(a.sampel_4) AS nilai_4,SUM(a.sampel_5) AS nilai_5,SUM(a.sampel_6) AS nilai_6,SUM(a.sampel_7) AS nilai_7
,SUM(a.sampel_8) AS nilai_8 FROM sampel a, akumulasi_jarak b where a.id_sampel=b.id_sampel and b.urutan=1 ORDER BY a.id_sampel ASC");
$array_sampel_urutan_2 = mysql_fetch_array($sql_sampel_urutan_2) or die(mysql_error()); $sampel1_urutan_2 = $array_sampel_urutan_2['nilai_1'] / $num_sampel2;
$sampel2_urutan_2 = $array_sampel_urutan_2['nilai_2'] / $num_sampel2; $sampel3_urutan_2 = $array_sampel_urutan_2['nilai_3'] / $num_sampel2; $sampel4_urutan_2 = $array_sampel_urutan_2['nilai_4'] / $num_sampel2; $sampel5_urutan_2= $array_sampel_urutan_2['nilai_5'] / $num_sampel2; $sampel6_urutan_2 = $array_sampel_urutan_2['nilai_6'] / $num_sampel2; $sampel7_urutan_2 = $array_sampel_urutan_2['nilai_7'] / $num_sampel2; $sampel8_urutan_2 = $array_sampel_urutan_2['nilai_8'] / $num_sampel2; $delete_nilai_acak = mysql_query("DELETE FROM nilai_acak");
$update_1 = mysql_query("INSERT INTO nilai_acak VALUES ('','$sampel1_urutan_1','$sampel2_urutan_1',
'$sampel3_urutan_1','$sampel4_urutan_1','$sampel5_urutan_1','$sampel6_urutan_1','$sampel 7_urutan_1','$sampel8_urutan_1')");
$update_1 = mysql_query("INSERT INTO nilai_acak VALUES ('','$sampel1_urutan_2','$sampel2_urutan_2',
'$sampel3_urutan_2','$sampel4_urutan_2','$sampel5_urutan_2','$sampel6_urutan_2','$sampel 7_urutan_2','$sampel8_urutan_2')");
$sql_pilihan = mysql_query("SELECT * FROM akumulasi_jarak ORDER BY id_akumulasi_jarak ASC");
$array_pilihan = mysql_fetch_array($sql_pilihan);
$id_akumulasi_jarak = $array_pilihan['id_akumulasi_jarak'];
$time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time;
$total_time = round(($finish - $start), 4);
$insert_waktu = mysql_query("INSERT INTO waktu VALUES ('','$total_time')") or die(mysql_error());
//mencari waktu penyelesaian ?>
<div id="page_content">
<div id="page_content_inner">
<h3 class="heading_b uk-margin-bottom">Algoritma K-Means Iterasi <?php echo $iterasi_tampil;?></h3>
<div class="md-card uk-margin-medium-bottom"> <div class="md-card-content">
<table id="dt_default" class="uk-table" cellspacing="0" width="100%"> <thead>
while($array_adult = mysql_fetch_array($sql_adult)){ ?>
<tr>
<td><?php echo $array_adult['cluster_pilihan'];?></td> <td><?php echo $array_adult['urutan'];?></td>
</tr
<?php } ?> </tbody> </table> </div> </div> </div> </div> <?php
$sql_cek_akumulasi_jarak = mysql_query("SELECT * FROM akumulasi_jarak ORDER BY id_sampel ASC");
$array_cek_akumulasi_jarak = mysql_fetch_array($sql_cek_akumulasi_jarak); $cluster_pilihan = $array_cek_akumulasi_jarak['cluster_pilihan'];
$id_sampel_pilihan = $array_cek_akumulasi_jarak['id_sampel'];
$sql_num_akumulasi = mysql_query("SELECT * FROM akumulasi_jarak2 WHERE cluster_pilihan='$cluster_pilihan' and id_sampel='$id_sampel_pilihan'");
$num = mysql_num_rows($sql_num_akumulasi); if($num > 2){
echo "<meta http-equiv='refresh' content='0; url=index.php?page=hasil_kmeans'>";
}?> </body> <?php
$delete_jarak = mysql_query("DELETE FROM jarak_knn"); $delete_jarak = mysql_query("DELETE FROM akumulasi_knn"); $delete_jarak = mysql_query("DELETE FROM cek_knn");
$sql_acak = mysql_query("SELECT * FROM testing ORDER BY id_testing DESC"); $i=1;
//proses perhitungan similiarity funtion pada algoritma KNN while($array_nilai_acak = mysql_fetch_array($sql_acak)){
$sql_sampel = mysql_query("SELECT * FROM sampel ORDER BY id_sampel ASC"); while($array_sampel = mysql_fetch_array($sql_sampel)){
$cluser = sqrt(pow(($array_sampel['sampel_1'] - $array_nilai_acak['x1']),2) + pow(($array_sampel['sampel_2'] - $array_nilai_acak['x2']),2)
+ pow(($array_sampel['sampel_3'] - $array_nilai_acak['x3']),2) + pow(($array_sampel['sampel_4'] - $array_nilai_acak['x4']),2)
+ pow(($array_sampel['sampel_5'] - $array_nilai_acak['x5']),2) + pow(($array_sampel['sampel_6'] - $array_nilai_acak['x6']),2)
+ pow(($array_sampel['sampel_7'] - $array_nilai_acak['x7']),2) + pow(($array_sampel['sampel_8'] - $array_nilai_acak['x8']),2)) ;
$insert_jarak = mysql_query("INSERT INTO jarak_knn VALUES ('','$array_sampel[id_sampel]','$cluser')") or die(mysql_error());
}
$i++; }
//proses perhitungan similiarity funtion pada algoritma KNN //nilai similiarity function pada sample
$sql_num = mysql_query("SELECT * FROM jarak_knn"); $sisa = mysql_num_rows($sql_num) - $k;
$sql_limit_atas = mysql_query("SELECT * FROM jarak_knn ORDER BY nilai DESC LIMIT $k") or die(mysql_error());
while($array_limit_atas = mysql_fetch_array($sql_limit_atas)){
while($array_limit_bawah = mysql_fetch_array($sql_limit_bawah)){
$insert = mysql_query("INSERT INTO akumulasi_knn VALUES ('','$array_limit_bawah[id_sampel]','Negatif')");
}
//nilai similiarity function pada sample //menghitung waktu eksekusi
$time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time;
$total_time = round(($finish - $start), 4); //menghitung waktu eksekusi
?>
<div id="page_content">
<div id="page_content_inner">
<h3 class="heading_b uk-margin-bottom">Algoritma KNN</h3> <div class="md-card uk-margin-medium-bottom">
<div class="md-card-content">
<p><?php echo 'Page generated in '.$total_time.' seconds.';?>
<table class="uk-table" cellspacing="0" width="100%" id="dt_default"> <thead>
<tr>
<th>Jumlahkehamilan(preg)</th>
<th>Konsentrasi plasma glukosadalam 2 jam (plas)</th> <th>Tekanandarahdiastolik (mm Hg) (pres)</th>
<th>Ketebalankulittricep (mm) (skin)</th>
<th>Serum insulin selama 2 jam (mu U/ml) (insu)</th>
<th>Index beratbadan(beratdalam kg / (tinggidalam meter)^2) (mass)</th>
</tr> </thead> <tfoot> <tr>
<th>Jumlahkehamilan(preg)</th>
<th>Konsentrasi plasma glukosadalam 2 jam (plas)</th> <th>Tekanandarahdiastolik (mm Hg) (pres)</th>
<th>Ketebalankulittricep (mm) (skin)</th>
<th>Serum insulin selama 2 jam (mu U/ml) (insu)</th>
<th>Index beratbadan(beratdalam kg / (tinggidalam meter)^2) (mass)</th>
<th>Fungsipedigree diabetes (pedi)</th> <th>Umur(years) (age)</th>
<th>Hasil</th> </tr> </tfoot> <tbody> <?php
$sql_adult = mysql_query("select a.*,b.* from sampel a, akumulasi_knn b where a.id_sampel=b.id_sampel
order by id_akumulasi_knn asc "); while($array_adult = mysql_fetch_array($sql_adult)){
?>
<tr>
<?php } ?> </tbody> </table>
<a href="index.php?page=akumulasi_knn">Akumulasi</a> <br /><br /> <?php
//menghitung tingkat akurasi
$sql_cek_knn = mysql_query("SELECT a.*, b.* FROM sampel a, akumulasi_knn b WHERE a.id_sampel=b.id_sampel");
while($array_cek_knn = mysql_fetch_array($sql_cek_knn)){
$id_sampel = $array_cek_knn['id_sampel'];
if($array_cek_knn['class'] == 'tested_positive'){ $nilai = 'Positif';
}
else if($array_cek_knn['class'] == 'tested_negative'){ $nilai = 'Negatif';
}
if($nilai == $array_cek_knn['hasil'])
$ketepatan = 1;
} else {
$ketepatan = 0; }
$insert_ketepatan =
mysql_query("INSERT INTO cek_knn VALUES ('','$id_sampel','$ketepatan')"); }
$select_total = mysql_query("SELECT COUNT(*) AS jum_sampel FROM sampel");
$ketepatan = ($array['jum_ketepatan'] / $array_total['jum_sampel']) * 100;
echo "Akurasi dari Algoritma ini adalah " . round($ketepatan , 3) . " %";
?> </div>
</div> </div> </div>
<div id="page_content">
<div id="page_content_inner">
<h3 class="heading_b uk-margin-bottom">Hasil K-Means</h3> <div class="md-card">
<div class="md-card-content">
<div class="uk-grid" data-uk-grid-margin> <div class="uk-width-1-1">
Hasil K-Means dengan Hasil Diabetes Positif adalah : <?php
$sql_adult = mysql_query("select a.*,b.* from sampel a, akumulasi_jarak b where a.id_sampel=b.id_sampel
and b.urutan='1'
order by a.id_sampel asc "); $string_positif = "";
while($array_adult = mysql_fetch_array($sql_adult)){
$string_positif .= "Sampel " . $array_adult['id_sampel'] . ', '; }
echo substr($string_positif, 0, strlen($string_positif) - 2); ?>
<div class="md-card-content">
<div class="uk-grid" data-uk-grid-margin> <div class="uk-width-1-1">
Hasil K-Means dengan Hasil Diabetes Negatif adalah : <?php
$sql_adult = mysql_query("select a.*,b.* from sampel a, akumulasi_jarak b where a.id_sampel=b.id_sampel
and b.urutan='0'
order by a.id_sampel asc "); $string = "";
while($array_adult = mysql_fetch_array($sql_adult)){ $string .= "Sampel " . $array_adult['id_sampel'] . ', '; }
echo substr($string, 0, strlen($string) - 2); ?>
</div> </div> </div> </div> </div> </div>
<div id="page_content">
<div id="page_content_inner">
<h3 class="heading_b uk-margin-bottom">Hasil KNN</h3> <div class="md-card">
<div class="md-card-content">
<div class="uk-grid" data-uk-grid-margin> <div class="uk-width-1-1">
order by id_akumulasi_knn asc "); $string_positif = "";
while($array_adult = mysql_fetch_array($sql_adult)){
$string_positif .= "Sampel " . $array_adult['id_sampel'] . ', '; }
echo substr($string_positif, 0, strlen($string_positif) - 2); ?>
</div> </div> </div> </div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-grid" data-uk-grid-margin> <div class="uk-width-1-1">
Hasil KNN dengan Hasil Diabetes Negatif adalah : <?php
$sql_adult = mysql_query("select a.*,b.* from sampel a, akumulasi_knn b where a.id_sampel=b.id_sampel
and b.hasil='Negatif'
order by a.id_sampel asc "); $string = "";
while($array_adult = mysql_fetch_array($sql_adult)){ $string .= "Sampel " . $array_adult['id_sampel'] . ', '; }
echo substr($string, 0, strlen($string) - 2); ?>