我尝试使用ML.net,因为我使用了Web,我遵循了ML.net in https://learn.microsoft.com/es-es/dotnet/machine-learning/tutorials/taxi-fare教程的所有步骤
但是,当我尝试使用该服务时,我收到了一条消息:"Transforms.CategoricalHashOneHotVectorizer“未在行中找到
model = pipeline.Train<Trazability, TrazabilityPrediction>();我不知道如何在本教程中获得正确的响应,但是当我试图将相同的代码放在中时,就会发现这是错误的。
在这里,我做的代码:
类Program.cs
public class Program
{
const string _datapath = @".\Datos\Train.csv";
const string _testdatapath = @".\Datos\Test.csv";
const string _modelpath = @".\Datos\Model.zip";
public float predicion()
{
var prediccion = DuracionDias();
return float.Parse(prediccion.ToString());
}
public async Task<TrazabilityPrediction> DuracionDias() {
PredictionModel<Trazability, TrazabilityPrediction> model = await Train();
Evaluate(model);
TrazabilityPrediction prediction = model.Predict(TrazabilityTest.Prueba1);
return prediction;
}
public static async Task<PredictionModel<Trazability, TrazabilityPrediction>> Train()
{
PredictionModel<Trazability, TrazabilityPrediction> model = null;
try
{
var pipeline = new LearningPipeline();
pipeline.Add(new TextLoader(_datapath).CreateFrom<Trazability>(useHeader: true, separator: ';'));
pipeline.Add(new ColumnCopier(("duracionDias", "Label")));
pipeline.Add(new CategoricalHashOneHotVectorizer("producto", "proveedor"));
pipeline.Add(new ColumnConcatenator("Features", "producto", "proveedor", "peso"));
pipeline.Add(new FastTreeRegressor());
model = pipeline.Train<Trazability, TrazabilityPrediction>();
await model.WriteAsync(path: _modelpath);
}
catch(Exception e)
{
throw new Exception(e.Message);
}
return model;
}
private static void Evaluate(PredictionModel<Trazability, TrazabilityPrediction> model)
{
var testData = new TextLoader(_testdatapath).CreateFrom<Trazability>(useHeader: true, separator: ';');
var evaluator = new RegressionEvaluator();
RegressionMetrics metrics = evaluator.Evaluate(model, testData);
Console.WriteLine($"Rms = {metrics.Rms}");
Console.WriteLine($"RSquared = {metrics.RSquared}");
}
}下面是模型
public class Trazability
{
[Column("0")]
public string producto;
[Column("1")]
public string proveedor;
[Column("2")]
public float peso;
[Column("3")]
public float duracionDias;
}
public class TrazabilityPrediction
{
[ColumnName("Score")]
public float duracionDias;
}这里还有.csv (train.csv和test.csv)
producto;proveedor;peso;duracionDias
Azucar;Sol;10;12
Azucar;Sol;10;12
Azucar;Sol;10;12
Azucar;Sol;10;12
Azucar;Sol;10;12
Azucar;Sol;20;24
Azucar;Sol;20;24
Azucar;Sol;20;24
Azucar;Sol;20;24
Azucar;Sol;20;24
Colorante;Sol;10;12
Colorante;Sol;10;12
Colorante;Sol;10;12
Colorante;Sol;10;12
Colorante;Sol;10;12
Colorante;Sol;20;24
Colorante;Sol;20;24
Colorante;Sol;20;24
Colorante;Sol;20;24
Colorante;Sol;20;24请帮帮我
发布于 2018-12-01 14:27:55
我使用您提供的代码和示例数据创建了一个POC,在运行application.Please注意事项时,我能够获得以下输出:我使用的是ML.NET版本5.0

我认为您的应用程序很好,但是ML.NET的不同版本,也就是problem.There,在最近的版本中发生了一些变化。
如果需要使用以前版本中的特性,可以使用Microsoft.ML.Legacy命名空间。
https://stackoverflow.com/questions/52504255
复制相似问题