LAMPIRAN A KODE PROGRAM ------------------------------------------------------------------------FORM UTAMA (frmUtama) ------------------------------------------------------------------------Public splitTBili, splitDBIli, splitAlkphos, splitTProtein, splitAlbumin As Double Private Sub cmdExit_Click() End End Sub

splitSGPT,

splitSGOT,

Private Sub cmdRules_Click() frmRules.Show End Sub Private Sub cmdKeluar_Click() End End Sub Private Sub cmdPohon_Click() frmPohon.Show End Sub Private Sub cmdTesting_Click() Set ar = con.Execute("select * from tb_tree_atribut") If ar.RecordCount = 0 Then MsgBox ("Pohon Keputusan Belum Terbentuk ! Ikuti Proses Latih Data Terlebih Dahulu.") Else frmTesting.Show End If

End Sub Private Sub cmdTraining_Click() frmTraining.Show End Sub Private Sub Command1_Click() Set ar = con.Execute("select * from tb_tree_atribut") If ar.RecordCount = 0 Then MsgBox ("Pohon Keputusan Belum Terbentuk ! Ikuti Proses Latih Data Terlebih Dahulu.") Else frmTampilTree.Show End If End Sub Private Sub Command2_Click() Set ar = con.Execute("select * from tb_rules") If ar.RecordCount = 0 Then MsgBox ("Pohon Keputusan Belum Terbentuk ! Ikuti Proses Latih Data Terlebih Dahulu.") Else frmTampilRules.Show End If End Sub

Private Sub Command3_Click() Set ar = con.Execute("select * from tb_hitung") If ar.RecordCount = 0 Then MsgBox ("Pohon Keputusan Belum Terbentuk ! Ikuti Proses Latih Data Terlebih Dahulu.") Else frmTampilHitung.Show End If End Sub Private Sub Command4_Click() Set ar = con.Execute("select * from tb_tree_atribut") If ar.RecordCount = 0 Then MsgBox ("Pohon Keputusan Belum Terbentuk ! Ikuti Proses Latih Data Terlebih Dahulu.") Else frmTestMaster.Show End If End Sub Private Sub Form_Load() Call openDB Set ar = con.Execute("truncate table tb_atribut") Set ar = con.Execute("truncate table tb_klas_atribut") Set ar = con.Execute("truncate table tb_pra") Set ar = con.Execute("truncate table tb_testing") Set ar = con.Execute("truncate table tb_hitung") Set ar = con.Execute("truncate table tb_entropy") Set ar = con.Execute("truncate table tb_gain") Set ar = con.Execute("truncate table tb_tree_atribut") Set ar = con.Execute("truncate table tb_trklasdetail") Set ar = con.Execute("truncate table tb_rules") 'Set ar = con.Execute("truncate table tb_tree_parental_detail") Set ar = con.Execute("Select * From tb_entropy") Set ar = con.Execute("truncate table tb_pra") End Sub Private Sub Label3_Click() End Sub

-----------------------------------------------------------------FORM LATIH DATA (frmTraining) -----------------------------------------------------------------Public kodehitung, kodetree, NextNode As String Dim kodeatribut, kodeklasatribut As String 'PROSES DATA Private Sub cmdProses_Click() Dim Level, i, j, jmlbaris, jmlkodetree As Integer Dim VBarisPenentu, ArrayKlasAtribut(), kal, ArrayKodeBarisPenentu(), ArrayRoot(), KondisiBarisPenentu, ExcludeAtribute, ArrayTreeAtribut(), AtributNode As String Dim maxgain As Double Set ar = con.Execute("select * from tb_hitung") If ar.RecordCount 0 Then confirmaction = MsgBox("Semua data pembentukan decision tree sebelumnya akan DIHAPUS. Lanjutkan?", vbOKCancel, "Konfirmasi Penghapusan") If confirmaction = 1 Then GoTo proses End If

Else proses: TreeSolved = "False"

