未处理的异常:System.ArgumentOutOfRangeException:特征列 'Features' 的模式不匹配:预期向量<R4>,得到向量<R8>

Unhandled Exception: System.ArgumentOutOfRangeException: Schema mismatch for feature column 'Features': expected Vector<R4>, got Vector<R8>

我正在尝试编写一个基本的 'hello world' 类型的程序来预测 XOR 函数的值。这是我收到的错误消息:

Unhandled Exception: System.ArgumentOutOfRangeException: Schema mismatch for feature column 'Features': expected Vector<R4>, got Vector<R8>

参数名称:inputSchema 这是我的代码:

type Sample = {
    X: float
    Y: float
    Result: float
}

let createSample x y result = {X = x; Y = y; Result = result}

let solveXOR() =
    let problem = 
        [
            createSample 0.0 0.0 0.0
            createSample 1.0 0.0 1.0
            createSample 0.0 1.0 1.0
            createSample 1.0 0.0 0.0
        ]

    let context = new MLContext()
    let data = context.Data.ReadFromEnumerable(problem)

    let pipeline = 
        context.Transforms
            .Concatenate("Features", "X", "Y")
            .Append(context.Transforms.CopyColumns(inputColumnName = "Result", outputColumnName = "Label"))
            //.Append(context.Transforms.Conversion.MapKeyToVector("X"))
            //.Append(context.Transforms.Conversion.MapKeyToVector("Y"))
            .AppendCacheCheckpoint(context)
            .Append(context.Regression.Trainers.FastTree())

    let model = pipeline.Fit(data)

    let predictions = model.Transform(data)
    let metrics = context.BinaryClassification.Evaluate(predictions)

    printfn "Accuracy %f" metrics.Accuracy

任何关于我做错了什么的指示将不胜感激。

好像是在抱怨浮点数的大小。 C# float 等同于 F# float32double 等同于 F# float。因此,请尝试将 float 替换为 float32single,并将 0.0 替换为 0.0f

A float32 在 F#

中也称为 single
  • C# float 等同于 F# singlefloat32
  • C# double 等同于 F# floatdouble