Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

f#

ml.net

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.

like image 530
John Atwood Avatar asked Dec 03 '25 03:12

John Atwood


1 Answers

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#

  • C# float is equivalent to F# single or float32
  • C# double is equivalent to F# float or double
like image 158
AMieres Avatar answered Dec 06 '25 05:12

AMieres



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!