Set ar = con.Execute("truncate table tb_hitung") Set ar = con.Execute("truncate table tb_entropy") Set ar = con.Execute("truncate table tb_gain") Set ar = con.Execute("truncate table tb_tree_atribut") Set ar = con.Execute("truncate table tb_trklasdetail") Set ar = con.Execute("truncate table tb_rules") 'Set ar = con.Execute("truncate table tb_tree_parental_detail") 'Tahapan Apabila Tabel Tree Masih Kosong Level = 0 VBarisPenentu = "TOTAL" KondisiBarisPenentu = "" KondisiBarisPenentuSimpan = "TOTAL" ExcludeAtribute = "" Call hitung(Level, VBarisPenentu, KondisiBarisPenentu, KondisiBarisPenentuSimpan, ExcludeAtribute) KodeBarisPenentu = kodehitung 'Membuat dan Menyimpan Row Pertama Pada Tabel Tree Atribut Set rsc = con.Execute("Select Kode_Atribut from tb_gain join(SELECT Max(Gain) as maxgain FROM `tb_gain` where Node = '" & kodehitung & "') as a on tb_gain.Gain = a.maxgain") AtributNode = rsc.Fields(0).Value Call autokodetree Parent = kodetree Set ar = con.Execute("INSERT INTO `tb_tree_atribut`(`Kode_Tree`, `Level`, `Kode_Atribut`) VALUES ('" & kodetree & "','" & Level & "','" & AtributNode & "')")

'Menentukan Leaf Dari Node Pertama Set ar = con.Execute("select Kode_Atribut from tb_tree_atribut where Kode_Tree = 'TR001'") AtributNode = ar.Fields(0).Value Set ar = con.Execute("Select * from tb_klas_atribut where Kode_Atribut = '" & AtributNode & "' order by Kode_Klas_Atribut") jmlchild = 1 Level = 1 ReDim ArrayKlasAtribut(0 To ar.RecordCount - 1, 0) ar.MoveFirst For i = 0 To ar.RecordCount - 1 ArrayKlasAtribut(i, 0) = ar.Fields(0).Value ar.MoveNext Next For i = 0 To ar.RecordCount - 1 'kal = "" kodeklasatribut = ArrayKlasAtribut(i, 0) Set rsa = con.Execute("select S1, S2, Entropy from tb_entropy where Node = '" & KodeBarisPenentu & "' and Kode_Klas_Atribut = '" & ArrayKlasAtribut(i, 0) & "'") If rsa!S1 = 0 Then Result = "No"

Else If rsa!S2 = 0 Then Result = "Yes" Else Result = "Next" End If End If

If Result = "Next" Then Call autokodetree NewChild = kodetree NextNode = NewChild Set rsb = con.Execute("INSERT INTO `tb_trklasdetail`(`Kode_Tree`, `Kode_Klas_atribut`, `Result`, `Child`) VALUES ('" & Parent & "', '" & kodeklasatribut & "', '" & Result & "', '" & NewChild & "')") 'Set rsb = con.Execute("INSERT INTO `tb_tree_parental_detail`(`Parent`, `Urutan_Child`, `Child`) VALUES ('" & Parent & "', '" & jmlchild & "','" & NewChild & "')") Set rsb = con.Execute("INSERT INTO `tb_tree_atribut`(`Kode_Tree`, `Level`, `Kode_Atribut`) VALUES ('" & NewChild & "','" & Level & "','NULL')") 'Ambil root jmlbaris = 0 nextroot = "true" Do Set rsc = con.Execute("select a.Kode_Tree, a.Level, b.Nama_Atribut, b.Klas_Atribut from((Select tb_trklasdetail.*, tb_tree_atribut.Level from tb_trklasdetail join tb_tree_atribut on tb_trklasdetail.Child = tb_tree_atribut.Kode_Tree) as a Join(select tb_klas_atribut.Kode_Klas_Atribut, tb_klas_atribut.Klas_Atribut, tb_atribut.Nama_Atribut from tb_klas_atribut join tb_atribut on tb_klas_atribut.Kode_Atribut = tb_Atribut.Kode_Atribut) as b on a.Kode_Klas_Atribut = b.Kode_Klas_Atribut) where a. Child = '" & NextNode & "' ") jmlbaris = jmlbaris + 1 If rsc.Fields(1).Value = 1 Then nextroot = "False" Else NextNode = rsc.Fields(0).Value End If Loop While nextroot = "true"

ReDim ArrayRoot(0 To jmlbaris - 1, 0 To 1) NextNode = NewChild For j = 0 To jmlbaris - 1 Set rsc = con.Execute("select a.Kode_Tree, a.Level, b.Nama_Atribut, b.Klas_Atribut from((Select tb_trklasdetail.*, tb_tree_atribut.Level from tb_trklasdetail join tb_tree_atribut on tb_trklasdetail.Child = tb_tree_atribut.Kode_Tree) as a Join(select tb_klas_atribut.Kode_Klas_Atribut, tb_klas_atribut.Klas_Atribut, tb_atribut.Nama_Atribut from tb_klas_atribut join tb_atribut on tb_klas_atribut.Kode_Atribut = tb_Atribut.Kode_Atribut) as b on a.Kode_Klas_Atribut = b.Kode_Klas_Atribut) where a. Child = '" & NextNode & "' ") ArrayRoot(j, 0) = rsc.Fields(2).Value ArrayRoot(j, 1) = rsc.Fields(3).Value NextNode = rsc.Fields(0).Value Next KondisiBarisPenentu = "" KondisiBarisPenentuSimpan = ""

