C# 从字符串而不是文件输入的ml.net列车模型

C# 从字符串而不是文件输入的ml.net列车模型,c#,ml.net,C#,Ml.net,我一直在使用以下代码行加载文本数据: pipeline.Add(new TextLoader(dataPath).CreateFrom<SentimentData>(separator: ',')); pipeline.Add(新的文本加载器(数据路径).CreateFrom(分隔符:','); 但是有没有办法将字符串作为数据注入?假设我们想从数据库中获取模型,我不必先将字符串保存到文件中,或者我需要吗 目前的文档非常糟糕,但它也是微软给我们的一个闪亮的新工具 谢谢您将希望使用在

我一直在使用以下代码行加载文本数据:

pipeline.Add(new TextLoader(dataPath).CreateFrom<SentimentData>(separator: ','));
pipeline.Add(新的文本加载器(数据路径).CreateFrom(分隔符:',');
但是有没有办法将字符串作为数据注入?假设我们想从数据库中获取模型,我不必先将字符串保存到文件中,或者我需要吗

目前的文档非常糟糕,但它也是微软给我们的一个闪亮的新工具


谢谢

您将希望使用在ML.NET的v0.2中引入的CollectionDataSource。您可以获取新的github位或nuget,然后可以在可枚举项上使用CollectionDataSource

您可以在其测试中找到完整的示例:

关于Iris数据的一个示例:

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());
PredictionModel<IrisData, IrisPrediction> model = pipeline.Train<IrisData, IrisPrediction>();

IrisPrediction prediction = model.Predict(new IrisData()
{
    SepalLength = 3.3f,
    SepalWidth = 1.6f,
    PetalLength = 0.2f,
    PetalWidth = 5.1f,
});

pipeline = new LearningPipeline();
collection = CollectionDataSource.Create(data.AsEnumerable());
pipeline.Add(collection);
pipeline.Add(new ColumnConcatenator(outputColumn: "Features",
    "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"));
pipeline.Add(new StochasticDualCoordinateAscentClassifier());
model = pipeline.Train<IrisData, IrisPrediction>();
var数据=新列表(){
新IrisData{separalength=1f,separalWidth=1f,petalalength=0.3f,petalaWidth=5.1f,Label=1},
新IrisData{separalength=1f,separalWidth=1f,petalalength=0.3f,petalaWidth=5.1f,Label=1},
新IrisData{separalength=1.2f,separalWidth=0.5f,petalalength=0.3f,PetalWidth=5.1f,Label=0}
};
var collection=CollectionDataSource.Create(数据);
管道。添加(收集);
添加(新列连接符(outputColumn:“功能”),
“萼片长度”、“萼片宽度”、“花瓣长度”、“花瓣宽度”);
添加(新的随机DualCoordinateAscentClassifier());
PredictionModel=pipeline.Train();
IrisPrediction prediction=model.Predict(新的IrisData()
{
分离长度=3.3f,
分离宽度=1.6f,
花瓣长度=0.2f,
花瓣宽度=5.1f,
});
管道=新的LearningPipeline();
collection=CollectionDataSource.Create(data.AsEnumerable());
管道。添加(收集);
添加(新列连接符(outputColumn:“功能”),
“萼片长度”、“萼片宽度”、“花瓣长度”、“花瓣宽度”);
添加(新的随机DualCoordinateAscentClassifier());
model=pipeline.Train();

如何在0.10中执行此操作。正如这里所解释的,我在培训中遇到了问题,github代码与最新版本不一致