我是 F#/.NET 新手,我正在尝试运行 How to translate the intro ML.Net demo to F#? 接受的答案中提供的 F# 示例。与 ML.NET library ,在 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 ),有人可以指出我做错了什么吗?
最佳答案
F# 只是有一些不同的语法,需要一些时间来适应。它不使用 new
关键字来实例化新类,也不使用命名参数,而是使用 =
而不是您在其中使用的 :
C#。
对于 C# 中的这一行:
pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(separator: ','))
在 F# 中是这样的:
pipeline.Add(TextLoader(dataPath).CreateFrom<IrisData>(separator=','))
关于f# - 在 F# 中运行 ML.Net Iris 演示时,我使用 TextLoader 是否错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50910370/