ExcludeAtribute = "where Nama_Atribut Not In(" j = jmlbaris - 1 Do KondisiBarisPenentu = KondisiBarisPenentu & ArrayRoot(j, 0) & "=" & "'" & ArrayRoot(j, 1) & "'" KondisiBarisPenentuSimpan = KondisiBarisPenentuSimpan & ArrayRoot(j, 0) & "=" & "" & ArrayRoot(j, 1) & "" ExcludeAtribute = ExcludeAtribute & "'" & ArrayRoot(j, 0) & "'" If j > 0 Then KondisiBarisPenentu = KondisiBarisPenentu & " And " KondisiBarisPenentuSimpan = KondisiBarisPenentuSimpan & " And " ExcludeAtribute = ExcludeAtribute & "," End If j = j - 1 Loop While j >= 0 ExcludeAtribute = ExcludeAtribute & ")" VBarisPenentu = NewChild Call hitung(Level, VBarisPenentu, KondisiBarisPenentu, KondisiBarisPenentuSimpan, ExcludeAtribute) NodeBaru = kodehitung Set rsc = con.Execute("Select Kode_Atribut from tb_gain join(SELECT Max(Gain) as maxgain FROM `tb_gain` where Node = '" & NodeBaru & "') as a on tb_gain.Gain = a.maxgain ") AtributNode = rsc!Kode_Atribut Set rsc = con.Execute("UPDATE `tb_tree_atribut` SET `Kode_Atribut`= '" & AtributNode & "' WHERE Kode_Tree = '" & NewChild & "'") Else Set rsb = con.Execute("INSERT INTO `tb_trklasdetail`(`Kode_Tree`, `Kode_Klas_atribut`, `Result`, `Child`) VALUES ('" & Parent & "', '" & kodeklasatribut & "', '" & Result & "', 'NULL')") End If jmlchild = jmlchild + 1 Next LevelKerja = 1

Do NextLevel = "False" Set ar = con.Execute("select * from tb_tree_atribut where Level = '" & LevelKerja & "'") If ar.RecordCount = 0 Then NextLevel = "False" Else jmlkodetree = ar.RecordCount - 1 ReDim ArrayTreeAtribut(0 To jmlkodetree, 0) ar.MoveFirst For i = 0 To ar.RecordCount - 1 ArrayTreeAtribut(i, 0) = ar.Fields(0).Value ar.MoveNext Next

For k = 0 To jmlkodetree Set rsx = con.Execute("select * from tb_hitung where Baris_Penentu = '" & ArrayTreeAtribut(k, 0) & "'") KodeBarisPenentu = rsx!Node Parent = ArrayTreeAtribut(k, 0) Set ar = con.Execute("select Kode_Atribut from tb_tree_atribut where Kode_Tree = '" & ArrayTreeAtribut(k, 0) & "' ") AtributNode = ar.Fields(0).Value Set ar = con.Execute("Select * from tb_klas_atribut where Kode_Atribut = '" & AtributNode & "' order by Kode_Klas_Atribut") 'KodeKlasAtribut = ar.Fields(0).Value jmlchild = 1 Level = LevelKerja + 1 ReDim ArrayKlasAtribut(0 To ar.RecordCount - 1, 0) ar.MoveFirst For i = 0 To ar.RecordCount - 1 ArrayKlasAtribut(i, 0) = ar.Fields(0).Value ar.MoveNext Next For i = 0 To ar.RecordCount - 1 'kal = "" 'Result = "NULL" kodeklasatribut = ArrayKlasAtribut(i, 0) Set rsa = con.Execute("select S1, S2, Entropy from tb_entropy where Node = '" & KodeBarisPenentu & "' and Kode_Klas_Atribut = '" & ArrayKlasAtribut(i, 0) & "'") If rsa!S1 = 0 And rsa!S2 = 0 Then Result = "UNCLASSIFIED" Else If rsa!S2 = 0 And rsa!S1 0 Then Result = "Yes" Else If rsa!S1 = 0 And rsa!S2 0 Then Result = "No" Else Result = "Next" End If End If End If If LevelKerja < 8 Then If Result = "Next" Then NextLevel = "True" Call autokodetree NewChild = kodetree NextNode = NewChild Set rsb = con.Execute("INSERT INTO `tb_trklasdetail`(`Kode_Tree`, `Kode_Klas_atribut`, `Result`, `Child`) VALUES ('" & Parent & "', '" & kodeklasatribut & "', '" & Result & "', '" & NewChild & "')") 'Set rsb = con.Execute("INSERT INTO `tb_tree_parental_detail`(`Parent`, `Urutan_Child`, `Child`) VALUES ('" & Parent & "', '" & jmlchild & "','" & NewChild & "')") Set rsb = con.Execute("INSERT INTO `tb_tree_atribut`(`Kode_Tree`, `Level`, `Kode_Atribut`) VALUES ('" & NewChild & "','" & Level & "','NULL')") 'Ambil root

