Hi !

Today post fast that the code is self explanatory.

First, based on the previous posts, the process of defining and training the model. The important thing happens on lines 15 and 16, where the model is recorded.


class Program
{
static void Main(string[] args)
{
var agesRangesCsv = "AgeRangeData.csv";
var pipeline = new LearningPipeline();
pipeline.Add(new TextLoader<AgeRangeData>(agesRangesCsv, separator: ","));
pipeline.Add(new Dictionarizer("Label"));
pipeline.Add(new ColumnConcatenator("Features", "AgeStart", "AgeEnd"));
pipeline.Add(new StochasticDualCoordinateAscentClassifier());
pipeline.Add(new PredictedLabelColumnOriginalValueConverter {PredictedLabelColumn = "PredictedLabel"});
var model = pipeline.Train<AgeRangeData, AgeRangePrediction>();
var modelFilePath = "AgeRangeDataModel.zip";
model.WriteAsync(modelFilePath);
Console.ReadLine();
}
}

And then another project, where the engraved model is used. Attention to lines 18 to 21, from there the way to use the model is the same


class Program
{
private static string _modelFilePath = "AgeRangeDataModel.zip";
private static PredictionModel<AgeRangeData, AgeRangePrediction> _model;
static void Main(string[] args)
{
LoadModel();
var prediction = _model.Predict(new AgeRangeData()
{
AgeStart = 1,
AgeEnd = 2
});
Console.WriteLine($"Predicted age range is: {prediction.PredictedLabels}");
Console.ReadLine();
}
private static async void LoadModel()
{
_model = await PredictionModel.ReadAsync<AgeRangeData, AgeRangePrediction>(_modelFilePath);
}
}

Happy Coding!

Greetings @ Toronto

El Bruno

References

My Posts

26 responses to “#MLNET – Write and Load models using Machine Learning .Net”

  1. […] Write and Load models using Machine Learning .Net […]

    Like

  2. […] Write and Load models using Machine Learning .Net […]

    Like

  3. […] Write and Load models using Machine Learning .Net […]

    Like

  4. […] Write and Load models using Machine Learning .Net […]

    Like

  5. […] Write and Load models using Machine Learning .Net […]

    Like

  6. […] Write and Load models using Machine Learning .Net […]

    Like

  7. […] Write and Load models using Machine Learning .Net […]

    Like

  8. […] Write and Load models using Machine Learning .Net […]

    Like

  9. […] Write and Load models using Machine Learning .Net […]

    Like

Leave a reply to #MLNET – Exportando modelos de Machine Learning.Net a formato #ONNX – El Bruno Cancel reply

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading