我是F#/ .NET的新手,我正在尝试运行使用How to translate the intro ML.Net demo to F#?的ML.NET library接受的答案中提供的F#示例,在Visual Studio上使用F#,使用Microsoft.ML( 0.2.0)。
构建时,我收到错误error FS0039: The type 'TextLoader' is not defined.
为避免这种情况,我添加了一行
open Microsoft.ML.Data
来源。 然而,那条线
pipeline.Add(new TextLoader<IrisData>(dataPath,separator = ","))
触发器:
error FS0033: The non-generic type 'Microsoft.ML.Data.TextLoader' does not expect any type arguments, but here is given 1 type argument(s)
更改为:
pipeline.Add(new TextLoader(dataPath,separator = ","))
收率:
error FS0495: The object constructor 'TextLoader' has no argument or settable return property 'separator'. The required signature is TextLoader(filePath: string) : TextLoader.
更改为:
pipeline.Add(new TextLoader(dataPath))
使构建成功,但代码在运行时失败
ArgumentOutOfRangeException: Column #1 not found in the dataset (it only has 1 columns)
,我假设因为未正确选取逗号分隔符(顺便提一下,您可以在https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data处找到并检查虹膜数据集)。
另外
pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))
没有工作。
我了解最近TextLoader
发生了变化(例如https://github.com/dotnet/machinelearning/issues/332),是否有人能指出我做错了什么?
答案 0 :(得分:8)
F#只是有一些不同的语法可能需要一些时间来习惯。它没有使用new
关键字来实例化新类,并且使用命名参数,它使用{C}中的=
而不是:
。
所以对于C#中的这一行:
pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))
这将是F#:
pipeline.Add(TextLoader(dataPath).CreateFrom<IrisData>(separator=','))