jmlbaris = 0 nextroot = "true" Do Set rsc = con.Execute("select a.Kode_Tree, a.Level, b.Nama_Atribut, b.Klas_Atribut from((Select tb_trklasdetail.*, tb_tree_atribut.Level from tb_trklasdetail join tb_tree_atribut on tb_trklasdetail.Child = tb_tree_atribut.Kode_Tree) as a Join(select tb_klas_atribut.Kode_Klas_Atribut, tb_klas_atribut.Klas_Atribut, tb_atribut.Nama_Atribut from tb_klas_atribut join tb_atribut on tb_klas_atribut.Kode_Atribut = tb_Atribut.Kode_Atribut) as b on a.Kode_Klas_Atribut = b.Kode_Klas_Atribut) where a. Child = '" & NextNode & "' ") jmlbaris = jmlbaris + 1 If rsc.Fields(1).Value = 1 Then nextroot = "False" Else NextNode = rsc.Fields(0).Value End If 'NextNode = rsc.Fields(0).Value Loop While nextroot = "true" 'rsc.Fields(2).Value > 0 ReDim ArrayRoot(0 To jmlbaris - 1, 0 To 1) NextNode = NewChild For j = 0 To jmlbaris - 1 Set rsc = con.Execute("select a.Kode_Tree, a.Level, b.Nama_Atribut, b.Klas_Atribut from((Select tb_trklasdetail.*, tb_tree_atribut.Level from tb_trklasdetail join tb_tree_atribut on tb_trklasdetail.Child = tb_tree_atribut.Kode_Tree) as a Join(select tb_klas_atribut.Kode_Klas_Atribut, tb_klas_atribut.Klas_Atribut, tb_atribut.Nama_Atribut from tb_klas_atribut join tb_atribut on tb_klas_atribut.Kode_Atribut = tb_Atribut.Kode_Atribut) as b on a.Kode_Klas_Atribut = b.Kode_Klas_Atribut) where a. Child = '" & NextNode & "' ") ArrayRoot(j, 0) = rsc.Fields(2).Value ArrayRoot(j, 1) = rsc.Fields(3).Value NextNode = rsc.Fields(0).Value Next For m = 0 To jmlbaris - 1 kal = "" For n = 0 To 1 kal = kal & ArrayRoot(m, n) & " " Next Next

KondisiBarisPenentu = "" KondisiBarisPenentuSimpan = "" ExcludeAtribute = "where Nama_Atribut Not In(" j = jmlbaris - 1 Do KondisiBarisPenentu = KondisiBarisPenentu & ArrayRoot(j, 0) & "=" & "'" & ArrayRoot(j, 1) & "'" KondisiBarisPenentuSimpan = KondisiBarisPenentuSimpan & ArrayRoot(j, 0) & "=" & "" & ArrayRoot(j, 1) & "" ExcludeAtribute = ExcludeAtribute & "'" & ArrayRoot(j, 0) & "'" If j > 0 Then KondisiBarisPenentu = KondisiBarisPenentu & " And " KondisiBarisPenentuSimpan = KondisiBarisPenentuSimpan & " And "

ExcludeAtribute = ExcludeAtribute & "," End If j = j - 1 Loop While j >= 0 ExcludeAtribute = ExcludeAtribute & ")" VBarisPenentu = NewChild

Call hitung(Level, VBarisPenentu, KondisiBarisPenentu, KondisiBarisPenentuSimpan, ExcludeAtribute) NodeBaru = kodehitung

