ML.Net 数据加载器(内存)

ML.Net Data Loader (Memory)

我找到的ML.Net个例子都是用TextLoader通过csv之类的方式加载数据

如何在没有 TextLoader 的情况下将数据加载到训练器中,

我正在将大量数据流式传输到列表

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>();

样本取自here

随着即将推出的新 ML.NET API,这将会改变,并且将提供新示例来展示如何执行此操作。

注意:我在 ML.NET 团队。

可能与

重复

您可以使用 CollectionDataSource,在 ML.NET 的 0.2 版中引入。