Imports System.Data
Imports System.Data.OleDb
Public Class DataMining
Dim MyCon As OleDbConnection
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\DataMiningProgram\Data.accdb"
Dim MyReader As OleDbDataReader
Dim MyCmd As OleDbCommand
Public DA As OleDbDataAdapter
Public DS As DataSet
Dim StrSQL As String
Public DA2 As OleDbDataAdapter
Public DS2 As DataSet
Dim StrSQL2 As String
Private CMB As OleDbCommandBuilder
Private DR As DataRow
Public Save_Status As String
Dim pre1 As Integer
Dim pre2 As Integer
Dim pre3 As Integer
Dim max1 As Double = 0
Dim max2 As Double = 0
Dim max3 As Double = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lbP.Text = ""
lbRecall.Text = ""
lbF.Text = ""
txt01.Text = ""
Label1.Text = ""
'---------------------------------------------------------------------------
MyCon = New OleDbConnection(strConn)
If MyCon.State = ConnectionState.Open Then
MyCon.Close()
Else
MyCon.Open()
End If
Dim StrSQL As String = "select * from Tb01"
DA = New OleDbDataAdapter(StrSQL, MyCon)
DS = New DataSet
DA.Fill(DS, "Tb01")
'---------------------------------------------------------------------------
Dim StrSQL2 As String = "select * from Tb02"
DA2 = New OleDbDataAdapter(StrSQL2, MyCon)
DS2 = New DataSet
DA2.Fill(DS2, "Tb02")
'---------------------------------------------------------------------------
d1.Text = ""
d2.Text = ""
d3.Text = ""
d4.Text = ""
d5.Text = ""
d6.Text = ""
d7.Text = ""
d8.Text = ""
d9.Text = ""
d10.Text = ""
d11.Text = ""
d12.Text = ""
d13.Text = ""
d14.Text = ""
d15.Text = ""
d16.Text = ""
d17.Text = ""
d18.Text = ""
d19.Text = ""
d20.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
d1.Text = ""
d2.Text = ""
d3.Text = ""
d4.Text = ""
d5.Text = ""
d6.Text = ""
d7.Text = ""
d8.Text = ""
d9.Text = ""
d10.Text = ""
d11.Text = ""
d12.Text = ""
d13.Text = ""
d14.Text = ""
d15.Text = ""
d16.Text = ""
d17.Text = ""
d18.Text = ""
d19.Text = ""
d20.Text = ""
Label1.Text = ""
Dim sumAi As Integer
Dim sumAi2 As Integer
Dim sumBi2 As Integer
Dim sumAB(10, 50) As Integer
Dim netAB(10, 50) As Double
Dim n As Integer = txt01.Text
Dim i As Integer = n - 1
l1.Text = DS.Tables(0).Rows(i).Item(0)
l2.Text = DS.Tables(0).Rows(i).Item(1)
l3.Text = DS.Tables(0).Rows(i).Item(2)
l4.Text = DS.Tables(0).Rows(i).Item(3)
l5.Text = DS.Tables(0).Rows(i).Item(4)
l6.Text = DS.Tables(0).Rows(i).Item(5)
l7.Text = DS.Tables(0).Rows(i).Item(6)
l8.Text = DS.Tables(0).Rows(i).Item(7)
l9.Text = DS.Tables(0).Rows(i).Item(8)
l10.Text = DS.Tables(0).Rows(i).Item(9)
l11.Text = DS.Tables(0).Rows(i).Item(10)
l12.Text = DS.Tables(0).Rows(i).Item(11)
l13.Text = DS.Tables(0).Rows(i).Item(12)
l14.Text = DS.Tables(0).Rows(i).Item(13)
l15.Text = DS.Tables(0).Rows(i).Item(14)
l16.Text = DS.Tables(0).Rows(i).Item(15)
l17.Text = DS.Tables(0).Rows(i).Item(16)
l18.Text = DS.Tables(0).Rows(i).Item(17)
l19.Text = DS.Tables(0).Rows(i).Item(18)
l20.Text = DS.Tables(0).Rows(i).Item(19)
For j = 0 To 19 Step 1
'- หาผลรวม A
sumAi += DS.Tables(0).Rows(i).Item(j)
'-หาผลรวม A ยก กำลัง2
sumAi2 += DS.Tables(0).Rows(i).Item(j) * DS.Tables(0).Rows(i).Item(j)
Next
Label1.Text &= "คนที่ " & n & "เมื่อเที้ยบกับ 50 คน" & vbNewLine & vbNewLine
For k = 0 To 49 Step 1
For l = 0 To 19 Step 1
'-หาผลรมของ B ยกกำลัง 2
sumBi2 += DS2.Tables(0).Rows(k).Item(l) * DS2.Tables(0).Rows(k).Item(l)
'- หาผลคูณของ Aรวม x B
sumAB(i, k) = sumAi * DS2.Tables(0).Rows(k).Item(l)
Next
'-หาผลต่างระหว่าง sumA*B/ร่างที่สองของ A,B ยกกำลัง 2
netAB(i, k) = (sumAB(i, k) / (Math.Sqrt(sumAi2) * Math.Sqrt(sumBi2)))
If netAB(i, k) > max1 Then
max1 = netAB(i, k)
pre1 = k + 1
ElseIf netAB(i, k) > max2 Then
max2 = netAB(i, k)
pre2 = k + 1
ElseIf netAB(i, k) > max3 Then
max3 = netAB(i, k)
pre3 = k + 1
End If
Label1.Text &= netAB(i, k).ToString("0.00") & " , "
Next
Label1.Text &= vbNewLine & vbNewLine
Label1.Text &= "คล้ายกับคนที่ " & pre1.ToString("00") & " เท่ากับ " & max1.ToString("0.00") & vbNewLine
Label1.Text &= "คล้ายกับคนที่ " & pre2.ToString("00") & " เท่ากับ " & max2.ToString("0.00") & vbNewLine
Label1.Text &= "คล้ายกับคนที่ " & pre3.ToString("00") & " เท่ากับ " & max3.ToString("0.00") & vbNewLine
Label1.Text &= vbNewLine & vbNewLine
'-เปลี่ยนเทียบสินค้า
Dim m(20) As Integer
Dim maxP1 As Integer
Dim maxP2 As Integer
Dim maxP3 As Integer
Dim p1 As Integer
Dim p2 As Integer
Dim p3 As Integer
Dim x(20) As Integer
For p = 0 To 19 Step 1
If DS.Tables(0).Rows(i).Item(p) = "0" Then
m(p) = DS2.Tables(0).Rows(pre1).Item(p) + DS2.Tables(0).Rows(pre2).Item(p) + DS2.Tables(0).Rows(pre3).Item(p)
End If
Next
For p = 0 To 19 Step 1
If m(p) > maxP1 Then
maxP1 = m(p)
p1 = p + 1
ElseIf m(p) > maxP2 Then
maxP2 = m(p)
p2 = p + 1
ElseIf m(p) > maxP3 Then
maxP3 = m(p)
p3 = p + 1
End If
Next
Label1.Text &= "สินค้าชิ้นที่ " & (p1).ToString("00") & " มีจำนวนที่เหมือน " & maxP1 & " ชิ้น " & vbNewLine
Label1.Text &= "สินค้าชิ้นที่ " & (p2).ToString("00") & " มีจำนวนที่เหมือน " & maxP2 & " ชิ้น " & vbNewLine
Label1.Text &= "สินค้าชิ้นที่ " & (p3).ToString("00") & " มีจำนวนที่เหมือน " & maxP2 & " ชิ้น " & vbNewLine
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim n As Integer
Dim a(20) As Integer
Dim b(20) As Integer
Dim pro(20) As Integer
Dim sumN As Integer
n = txt01.Text - 1
lb5.Text = ""
d1.Text = DS.Tables(0).Rows(n).Item(0)
d2.Text = DS.Tables(0).Rows(n).Item(1)
d3.Text = DS.Tables(0).Rows(n).Item(2)
d4.Text = DS.Tables(0).Rows(n).Item(3)
d5.Text = DS.Tables(0).Rows(n).Item(4)
d6.Text = DS.Tables(0).Rows(n).Item(5)
d7.Text = DS.Tables(0).Rows(n).Item(6)
d8.Text = DS.Tables(0).Rows(n).Item(7)
d9.Text = DS.Tables(0).Rows(n).Item(8)
d10.Text = DS.Tables(0).Rows(n).Item(9)
d11.Text = DS.Tables(0).Rows(n).Item(10)
d12.Text = DS.Tables(0).Rows(n).Item(11)
d13.Text = DS.Tables(0).Rows(n).Item(12)
d14.Text = DS.Tables(0).Rows(n).Item(13)
d15.Text = DS.Tables(0).Rows(n).Item(14)
d16.Text = DS.Tables(0).Rows(n).Item(15)
d17.Text = DS.Tables(0).Rows(n).Item(16)
d18.Text = DS.Tables(0).Rows(n).Item(17)
d19.Text = DS.Tables(0).Rows(n).Item(18)
d20.Text = DS.Tables(0).Rows(n).Item(19)
a(0) = (l1.Text)
a(1) = (l2.Text)
a(2) = (l3.Text)
a(3) = (l4.Text)
a(4) = (l5.Text)
a(5) = (l6.Text)
a(6) = (l7.Text)
a(7) = (l8.Text)
a(8) = (l9.Text)
a(9) = (l10.Text)
a(10) = (l11.Text)
a(11) = (l12.Text)
a(12) = (l13.Text)
a(13) = (l14.Text)
a(14) = (l15.Text)
a(15) = (l16.Text)
a(16) = (l17.Text)
a(17) = (l18.Text)
a(18) = (l19.Text)
a(19) = (l20.Text)
For i = 0 To 19 Step 1
If a(i) = DS.Tables(0).Rows(n).Item(i) Then
Else
If DS.Tables(0).Rows(n).Item(i) = 1 Then
pro(i) = 1
sumN += 1
End If
End If
Next
lb5.Text &= " สินค้าแนะนำใหม่" & vbNewLine
For i = 0 To 19 Step 1
If pro(i) = 1 Then
lb5.Text &= " แนะนำสินค้าชื้นที่ " & (i + 1).ToString("00") & vbNewLine
End If
Next
txtS.Text = sumN
txtTNum.Text = sumN
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim t As Integer = txtTS.Text
Dim tNum As Integer = txtTNum.Text
Dim nt As Integer = txtNT.Text
Dim s As Integer = txtS.Text
Dim p As Double
Dim recall As Double
Dim f As Double
p = t / tNum
recall = nt / s
f = (2 * p * recall) / (p + recall)
lbP.Text = p.ToString("0.##")
lbRecall.Text = recall.ToString("0.##")
lbF.Text = f.ToString("0.##" & "%")
End Sub
End Class
Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery, CakePHP