Set rsc = con.Execute("Select max(Gain) from tb_gain where Node = '" & NodeBaru & "' ") maxgain = rsc.Fields(0).Value Set rsc = con.Execute("Select * from tb_gain where Node = '" & NodeBaru & "' and Gain = '" & maxgain & "'") jmlgaintertinggi = rsc.RecordCount 'Pengambilan node dengan nilai Gain sama If jmlgaintertinggi > 1 Then rsc.MoveFirst AtributNode = rsc!Kode_Atribut Else

Set rsc = con.Execute("Select Kode_Atribut from tb_gain join(SELECT Max(Gain) as maxgain FROM `tb_gain` where Node = '" & NodeBaru & "') as a on tb_gain.Gain = a.maxgain where tb_gain.Node = '" & NodeBaru & "' and tb_gain.Gain = a.maxgain ") AtributNode = rsc.Fields(0).Value End If Set rsc = con.Execute("UPDATE `tb_tree_atribut` SET `Kode_Atribut`= '" & AtributNode & "' WHERE Kode_Tree = '" & NewChild & "'") Else Set rsb = con.Execute("INSERT INTO `tb_trklasdetail`(`Kode_Tree`, `Kode_Klas_atribut`, `Result`, `Child`) VALUES ('" & Parent & "', '" & kodeklasatribut & "', '" & Result & "', 'NULL')") End If Else If Result = "Next" Then Set rsb = con.Execute("INSERT INTO `tb_trklasdetail`(`Kode_Tree`, `Kode_Klas_atribut`, `Result`, `Child`) VALUES ('" & Parent & "', '" & kodeklasatribut & "', '" & Result & "', 'UNCLASSIFIED')") Else Set rsb = con.Execute("INSERT INTO `tb_trklasdetail`(`Kode_Tree`, `Kode_Klas_atribut`, `Result`, `Child`) VALUES ('" & Parent & "', '" & kodeklasatribut & "', '" & Result & "', 'NULL')") End If End If jmlchild = jmlchild + 1 Next Next LevelKerja = LevelKerja + 1

If LevelKerja > 8 Then NextLevel = "False" End If End If Loop While NextLevel = "True" Set ar = con.Execute("truncate table tb_rules") Set ar = con.Execute("SELECT * FROM `tb_trklasdetail` where result 'Next' or Child = 'UNCLASSIFIED'") ar.MoveFirst For a = 0 To ar.RecordCount - 1 If ar.Fields(0).Value = "TR001" Then Set rs1 = con.Execute("select b.Nama_Atribut, a.Klas_Atribut from((select * from tb_klas_atribut where Kode_Klas_Atribut = '" & ar.Fields(1).Value & "' )as a join (select * from tb_atribut) as b on a.Kode_Atribut = b.Kode_Atribut)") KondisiBarisPenentu = "" & rs1.Fields(0) & " = " & rs1.Fields(1) & "" Set rs2 = con.Execute("INSERT INTO `tb_rules`(`Rule`, `Hasil`) VALUES ('" & KondisiBarisPenentu & "','" & ar.Fields(2) & "')") Else NewChild = ar.Fields(0).Value NextNode = NewChild jmlbaris = 0 nextroot = "true" Do Set rsc = con.Execute("select a.Kode_Tree, a.Level, b.Nama_Atribut, b.Klas_Atribut from((Select tb_trklasdetail.*, tb_tree_atribut.Level from tb_trklasdetail join tb_tree_atribut on tb_trklasdetail.Child = tb_tree_atribut.Kode_Tree) as a Join(select tb_klas_atribut.Kode_Klas_Atribut, tb_klas_atribut.Klas_Atribut, tb_atribut.Nama_Atribut from tb_klas_atribut join tb_atribut on tb_klas_atribut.Kode_Atribut = tb_Atribut.Kode_Atribut) as b on a.Kode_Klas_Atribut = b.Kode_Klas_Atribut) where a. Child = '" & NextNode & "' ") jmlbaris = jmlbaris + 1 If rsc.Fields(1).Value = 1 Then nextroot = "False" Else NextNode = rsc.Fields(0).Value End If Loop While nextroot = "true" ReDim ArrayRoot(0 To jmlbaris - 1, 0 To 1) NextNode = NewChild For j = 0 To jmlbaris - 1 Set rsc = con.Execute("select a.Kode_Tree, a.Level, b.Nama_Atribut, b.Klas_Atribut from((Select tb_trklasdetail.*, tb_tree_atribut.Level from tb_trklasdetail join tb_tree_atribut on tb_trklasdetail.Child = tb_tree_atribut.Kode_Tree) as a Join(select tb_klas_atribut.Kode_Klas_Atribut, tb_klas_atribut.Klas_Atribut, tb_atribut.Nama_Atribut from tb_klas_atribut join tb_atribut on tb_klas_atribut.Kode_Atribut = tb_Atribut.Kode_Atribut) as b on a.Kode_Klas_Atribut = b.Kode_Klas_Atribut) where a. Child = '" & NextNode & "' ") ArrayRoot(j, 0) = rsc.Fields(2).Value ArrayRoot(j, 1) = rsc.Fields(3).Value NextNode = rsc.Fields(0).Value Next For m = 0 To jmlbaris - 1 kal = "" For n = 0 To 1 kal = kal & ArrayRoot(m, n) & " " Next

