我正在尝试编写一个基本的“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#float32
,而double
等效于F#float
。因此,尝试将float
替换为float32
或single
,并将0.0
替换为0.0f
。float32
在F#中也称为single
float
等效于F#single
或float32
double
等效于F#float
或double
关于f# - 未处理的异常:System.ArgumentOutOfRangeException:功能列'Features'的架构不匹配:预期的Vector <R4>,获得了Vector <R8>,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54820002/