f# - 在 F# 中运行 ML.Net Iris 演示时,我是否使用了错误的 TextLoader?
问题描述
我是 F#/.NET 的新手,我正在尝试运行如何将介绍 ML.Net 演示转换为 F#?使用ML.NET 库,在 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/找到并检查 iris 数据集机器学习数据库/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=','))
推荐阅读
- javascript - 即使实现了 .setOffset(),使用功能组件创建的动画 PanResponder 也会跳转动画
- c++ - 如何将 OpenCV 与 MATLAB for macOS 链接
- php - 如果不包含某些字符串,则替换某些子值?还是重写 XPATH 查询?网站抓取
- python - 如何让python读取机器人在discord上发送的消息
- javascript - CSS-HTML:使用 html 和 css 将图像放在另一个图像之上
- ubuntu - 使用 Ubuntu makefile 编译 Latex 项目的连续命令
- java - 服务层上的异步java方法
- cakebuild - 加载 Cake.Bakery.exe 时 OmniSharp 挂起
- javascript - 获取从 FlatList 呈现的项目总数,然后根据项目状态更改更新该数字
- c++ - 比较存储在二维数组中的字符 c++/c