LAMPIRAN Listing program aplikasi data mining menggunakan algoritma apriori dan FP-Growth adalah sebagai berikut:
1. Proses pembuatan tabel C1 $ld_barang=$data['id_barang']; $count_barang = mysql_query("SELECT count(*) AS jum_barang FROM transaksi_barang where id_barang='$ld_barang' and kode_transaksi <= '$jum_transaksi'") or die(mysql_error()); $array_count_barang = mysql_fetch_array($count_barang); $distinc_transaksi = mysql_query("select count(distinct(kode_transaksi)) as jum_transaksi from transaksi_barang where kode_transaksi <= '$jum_transaksi'"); $array_count_transaksi = mysql_fetch_array($distinc_transaksi); $support = $array_count_barang['jum_barang']/$array_count_transaksi['jum_transaksi']; $sql_rows_support = mysql_query("SELECT * FROM support_apriori WHERE id_barang='$ld_barang' and nilai_support='$support'"); if(mysql_num_rows($sql_rows_support)){
echo ''; } else {
$insert_support = mysql_query("INSERT INTO support_apriori VALUES ('', '$ld_barang', '$support')"); } $l++; }
Universitas Sumatera Utara
73
2. Proses pembuatan tabel C2
$TRecord = mysql_query("SELECT a.*,b.* FROM barang a, support_apriori b where a.id_barang=b.id_barang and b.nilai_support >= '$min_support' order By a.id_barang ASC") or die(mysql_error());
$j=1; while($data=mysql_fetch_array($TRecord)) $i=$data['id_barang']; $TRecord2 = mysql_query("SELECT a.*,b.* FROM barang a, support_apriori b where a.id_barang=b.id_barang and b.nilai_support >= '$min_support' order By a.id_barang ASC") or die(mysql_error());
while($data2=mysql_fetch_array($TRecord2)){ $id_barang2=$data2['id_barang']; $nilai_support = $min_support;
if($i!=$id_barang2){
$sql_cek_kombinasi = mysql_query("SELECT * FROM kombinasi_apriori WHERE id_barang='$i' and id_kombinasi='$id_barang2' and support_count='$nilai_support'"); if(mysql_num_rows($sql_cek_kombinasi)){
echo ''; } else {
Universitas Sumatera Utara
$insert_sql = mysql_query("INSERT INTO kombinasi_apriori VALUES ('$i', '$id_barang2','$nilai_support')") or die (mysql_error()); $delete_sql = mysql_query("DELETE FROM kombinasi_apriori WHERE id_kombinasi='$i'"); } } }
$j++; }
3. Proses Pembuatan Tabel L1 $distinc_transaksi = mysql_query("select count(distinct(kode_transaksi)) as jum_transaksi from transaksi_barang where kode_transaksi <= '$jum_transaksi'"); $array_count_transaksi = mysql_fetch_array($distinc_transaksi); $TRecord = mysql_query("SELECT * FROM kombinasi_apriori order By id_kombinasi ASC") or die(mysql_error()); while($data=mysql_fetch_array($TRecord)){ $total = 0; for ($l=1;$l<=$array_count_transaksi['jum_transaksi'];$l++){ $id1=$data['id_kombinasi']; $id2=$data['id_barang'];
$sql_transaksi = mysql_query("SELECT count(*) as jum_trans from transaksi_barang where id_barang IN('$id1','$id2') and kode_transaksi ='$l' and kode_transaksi <= '$jum_transaksi'"); $array_transaksi = mysql_fetch_array($sql_transaksi);
Universitas Sumatera Utara
75
$array_transaksi['jum_trans']; if($array_transaksi['jum_trans'] == 2){ $cont = 1;
} else { $cont = 0;
} $total = $total+$cont; }
$support2= $total/$array_count_transaksi['jum_transaksi'];
$update_kombinasi = mysql_query("UPDATE kombinasi_apriori SET support_count = '$support2' WHERE id_kombinasi='$id1' and id_barang='$id2'");
$j++;
}
4. Proses Pembuatan Tabel L2
$TRecord = mysql_query("SELECT * FROM kombinasi_apriori WHERE support_count >= '$min_support' order By id_kombinasi ASC") or die(mysql_error());
Universitas Sumatera Utara
while($data=mysql_fetch_array($TRecord)){ $total = 0; for ($l=1;$l<=$array_count_transaksi['jum_transaksi'];$l++){ $id1=$data['id_kombinasi']; $id2=$data['id_barang'];
$sql_transaksi = mysql_query("SELECT count(*) as jum_trans from transaksi_barang where id_barang IN('$id1','$id2') and kode_transaksi ='$l' and kode_transaksi <= '$jum_transaksi'"); $array_transaksi = mysql_fetch_array($sql_transaksi);
$array_transaksi['jum_trans']; if($array_transaksi['jum_trans'] == 2){ $cont = 1;
} else { $cont = 0;
} $total = $total+$cont; }
$count_barang = mysql_query("SELECT count(*) AS jum_barang FROM transaksi_barang where id_barang='$id1' and kode_transaksi <= '$jum_transaksi'") or die(mysql_error()); $array_count_barang = mysql_fetch_array($count_barang);
Universitas Sumatera Utara
77
$confidence= $total/$array_count_barang['jum_barang']; $sql_jum_confidence = mysql_query("SELECT * FROM confidence_apriori WHERE min_support='$min_support' and id1='$id1' and id2='$id2' and confidence='$confidence'"); if(mysql_num_rows($sql_jum_confidence)){
echo ''; } else { $insert_confidence1 = mysql_query("INSERT INTO confidence_apriori VALUES ('$id1', '$id2','$confidence','$min_support')") or die (mysql_error()); } $j++; } ?>
Nomor | Kombinasi | Kesimpulan | Nilai Confidence |
= '$nilai_confidence' and min_support ='$min_support'") or die(mysql_error()); while($array_hasil_confidence=mysql_fetch_array($sql_hasil_confidence)){
Universitas Sumatera Utara
?> | " . $array_hasil_confidence['id2'];?> | <span>Jika Konsumen Membeli <strong>, maka membeli <strong>
| |
Universitas Sumatera Utara
79
} ?>
$time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 4);
echo "Lama Proses Filtering : " . $total_time." detik";
} ?>
5. Menghitung frekuensi item $jum_transaksi = $_POST['jum_transaksi']; $sql_transaksi = mysql_query("SELECT distinct(kode_transaksi) FROM transaksi_barang where kode_transaksi <= '$jum_transaksi'"); $num_transaksi = mysql_num_rows($sql_transaksi); $support = $_POST['support']; $minimum_support = $support * $num_transaksi; $confidence = $_POST['confidence'];
Universitas Sumatera Utara
$i=1; $sql_barang = mysql_query("SELECT * FROM barang ORDER BY id_barang DESC"); while($array_barang = mysql_fetch_array($sql_barang)){ $sql_num_barang = mysql_query("SELECT * FROM transaksi_barang WHERE id_barang='" . $array_barang['id_barang'] . "' and kode_transaksi <= '$jum_transaksi'") or die (mysql_error()); $num_barang = mysql_num_rows($sql_num_barang); $array_num = mysql_fetch_array($sql_num_barang); if($num_barang >= $minimum_support){ $sql_support = mysql_query("SELECT * FROM transaksi_barang WHERE id_barang = '" . $array_num['id_barang'] . "' and kode_transaksi <= '$jum_transaksi'") or die (mysql_error()); while($array_support = mysql_fetch_array($sql_support)){ $kode_transaksi = $array_support['kode_transaksi']; $tgl_transaksi = $array_support['tgl_transaksi']; $id_barang = $array_support['id_barang']; $sql_cek_support = mysql_query("SELECT * FROM support_fpgrowth WHERE kode_transaksi='$kode_transaksi' and tgl_transaksi='$tgl_transaksi' and id_barang='$id_barang' and support='$support' and jum_transaksi='$jum_transaksi'") or die (mysql_error()); if(mysql_num_rows($sql_cek_support)){ echo ''; } else { $insert_support = mysql_query("INSERT INTO support_fpgrowth VALUES ('','$kode_transaksi','$tgl_transaksi','$id_barang','$support' ,'$jum_transaksi')") or die(mysql_error()); //fungsi untuk menginput data ke database; } }
} else if($num_barang <= 1) {
Universitas Sumatera Utara
81
} $i++; }
6. Pembuatan tree $sql_tampil_support = mysql_query("SELECT a.*, b.* FROM support_fpgrowth a, barang b WHERE a.id_barang=b.id_barang and a.support='$support' and a.jum_transaksi='$jum_transaksi' order by a.kode_transaksi ASC") or die(mysql_error()); while($array_tampil_support=mysql_fetch_array($sql_tampil_support)){ }
$sql_tampil_support = mysql_query("SELECT distinct(b.nama_barang),a.id_barang FROM support_fpgrowth a, barang b WHERE a.id_barang=b.id_barang and a.support='$support' and a.jum_transaksi='$jum_transaksi' order by a.kode_transaksi ASC") or die(mysql_error()); while($array_tampil_support=mysql_fetch_array($sql_tampil_support)){
$sql_tampil_transaksi = mysql_query("SELECT * FROM support_fpgrowth WHERE id_barang='" . $array_tampil_support['id_barang'] . "' and support='$support' and jum_transaksi='$jum_transaksi'") or die (mysql_error()); while($array_tampil_transaksi=mysql_fetch_array($sql_tampil_transaksi)){
$sql_tampil_transaksi2 = mysql_query("SELECT a.*,b.* FROM support_fpgrowth a, barang b WHERE a.id_barang=b.id_barang and a.id_barang !='" . $array_tampil_support['id_barang'] . "' and a.kode_transaksi='" . $array_tampil_transaksi['kode_transaksi'] . "' and a.support='$support' and a.jum_transaksi='$jum_transaksi'") or die (mysql_error()); while($array_tampil_transaksi2=mysql_fetch_array($sql_tampil_transaksi2)){
Universitas Sumatera Utara
$kombinasi1 = $array_tampil_support['id_barang']; $kombinasi2 = $array_tampil_transaksi2['id_barang']; $kode_transaksi = $array_tampil_transaksi['kode_transaksi']; $sql_cek_kombinasi = mysql_query("SELECT * FROM kombinasi_fpgrowth WHERE kombinasi_1='$kombinasi1' and kombinasi_2='$kombinasi2'") or die(mysql_error()); $num_kombinasi = mysql_num_rows($sql_cek_kombinasi); if($num_kombinasi >= 2){ $sql_cek_kombinasi2 = mysql_query("SELECT * FROM hasil_kombinasi WHERE hasil_kombinasi_1='$kombinasi1' and hasil_kombinasi_2='$kombinasi2'") or die(mysql_error()); if(mysql_num_rows($sql_cek_kombinasi2)){ echo ''; } else { $sql_insert_kombinasi2 = mysql_query("INSERT INTO hasil_kombinasi VALUES('','$kombinasi1','$kombinasi2')") or die(mysql_error()); } } $sql_cek_kombinasi2 = mysql_query("SELECT * FROM kombinasi_fpgrowth WHERE kombinasi_1='$kombinasi1' and kombinasi_2='$kombinasi2' and kode_transaksi='$kode_transaksi'") or die(mysql_error());
if(mysql_num_rows($sql_cek_kombinasi2)){ echo ''; } else { $sql_insert_kombinasi = mysql_query("INSERT INTO kombinasi_fpgrowth VALUES('','$kombinasi1','$kombinasi2','$kode_transaksi')") or die(mysql_error()); } }
Universitas Sumatera Utara
83
}
} 7. Menghitung confidence $sql_tampil_support = mysql_query("SELECT * FROM hasil_kombinasi"); while($array_tampil_support=mysql_fetch_array($sql_tampil_support)){ $sql_nama_barang1=mysql_query("SELECT * FROM barang where id_barang='" . $array_tampil_support['hasil_kombinasi_1'] . "'"); $array_nama_barang1 = mysql_fetch_array($sql_nama_barang1); $sql_nama_barang2=mysql_query("SELECT * FROM barang where id_barang='" . $array_tampil_support['hasil_kombinasi_2'] . "'"); $array_nama_barang2 = mysql_fetch_array($sql_nama_barang2); $sql_num_1 = mysql_query("SELECT * FROM transaksi_barang WHERE id_barang='". $array_tampil_support['hasil_kombinasi_1'] . "' and kode_transaksi <= '$jum_transaksi'") or die(mysql_error()); $num_1 = mysql_num_rows($sql_num_1); $sql_num_2 = mysql_query("SELECT * FROM kombinasi_fpgrowth WHERE kombinasi_1='". $array_tampil_support['hasil_kombinasi_1'] . "' and kombinasi_2='". $array_tampil_support['hasil_kombinasi_2'] . "'") or die(mysql_error()); $num_2 = mysql_num_rows($sql_num_2); $hasil = $num_2 / $num_1; if($hasil >= $confidence){ $confidence1 =$array_tampil_support['hasil_kombinasi_1']; $confidence2 =$array_tampil_support['hasil_kombinasi_2']; $sql_num_confidence = mysql_query("SELECT * FROM confidence_fpgrowth WHERE confidence_1='" . $array_tampil_support['hasil_kombinasi_1'] . "' and confidence_2 = '" . $array_tampil_support['hasil_kombinasi_2'] . "'") or die(mysql_error());
Universitas Sumatera Utara
if(mysql_num_rows($sql_num_confidence)){ echo ''; } else {
$sql_confidence = mysql_query("INSERT INTO confidence_fpgrowth VALUES ('','$confidence1', '$confidence2', '$hasil')") or die(mysql_error()); } }
}
8.
Menampilkan hasil kombinasi dan menginput ke tabel confidence
$sql_tampil_support = mysql_query("SELECT * FROM hasil_kombinasi"); while($array_tampil_support=mysql_fetch_array($sql_tampil_support)){ $sql_nama_barang1=mysql_query("SELECT * FROM barang where id_barang='" . $array_tampil_support['hasil_kombinasi_1'] . "'"); $array_nama_barang1 = mysql_fetch_array($sql_nama_barang1); $sql_nama_barang2=mysql_query("SELECT * FROM barang where id_barang='" . $array_tampil_support['hasil_kombinasi_2'] . "'"); $array_nama_barang2 = mysql_fetch_array($sql_nama_barang2); $sql_num_1 = mysql_query("SELECT * FROM transaksi_barang WHERE id_barang='". $array_tampil_support['hasil_kombinasi_1'] . "' and kode_transaksi <= '$jum_transaksi'") or die(mysql_error()); $num_1 = mysql_num_rows($sql_num_1); $sql_num_2 = mysql_query("SELECT * FROM kombinasi_fpgrowth WHERE kombinasi_1='". $array_tampil_support['hasil_kombinasi_1'] . "' and kombinasi_2='". $array_tampil_support['hasil_kombinasi_2'] . "'") or die(mysql_error()); $num_2 = mysql_num_rows($sql_num_2);
Universitas Sumatera Utara
85
$hasil = $num_2 / $num_1; if($hasil >= $confidence){ $confidence1 =$array_tampil_support['hasil_kombinasi_1']; $confidence2 =$array_tampil_support['hasil_kombinasi_2']; $sql_num_confidence = mysql_query("SELECT * FROM confidence_fpgrowth WHERE confidence_1='" . $array_tampil_support['hasil_kombinasi_1'] . "' and confidence_2 = '" . $array_tampil_support['hasil_kombinasi_2'] . "'") or die(mysql_error()); if(mysql_num_rows($sql_num_confidence)){ echo ''; } else {
$sql_confidence = mysql_query("INSERT INTO confidence_fpgrowth VALUES ('','$confidence1', '$confidence2', '$hasil')") or die(mysql_error()); } }
} ?>
Kesimpulan | Confidence |
Universitas Sumatera Utara
$sql_tampil_support = mysql_query("SELECT * FROM confidence_fpgrowth"); while($array_tampil_support=mysql_fetch_array($sql_tampil_support)){ ?>
?> | |
9. Menampilkan hasil korelasi ?>
Universitas Sumatera Utara
87
echo "Lama Proses Filtering : " . $total_time." detik"; } ?>
Universitas Sumatera Utara
CURRICULUM VITAE
Nama
: Eva Cristy Yuliana Manurung
Alamat Sekarang
: Jl. Jamin Ginting Gang Ganefo No. 8 Padang Bulan Medan
Alamat Orang Tua
: Bahbutong, Kecamatan Sidamanik, Kabupaten Simalungun
Telepon/ hp
: 085359807001
Riwayat Pendidikan: 1996 – 2002
: SD NEGERI NO 091423 BAH BUTONG
2002 – 2005
: SMP NEGERI 1 SIDAMANIK
2005 – 2008
: SMA NEGERI 3 PEMATANG SIANTAR
2008 – 2011
: D3 TEKNIK INFORMATIKA UNIVERSITAS SUMATERA
UTARA
Keahlian/ Kursus yang diikuti:
1.
Kursus bahasa inggris
2.
Mengetahui Microsoft Visual Basic
3.
Mengetahui PHP
Universitas Sumatera Utara