This blog post shows the F# code that works for ML.NET. The code below read a text file with salary data. Trainer the model and predict the Salary. You can watch the original video in the link below.
open System
open Microsoft.ML
open Microsoft.ML.Data
let trainFile = “./SalaryTrain.csv”
let testFile = “./SalaryTest.csv”
type SalaryData = {
[<LoadColumn(0)>]
YearsExperience: float32;
[<LoadColumn(1)>]
Salary: float32;
}
[<CLIMutable>]
type SalaryPrediction = {
[<ColumnName(“Score”)>]
PredictedSalary: float32;
[<EntryPoint>]
let main argv =
let context = MLContext()
let loadDataByPath path =
context.Data.LoadFromTextFile<SalaryData>(path, hasHeader=true, separatorChar=‘,’)
let trainData = loadDataByPath trainFile
let testData = loadDataByPath testFile
let pipeline =
EstimatorChain()
.Append(context.Transforms.Concatenate(“Features”, “YearsExperience”))
.Append(context.Transforms.CopyColumns((“Label”, “Salary”)))
.Append(context.Regression.Trainers.LbfgsPoissonRegression())
printfn “Training model…”
let model = pipeline.Fit trainData
let predictions = model.Transform testData
printfn “Evaluating model…”
let metrics = context.Regression.Evaluate(predictions, “Label”, “Score”)
printfn “RMS – %.2f” metrics.RootMeanSquaredError
printfn “R^2 – %.2f” metrics.RSquared
let predictionFunc = context.Model.CreatePredictionEngine<SalaryData, SalaryPrediction>(model)
let salaryPrediction = {
YearsExperience = 8.0f
Salary = 0.0f
}
let prediction = predictionFunc.Predict(salaryPrediction)
printfn “Prediction – %.2f” prediction.PredictedSalary
Console.ReadLine() |> ignore
0
You will going to get the result below when you run the code. Do play around with the value and model.

Code download for this article only: https://github.com/chanmmn/ByOtherDeveloper/tree/main/FSharpRegression?WT.mc_id=DP-MVP-36769
Other code download: https://github.com/jwood803/MLNetExamples?WT.mc_id=DP-MVP-36769
Video: https://www.youtube.com/watch?v=PVJMX-iD0no&t=4s?WT.mc_id=DP-MVP-36769