StevieBee Ответов: 0

Ml.net с помощью VB.NET - многочисленные вопросы


Ниже приводится моя первая попытка использовать ML.Net с VB.Сеть через
Microsoft Visual Studio Community 2017 
Version 15.8.1
VisualStudio.15.Release/15.8.1+28010.2003
Microsoft .NET Framework
Version 4.7.03056


1. Почему я вижу
oPrediction(Setosa).Label = 1
oPrediction(versicolor).Label = 1
oPrediction(virginica).Label = 1

а почему бы и нет?
oPrediction(Setosa).Label = Iris-setosa
oPrediction(versicolor).Label = Iris-versicolor
oPrediction(virginica).Label = Iris-virginica


2. Как я могу проверить iris-data.txt файл действительно читается?
Причина, по которой я спрашиваю, заключается в том, что я неправильно написал имя, и там не было никакой ошибки.

3. Почему я вижу "систему.Об: колонке 'счет 'счет' не найдены. Имя параметра: имя' когда тестовый раздел раскомментирован?

4. я видел детали предварительного просмотра, используемые в C#, предоставляющие детали модели (веса и смещения).
Как мне включить ВКЛ VB.Net-что?

Option Explicit On

Imports Microsoft.ML
Imports Microsoft.ML.Runtime.Api
Imports Microsoft.ML.Runtime.Data
Imports Microsoft.ML.Runtime.Learners
Imports Microsoft.ML.Transforms.Conversions
Imports System
Imports System.IO

Public Class frmMain

    Private Sub btnIRIS_Click(sender As Object, e As EventArgs) Handles btnIRIS.Click
        Dim sPath As String = "C:\VBnet bespoke\MachineLearning\MachineLearning\dat"
        Dim sTrainingDataFile As String = sPath & "\iris-data.txt"
        Dim sTestDataFile As String = sPath & "\iris-data.txt"

        Dim mlContext As New MLContext()

        ' ------------------------------------------------------------------------------------------------------------------------------
        ' Train
        ' ------------------------------------------------------------------------------------------------------------------------------

        ' Define how to read what from the file
        Dim oTextReader = mlContext.Data.TextReader(New TextLoader.Arguments() With
                                        {
                                          .Separator = "," _
                                        , .HasHeader = False _
                                        , .Column = {New TextLoader.Column("SepalLength", DataKind.R4, 0),              ' seems values have to be Single & not Double (ie can't use R8)
                                                        New TextLoader.Column("SepalWidth", DataKind.R4, 1),
                                                        New TextLoader.Column("PetalLength", DataKind.R4, 2),
                                                        New TextLoader.Column("PetalWidth", DataKind.R4, 3),
                                                        New TextLoader.Column("Label", DataKind.TX, 4)
                                                    }
                                        })

        ' Define lazy (present only when needed) data view as read from Training Data file
        Dim oTrainingDataView = oTextReader.Read(sTrainingDataFile)

        'Debug.Print("Number of rows read from file" & Format(oTrainingDataView.GetRowCount))

        ' We're going to use "SepalLength", "SepalWidth", "PetalLength", "PetalWidth" as the known Features to train the network to predict Label
        Dim oPipeline = mlContext.Transforms.Concatenate("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")

        With oPipeline
            ' Normalize the data file feature values to ensure all are between -1 & +1
            .Append(mlContext.Transforms.Normalize("SepalLength"))
            .Append(mlContext.Transforms.Normalize("SepalWidth"))
            .Append(mlContext.Transforms.Normalize("PetalLength"))
            .Append(mlContext.Transforms.Normalize("PetalWidth"))

            ' Ensure the text value is mapped to a numeric (single,R4) value (just an index into the list of possible label text values).
            .Append(mlContext.Transforms.Categorical.MapValueToKey("Label"))

            ' Given the features & the corresponding known label, use SDCA to train the network by deriving best weights & biases
            .Append(mlContext.MulticlassClassification.Trainers.StochasticDualCoordinateAscent(label:="Label", features:="Features"))

            ' Output from network is a number so convert back to the appropriate string describing the flower
            .Append(mlContext.Transforms.Conversion.MapKeyToValue(("PredictedLabel", "Label")))
        End With

        Dim oModel = oPipeline.Fit(oTrainingDataView)

        ' ------------------------------------------------------------------------------------------------------------------------------
        ' Test
        ' ------------------------------------------------------------------------------------------------------------------------------

        Dim oTestData = oTextReader.Read(sTestDataFile)
        Dim oTestPredictions = oModel.Transform(oTestData)
        Dim oMetrics = mlContext.MulticlassClassification.Evaluate(oTestPredictions, label:="Label")

        Debug.Print("AccurancyMicro = " & Format(oMetrics.AccuracyMicro, "#.######"))

        ' ------------------------------------------------------------------------------------------------------------------------------
        ' Predict
        ' ------------------------------------------------------------------------------------------------------------------------------

        Dim oIRIS_Data As New Iris_Data
        Dim oIRIS_Prediction As New Iris_Prediction

        ' 5.1,3.5,1.4,0.2,Iris-Setosa
        Dim oPredictionSetosa = oModel.MakePredictionFunction(Of Iris_Data, Iris_Prediction)(mlContext).Predict _
                (New Iris_Data With {.SepalLength = 5.1, .SepalWidth = 3.5, .PetalLength = 1.4, .PetalWidth = 0.2, .Label = vbNull})
        ' Label seems to have to be vbNull. If missing nothing returned. If a non-null value then same is returned.

        Debug.Print("oPrediction(Setosa).Label = " & oPredictionSetosa.Label)

        ' 7.0,3.2,4.7,1.4,Versicolor (from file)
        Dim oPredictionVersicolor = oModel.MakePredictionFunction(Of Iris_Data, Iris_Prediction)(mlContext).Predict _
                (New Iris_Data With {.SepalLength = 7.0, .SepalWidth = 3.2, .PetalLength = 4.7, .PetalWidth = 1.4, .Label = vbNull})
        ' Label seems to have to be vbNull. If missing nothing returned. If a non-null value then same is returned.

        Debug.Print("oPrediction(ersicolor).Label = " & oPredictionVersicolor.Label)

        '6.3,3.3,6.0,2.5,Iris-virginica
        Dim oPredictionVirginica = oModel.MakePredictionFunction(Of Iris_Data, Iris_Prediction)(mlContext).Predict _
                (New Iris_Data With {.SepalLength = 6.3, .SepalWidth = 3.3, .PetalLength = 6.0, .PetalWidth = 2.5, .Label = vbNull})
        ' Label seems to have to be vbNull. If missing nothing returned. If a non-null value then same is returned.

        Debug.Print("oPrediction(virginica).Label = " & oPredictionVirginica.Label)
    End Sub
End Class

Public Class Iris_Data
    Public SepalLength As Single
    Public SepalWidth As Single
    Public PetalLength As Single
    Public PetalWidth As Single

    <ColumnName("Label")>
    Public Label As String
End Class

Public Class Iris_Prediction
    <ColumnName("Label")>
    Public Label As String
End Class


Вся помощь/указатели приветствуются.

Что я уже пробовал:

Я выудил кое-какую информацию из
https://docs.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/single-predict-model-ml-net
https://docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/taxi-fare
https://docs.microsoft.com/en-us/dotnet/machine-learning/resources/transforms#normalization
https://blogs.msdn.microsoft.com/dotnet/2018/10/08/announcing-ml-net-0-6-machine-learning-net/
https://github.com/dotnet/machinelearning/blob/master/docs/code/MlNetCookBook.md

0 Ответов