我有4个集群(0,1,2,3)和来自某个类(0级,1级,2级)的大量数据。数据如下所示。
(cluster, class) number of data
(0,0) 1
(0,1) 2
(0,2) 2
(1,0) 0
(1,1) 0
(1,2) 0
(2,0) 0
(2,1) 0
(2,2) 1
(3,0) 4
(3,1) 3
(3,2) 0
我想为每个群集提供类名。
这个想法是,某个集群的名称将是该类的名称,其中最常出现具有特定类别的数据的数量。
我想给群集命名,所以名称将如下所示。
任何人都可以帮助如何在VB.NET中解决这个问题?谢谢
cluster class
0 1
1
2 2
3 0
答案 0 :(得分:1)
您可以做的是创建一个"自定义数组对象"像这样:
Public Class DataArray(Of T)
Public Sub New(rowCount As Integer, columnCount As Integer)
If (rowCount < 0) Then
Throw New ArgumentOutOfRangeException("rowCount")
ElseIf (columnCount < 0) Then
Throw New ArgumentOutOfRangeException("columnCount")
End If
Me.array = New T((rowCount - 1), (columnCount - 1)) {}
Me.names = New String(rowCount - 1) {}
Me.rowCount = rowCount
Me.columnCount = columnCount
End Sub
Default Public Property Item(rowIndex As Integer, columnIndex As Integer) As T
Get
Return Me.array(rowIndex, columnIndex)
End Get
Set(value As T)
Me.array(rowIndex, columnIndex) = value
End Set
End Property
Public Property Cluster(rowIndex As Integer) As String
Get
Dim s As String = Me.names(rowIndex)
Return If((s Is Nothing), String.Empty, s)
End Get
Set(value As String)
Me.names(rowIndex) = If((value Is Nothing), String.Empty, value)
End Set
End Property
Public Sub [Set](rowIndex As Integer, values As T(), name As String)
For i As Integer = 0 To (values.Length - 1)
Me.array(rowIndex, i) = values(i)
Next
Me.names(rowIndex) = name
End Sub
Private ReadOnly array As T(,)
Private ReadOnly names As String()
Private ReadOnly rowCount As Integer
Private ReadOnly columnCount As Integer
End Class
现在,如果我创建一个包含4行(0,1,2,3)
和3列(0,1,2)
数据类型Integer
的数组:
Dim data As New DataArray(Of Integer)(4, 3)
并填充一些数据:
data.[Set](0, {0, 1, 2}, "Cluster 0")
data.[Set](1, {0, 0, 0}, "Cluster 1")
data.[Set](2, {0, 0, 1}, "Cluster 2")
data.[Set](3, {4, 3, 0}, "Cluster 3")
我也可以像你一样设置值:
data(0, 0) = 1
data(0, 1) = 2
data(0, 2) = 2
data(1, 0) = 0
data(1, 1) = 0
data(1, 2) = 0
data(2, 0) = 0
data(2, 1) = 0
data(2, 2) = 1
data(3, 0) = 4
data(3, 1) = 3
data(3, 2) = 0
并命名每个群集:
data.Cluster(0) = "Cluster 0"
data.Cluster(1) = "Cluster 1"
data.Cluster(2) = "Cluster 2"
data.Cluster(3) = "Cluster 3"