-
-
Save elbruno/387904adeb425a914b3ffd97c1c23515 to your computer and use it in GitHub Desktop.
MLNet060SampleProgram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
var dataPath = "AgeRangeData.csv"; | |
var env = new LocalEnvironment(); | |
var reader = TextLoader.CreateReader(env, ctx => ( | |
Age: ctx.LoadFloat(1), | |
Label: ctx.LoadText(3)), | |
separator: ',', hasHeader: true); | |
var trainData = reader.Read(new MultiFileSource(dataPath)); | |
var classification = new MulticlassClassificationContext(env); | |
var learningPipeline = reader.MakeNewEstimator() | |
.Append(r => ( | |
r.Label, | |
Predictions: classification.Trainers.Sdca | |
(label: r.Label.ToKey(), | |
features: r.Age.AsVector()))) | |
.Append(r => r.Predictions.predictedLabel.ToValue()); | |
var model = learningPipeline.Fit(trainData); | |
var predictionFunc = model.AsDynamic.MakePredictionFunction<AgeRangeNewApi, AgeRangePredictionNewApi>(env); | |
var example = new AgeRangeNewApi() | |
{ | |
Age = 6, | |
Name = "John", | |
Gender = "M" | |
}; | |
var prediction = predictionFunc.Predict(example); | |
Console.WriteLine("prediction: " + prediction.PredictedLabel); | |
Console.ReadLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment