#MLNET – Loading Data In our LearningPipeline With List (Lists for ever!)

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


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

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: