代码之家  ›  专栏  ›  技术社区  ›  Davide Fiocco

在f_中运行ml.net iris演示时,使用textloader是否错误?

  •  5
  • Davide Fiocco  · 技术社区  · 6 年前

    我对f/.net还不熟悉,我正在尝试运行f示例,该示例在接受的答案中提供 How to translate the intro ML.Net demo to 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 )有人能指出我做错了什么吗?

    1 回复  |  直到 6 年前
        1
  •  8
  •   Jon    6 年前

    F只是有一点不同的语法,需要一些适应。它不使用 new 关键字来实例化一个新类,并使用它使用的命名参数 = 而不是 : 你会用C写的。

    因此,对于C中的这一行:

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

    这就是F:

    pipeline.Add(TextLoader(dataPath).CreateFrom<IrisData>(separator=','))
    
    推荐文章