I am trying to write a basic 'hello world' type program to predict the values of the XOR function. This is the error message I am getting:
Unhandled Exception: System.ArgumentOutOfRangeException: Schema mismatch for feature column 'Features': expected Vector<R4>, got Vector<R8>
Parameter name: inputSchema This is my code:
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
Any pointers as to what I am doing wrong would be greatly appreciated.
It seems to be complaining about the size of float numbers. A C# float is equivalent to an F# float32 and a double is equivalent to an F# float. So try replacing your float with float32 or single, and 0.0 with 0.0f.
A float32 is also called a single in F#
float is equivalent to F# single or float32double is equivalent to F# float or doubleIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With