Hi!
In the last post about Machine Learning.Net I wrote about some of the novelties of the version 0.2.0. One interesting new feature allowed us to load data not only from a flat text file, like an Csv,. The new option allow us to work with objects within a collection.
The following code example shows us in the first lines the standard load option using a Flat Text File. Then from the line 10m, thew new feature using a collection of objects
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 fileName = "AgeRanges.csv"; | |
var pipeline = new LearningPipeline(); | |
// standard load from file | |
pipeline.Add(new TextLoader(fileName).CreateFrom<AgeRange>(separator: ',', useHeader: true)); | |
// load data from List<>() | |
var data = new List<AgeRange> | |
{ | |
new AgeRange { Name = "John", Age = 12, Sex = "M", Label = "boy"}, | |
new AgeRange { Name = "Laslo", Age = 2, Sex = "M", Label = "baby"}, | |
new AgeRange { Name = "Mary", Age = 16, Sex = "F", Label = "teenager"}, | |
new AgeRange { Name = "Gracie", Age = 6, Sex = "F", Label = "girl"} | |
}; | |
var collection = CollectionDataSource.Create(data); | |
pipeline.Add(collection); | |
} |
Plain text files are very useful, in the same way, having the opportunity to work with collections allows us to optimize our data loads process to be able to connect directly to a standard database or any other type of data repository.
Happy Coding!
Greetings @ Burlington
El Bruno
References
My Posts
20 comments