使用现有的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 团队。