Next KondisiBarisPenentu = "" ExcludeAtribute = "where Nama_Atribut Not In(" j = jmlbaris - 1 Do KondisiBarisPenentu = KondisiBarisPenentu & ArrayRoot(j, 0) & "=" & "" & ArrayRoot(j, 1) & "" ExcludeAtribute = ExcludeAtribute & "'" & ArrayRoot(j, 0) & "'" If j > 0 Then KondisiBarisPenentu = KondisiBarisPenentu & " And " ExcludeAtribute = ExcludeAtribute & "," End If j = j - 1 Loop While j >= 0 Set rs1 = con.Execute("select d.Nama_Atribut, c.Klas_Atribut from(select a.Kode_Klas_Atribut, b.Klas_Atribut, b.Kode_Atribut from(SELECT * FROM `tb_trklasdetail` ) as a join (select * from tb_klas_atribut where Kode_Klas_Atribut = '" & ar.Fields(1).Value & "') as b on a.Kode_Klas_Atribut = b.Kode_Klas_Atribut) as c join (select * from tb_atribut)as d on c.KOde_Atribut = d.Kode_Atribut") KondisiBarisPenentu = KondisiBarisPenentu & " And " & rs1.Fields(0).Value & "=" & rs1.Fields(1).Value ExcludeAtribute = ExcludeAtribute & ")" If ar.Fields(2).Value "Next" Then Set rs2 = con.Execute("INSERT INTO `tb_rules`(`Rule`, `Hasil`) VALUES ('" & KondisiBarisPenentu & "','" & ar.Fields(2) & "')") Else Set rs2 = con.Execute("INSERT INTO `tb_rules`(`Rule`, `Hasil`) VALUES ('" & KondisiBarisPenentu & "','" & ar.Fields(3) & "')") End If End If ar.MoveNext Next

TreeSolved = "True"

If TreeSolved = "True" Then MsgBox ("Proses Pembentukan Tree Selesai") End If Set ar = con.Execute("select * from tb_tree_atribut") If ar.RecordCount = 0 Then MsgBox "Tree Tidak Terbentuk Karena Data Latih Tidak Menghasilkan Pola", vbCritical Else frmTampilTree.Show End If End If End Sub

Cukup

Untuk

