I'm looking at a the cs file here:
https://www.microsoft.com/net/learn/apps/machine-learning-and-ai/ml-dotnet/get-started/windows
and in my attempt to translate it to F# it compiles just fine but throws a System.Reflection.TargetInvocationException
when run: FormatException: One of the identified items was in an invalid format
. What am I missing?
Editted: Was using records before
open Microsoft.ML
open Microsoft.ML.Runtime.Api
open Microsoft.ML.Trainers
open Microsoft.ML.Transforms
open System
type IrisData =
[<Column("0")>] val mutable SepalLength : float
[<Column("1")>] val mutable SepalWidth : float
[<Column("2")>] val mutable PetalLength : float
[<Column("3")>] val mutable PetalWidth : float
[<Column("4");ColumnName("Label")>] val mutable Label : string
new(sepLen, sepWid, petLen, petWid, label) =
{ SepalLength = sepLen
SepalWidth = sepWid
PetalLength = petLen
PetalWidth = petWid
Label = label }
type IrisPrediction =
[<ColumnName("PredictedLabel")>] val mutable PredictedLabels : string
new() = { PredictedLabels = "Iris-setosa" }
[<EntryPoint>]
let main argv =
let pipeline = new LearningPipeline()
let dataPath = "iris.data.txt"
pipeline.Add(new TextLoader<IrisData>(dataPath,separator = ","))
pipeline.Add(new Dictionarizer("Label"))
pipeline.Add(new ColumnConcatenator("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"))
pipeline.Add(new StochasticDualCoordinateAscentClassifier())
pipeline.Add(new PredictedLabelColumnOriginalValueConverter(PredictedLabelColumn = "PredictedLabel") )
let model = pipeline.Train<IrisData, IrisPrediction>()
let prediction = model.Predict(IrisData(3.3, 1.6, 0.2, 5.1,""))
Console.WriteLine("Predicted flower type is: {prediction.PredictedLabels}")
0 // return an integer exit code
IrisData
andIrisPrediction
classes used in the tutorial are custom types (POCOs), not F# records used in your code. – Causeriepublic
as in C#. – Causerie