Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MLNet060SampleProgram.cs
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
You can’t perform that action at this time.