f# - 在 F# 中运行 ML.Net Iris 演示时,我使用 TextLoader 是否错误?

标签 f# ml.net

我是 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/

相关文章:

python - FSharp 运行我的算法比 Python 慢

c# - 使用 C# 和 LightGBM 进行基于 GPU 的二元分类是否可行(还?)

c# - 显示哪个分数与哪个标签相关的 ML.Net 错误

machine-learning - Ml.NET - 基于某些属性预测部门

class - 在 F# 中使用私有(private)构造函数创建一个类

f# - 在异构列表上,是否可以使压缩然后解压缩与原始列表相同?

f# - 矩阵的内存不足异常

c# - 如何将 Serilog.Log.ForContext 与 F# 函数或 C# 方法一起使用

f# - 如何将 "Hello ML.NET World"示例翻译成 F#?

c# - 系统无效操作异常: The asynchronous operation has not completed