Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

65 lines (46 sloc) 1.73 KB
open System
open Microsoft.ML
open Microsoft.ML.Data
let trainFile = "./SalaryTrain.csv"
let testFile = "./SalaryTest.csv"
type SalaryData = {
YearsExperience: float32;
Salary: float32;
type SalaryPrediction = {
PredictedSalary: float32;
let main argv =
let context = MLContext()
let loadDataByPath path =
context.Data.LoadFromTextFile<SalaryData>(path, hasHeader=true, separatorChar=',')
//let trainData = context.Data.LoadFromTextFile<SalaryData>(trainFile, hasHeader=true, separatorChar=',')
//let testData = context.Data.LoadFromTextFile<SalaryData>(testFile, hasHeader=true, separatorChar=',')
let trainData = loadDataByPath trainFile
let testData = loadDataByPath testFile
let pipeline =
.Append(context.Transforms.Concatenate("Features", "YearsExperience"))
.Append(context.Transforms.CopyColumns(("Label", "Salary")))
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
You can’t perform that action at this time.