我正在尝试编写一个基本的“ 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
任何有关我做错事情的指针将不胜感激。
答案 0 :(得分:1)
似乎在抱怨浮点数的大小。 C#float
等效于F#float32
,而double
等效于F#float
。因此,请尝试将float
替换为float32
或single
,并将0.0
替换为0.0f
。
在F#中,float32
也称为single
float
等同于F#single
或float32
double
等同于F#float
或double