Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I using TextLoader wrong when running the ML.Net Iris demo in F#?

Tags:

f#

ml.net

I am new to F#/.NET and I am trying to run the F# example provided in the accepted answer of How to translate the intro ML.Net demo to F#? with the ML.NET library, using F# on Visual Studio, using Microsoft.ML (0.2.0).

When building it I get the error error FS0039: The type 'TextLoader' is not defined.

To avoid this, I added the line

open Microsoft.ML.Data

to the source. Then, however, the line

pipeline.Add(new TextLoader<IrisData>(dataPath,separator = ","))

triggers: error FS0033: The non-generic type 'Microsoft.ML.Data.TextLoader' does not expect any type arguments, but here is given 1 type argument(s)

Changing to:

pipeline.Add(new TextLoader(dataPath,separator = ","))

yields: error FS0495: The object constructor 'TextLoader' has no argument or settable return property 'separator'. The required signature is TextLoader(filePath: string) : TextLoader.

Changing to:

pipeline.Add(new TextLoader(dataPath))

makes the build successful, but the code fails when running with ArgumentOutOfRangeException: Column #1 not found in the dataset (it only has 1 columns), I assume because the comma separator is not correctly picked up (incidentally, you can find and inspect the iris dataset at https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data).

Also

pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))

won't work.

I understand that there have been changes in TextLoader recently (see e.g. https://github.com/dotnet/machinelearning/issues/332), can somebody point me to what I am doing wrong?

like image 782
Davide Fiocco Avatar asked Mar 05 '23 23:03

Davide Fiocco


1 Answers

F# just has a bit of a different syntax that can take some getting used to. It doesn't use the new keyword to instantiate a new class and to use named parameters it uses the = instead of : that you would in C#.

So for this line in C#:

pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))

It would be this in F#:

pipeline.Add(TextLoader(dataPath).CreateFrom<IrisData>(separator=','))
like image 179
Jon Avatar answered Apr 07 '23 06:04

Jon