'Pra Proses GINI Private Sub Command2_Click() Dim ArrayNamaAtribut(0 To 8) As String Dim ArraySplit(0 To 8) As Double Dim ArrayA(), ArrayB(), ArrayC() As Double Dim Split, GiniLow, GiniHigh As Double 'Menghapus Semua Data dari tb_atribut, tb_klas_atribut, dan tb_pra If Text1.Text = "" Then MsgBox "Anda Belum Menentukan Jumlah Data Testing Dan Training", vbCritical, "REQUIRED INPUT" Text1.SetFocus Else Set ar = con.Execute("select * from tb_atribut") If ar.RecordCount 0 Then confirmaction = MsgBox("Semua data pada tb_atribut, tb_klas_atribut, dan tb_pra akan DIHAPUS. Lanjutkan?", vbOKCancel, "Konfirmasi Penghapusan") If confirmaction = 1 Then GoTo proses Else MsgBox ("pra proses dibatalkan") End If Else proses: Set ar = con.Execute("truncate table tb_atribut") Set ar = con.Execute("truncate table tb_klas_atribut") Set ar = con.Execute("truncate table tb_pra") Set ar = con.Execute("truncate table tb_testing") Set ar = con.Execute("truncate table tb_pre_gini") StatusPraProses = "Computing" ArrayNamaAtribut(0) = "age" ArrayNamaAtribut(1) = "gender" ArrayNamaAtribut(2) = "total_bili" ArrayNamaAtribut(3) = "direct_bili" ArrayNamaAtribut(4) = "alkphos" ArrayNamaAtribut(5) = "sgpt" ArrayNamaAtribut(6) = "sgot" ArrayNamaAtribut(7) = "total_protein" ArrayNamaAtribut(8) = "albumin" Set rsa = con.Execute("select * from tb_liver") jmltraining = (Text1.Text * (1 / 100)) * rsa.RecordCount Set ar = con.Execute("select * from tb_liver") ar.MoveFirst For i = 0 To jmltraining - 1 Set rs1 = con.Execute("INSERT INTO `tb_pre_gini`(`age`, `gender`, `total_bili`, `direct_bili`, `alkphos`, `sgpt`, `sgot`, `total_protein`, `albumin`, `liver_patient`) VALUES ('" & ar.Fields(0).Value & "','" & ar.Fields(1).Value & "','" & ar.Fields(2).Value & "','" & ar.Fields(3).Value & "','" & ar.Fields(4).Value & "','" & ar.Fields(5).Value & "','" & ar.Fields(6).Value & "','" & ar.Fields(7).Value & "','" & ar.Fields(8).Value & "','" & ar.Fields(9).Value & "')") ar.MoveNext Next For j = 0 To 8 Set rs1 = con.Execute("select " & ArrayNamaAtribut(j) & " from tb_pre_gini group by " & ArrayNamaAtribut(j) & " order by " & ArrayNamaAtribut(j) & "") If ArrayNamaAtribut(j) "age" And ArrayNamaAtribut(j) "gender" Then ReDim ArrayA(0 To rs1.RecordCount - 1, 0) rs1.MoveFirst For i = 0 To rs1.RecordCount - 1 ArrayA(i, 0) = rs1.Fields(0).Value rs1.MoveNext

Next ReDim ArrayB(0 To rs1.RecordCount, 0) For i = 0 To rs1.RecordCount If i = 0 Then ArrayB(i, 0) = ArrayA(i, 0) Else If i > 0 And i < rs1.RecordCount - 1 Then ArrayB(i, 0) = (ArrayA(i - 1, 0) + ArrayA(i, 0)) / 2 Else ArrayB(i, 0) = ArrayA(i - 1, 0)

End If End If Next

Set rs2 = con.Execute("select count(*) from tb_pre_gini") jmltotaldata = rs2.Fields(0).Value ReDim ArrayC(0 To rs1.RecordCount) For i = 0 To rs1.RecordCount Set rs2 = con.Execute("select count(*) from tb_pre_gini where " & ArrayNamaAtribut(j) & " '" & ArrayB(i, 0) & "' and liver_patient = '2'") jmlNoHigh = rs2.Fields(0).Value If jmlYesLow = 0 Or jmlTotalLow = 0 Then pgylow = 0 Else If jmlNoLow = 0 Or jmlTotalLow = 0 Then pgnlow = 0 Else pgylow = (jmlYesLow / jmlTotalLow) pgnlow = (jmlNoLow / jmlTotalLow) End If End If If jmlYesHigh = 0 Or jmlTotalHigh = 0 Then pgyhigh = 0 Else If jmlNoHigh = 0 Or jmlTotalHigh = 0 Then pgnhigh = 0 Else pgyhigh = (jmlYesHigh / jmlTotalHigh)

pgnhigh = (jmlNoHigh / jmlTotalHigh) End If End If GiniLow = 1 - (pgylow ^ 2) - (pgnlow ^ 2) GiniHigh = 1 - (pgyhigh ^ 2) - (pgnhigh ^ 2) If GiniLow = 0 Then pginilow = 0 Else If GiniHigh = 0 Then pginihigh = 0 Else If jmlTotalLow = 0 Then tplow = 0 Else If jmlTotalHigh = 0 Then tphigh = 0 Else tplow = (jmlTotalLow / jmltotaldata) tphigh = (jmlTotalHigh / jmltotaldata) pginilow = (tplow * GiniLow) pginihigh = (tphigh * GiniHigh) End If End If End If End If Gini = pginilow + pginihigh ArrayC(i) = Gini Next Split = ArrayC(0) 'Split = 0 IndexSplit = 0 For i = 0 To rs1.RecordCount If ArrayC(i) < Split Then Split = ArrayC(i) IndexSplit = i 'Split = i 'ArraySplit(j) = ArrayB(i, 0) End If Next ArraySplit(j) = ArrayB(IndexSplit, 0) End If Next

