未处理的异常:System.ArgumentOutOfRangeException:特征列'Features'的架构不匹配:预期的Vector <r4>,得到了Vector <r8>

时间:2019-02-22 04:20:05

标签: f# ml.net

我正在尝试编写一个基本的“ 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

任何有关我做错事情的指针将不胜感激。

1 个答案:

答案 0 :(得分:1)

似乎在抱怨浮点数的大小。 C#float等效于F#float32,而double等效于F#float。因此,请尝试将float替换为float32single,并将0.0替换为0.0f

在F#中,float32也称为single

  • C#float等同于F#singlefloat32
  • C#double等同于F#floatdouble