-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathProgram.cs
More file actions
39 lines (31 loc) · 1.22 KB
/
Copy pathProgram.cs
File metadata and controls
39 lines (31 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Microsoft.ML;
using Microsoft.ML.Runtime.Data;
using Microsoft.ML.StaticPipe;
using Microsoft.ML.Trainers;
using Microsoft.ML.Transforms;
using System;
namespace SimpleRegression
{
class Program
{
static void Main(string[] args)
{
var context = new MLContext();
var reader = TextLoader.CreateReader(context, ctx => (
YearsExperience: ctx.LoadFloat(0),
Salary: ctx.LoadFloat(1)
), hasHeader: true, separator: ',');
var data = reader.Read(new MultiFileSource("SalaryData.csv"));
var pipeline = reader.MakeNewEstimator()
.Append(r => (
r.Salary,
Prediction: context.Regression.Trainers.Sdca(label: r.Salary, features: r.YearsExperience.AsVector())
));
var model = pipeline.Fit(data).AsDynamic;
var predictionFunc = model.MakePredictionFunction<SalaryData, SalaryPrediction>(context);
var prediction = predictionFunc.Predict(new SalaryData { YearsExperience = 8 });
Console.WriteLine($"Predicted salary - {String.Format("{0:C}", prediction.PredictedSalary)}");
Console.Read();
}
}
}