我找到的ML.Net示例都使用TextLoader通过csv或类似方式加载数据。
如何在不使用TextLoader的情况下将数据加载到训练器中,
我正在将大量数据流式传输到一个List中
var pipeline = new LearningPipeline{ new Microsoft.ML.Data.TextLoader(_datapath).CreateFrom<Match>(useHeader: true, separator: ','), …
是否有接受T[]的实现?持续将csv文件写入磁盘似乎是很多不必要的IO,从持续的角度来看,特别是如果训练函数锁定了文件。意味着每个活跃的训练实例需要多个文件。
回答:
使用现有的LearningPipeline
API,可以使用CollectionDataSource
来训练已经在内存中的数据:
var pipeline = new LearningPipeline();var data = new List<IrisData>() { new IrisData { SepalLength = 1f, SepalWidth = 1f, PetalLength=0.3f, PetalWidth=5.1f, Label=1}, new IrisData { SepalLength = 1f, SepalWidth = 1f, PetalLength=0.3f, PetalWidth=5.1f, Label=1}, new IrisData { SepalLength = 1.2f, SepalWidth = 0.5f, PetalLength=0.3f, PetalWidth=5.1f, Label=0}};var collection = CollectionDataSource.Create(data);pipeline.Add(collection);pipeline.Add(new ColumnConcatenator(outputColumn: "Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));pipeline.Add(new StochasticDualCoordinateAscentClassifier());var model = pipeline.Train<IrisData, IrisPrediction>();
示例来自这里。
随着即将推出的新的ML.NET API,这将发生变化,并将提供新的示例来展示如何做到这一点。
注:我是ML.NET团队的一员。