我一直在尝试使用 ML.net,因为它是一个 Web API,我按照https://docs.microsoft.com/es-es/dotnet/machine-learning/tutorials/taxi中 ML.net 教程的所有步骤进行操作票价
但是,当我尝试使用该服务时,我收到消息: “Transforms.CategoricalHashOneHotVectorizer”未在 该行中找到
model = pipeline.Train<Trazability, TrazabilityPrediction>();
我不知道如何在教程中获得正确的响应,但是当我尝试将相同的代码放入 Web Api proyect 时,会出现此错误。
这是我做的代码:
类程序.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
请帮我