For j = 0 To 8 Call autokodeatribut If ArrayNamaAtribut(j) "age" And ArrayNamaAtribut(j) "gender" Then Set ar = con.Execute("INSERT INTO `tb_atribut`(`Kode_Atribut`, `Nama_Atribut`, Split) VALUES ('" & kodeatribut & "','" & ArrayNamaAtribut(j) & "', '" & ArraySplit(j) & "')") Call autokodeklasatribut Set ar = con.Execute("INSERT INTO `tb_klas_atribut`(`Kode_Klas_Atribut`, `Kode_Atribut`, `Klas_Atribut`) VALUES ('" & kodeklasatribut & "','" & kodeatribut & "','" & ArraySplit(j) & "')") Else

If ArrayNamaAtribut(j) = "age" Then Set ar = con.Execute("INSERT INTO `tb_atribut`(`Kode_Atribut`, `Nama_Atribut`, Split) VALUES ('" & kodeatribut & "','" & ArrayNamaAtribut(j) & "', '0')") Call autokodeklasatribut Set ar = con.Execute("INSERT INTO `tb_klas_atribut`(`Kode_Klas_Atribut`, `Kode_Atribut`, `Klas_Atribut`) VALUES ('" & kodeklasatribut & "','" & kodeatribut & "','child (=15 and =50)')") Else Set ar = con.Execute("INSERT INTO `tb_atribut`(`Kode_Atribut`, `Nama_Atribut`, Split) VALUES ('" & kodeatribut & "','" & ArrayNamaAtribut(j) & "', '0')") Call autokodeklasatribut Set ar = con.Execute("INSERT INTO `tb_klas_atribut`(`Kode_Klas_Atribut`, `Kode_Atribut`, `Klas_Atribut`) VALUES ('" & kodeklasatribut & "','" & kodeatribut & "','Male')") Call autokodeklasatribut Set ar = con.Execute("INSERT INTO `tb_klas_atribut`(`Kode_Klas_Atribut`, `Kode_Atribut`, `Klas_Atribut`) VALUES ('" & kodeklasatribut & "','" & kodeatribut & "','Female')") End If End If Next Set rsa = con.Execute("select * from tb_liver") jmltraining = (Text1.Text * (1 / 100)) * rsa.RecordCount maxrowtraining = Math.Round(jmltraining, 0) Text2.Text = maxrowtraining If Text1.Text = 100 Then Text4.Text = maxrowtraining Else Text4.Text = rsa.RecordCount - maxrowtraining End If rsa.MoveFirst For j = 0 To rsa.RecordCount - 1 isivalue = "" For k = 0 To 8 If ArrayNamaAtribut(k) "age" And ArrayNamaAtribut(k) "gender" Then If rsa.Fields(k).Value = 3.8) Then

albumin = "3.8 - 6.0" Else If (ar!albumin < 3.8) And (ar!albumin >= 3) Then albumin = "3.0 - 3.7" Else If (ar!albumin < 3) And (ar!albumin >= 2) Then albumin = "2.0 - 2.9" Else albumin = "0 - 1.9" End If End If End If 'Klasifikasi Patient Liver If (ar!liver_patient = 1) Then liver_patient = "Yes" Else liver_patient = "No" End If

If maxrowtraining = ar.RecordCount Then sql2 = "Insert into tb_pra (age, gender, total_bili, direct_bili, alkphos,sgpt,sgot,total_protein,albumin,liver_patient) Values" & _ " ('" & age & "' , '" & gender & "' , '" & total_bili & "' , '" & direct_bili & "', '" & alkphos & "','" & sgpt & "', '" & sgot & "', '" & total_protein & "','" & albumin & "', '" & liver_patient & "')" Set rs = con.Execute(sql2) sql2 = "Insert into tb_testing (age, gender, total_bili, direct_bili, alkphos,sgpt,sgot,total_protein,albumin,liver_patient) Values" & _ " ('" & age & "' , '" & gender & "' , '" & total_bili & "' , '" & direct_bili & "', '" & alkphos & "','" & sgpt & "', '" & sgot & "', '" & total_protein & "','" & albumin & "', '" & liver_patient & "')" Set rs = con.Execute(sql2) Else If i = 3.8) Then albumin = "3.8 - 6.0" Else If (txAlbumin.Text < 3.8) And (txAlbumin.Text >= 3) Then albumin = "3.0 - 3.7" Else If (txAlbumin.Text < 3) And (txAlbumin.Text >= 2) Then albumin = "2.0 - 2.9" Else albumin = "0 - 1.9" End If End If End If

Else Set ar = con.Execute("select * from tb_atribut")

'Klasifikasi Usia ar.MoveFirst If txUsia.Text = 15) And (txUsia.Text