I was trying to use ML.net since a Web API, I followed all the steps of the tutorial of ML.net in https://learn.microsoft.com/es-es/dotnet/machine-learning/tutorials/taxi-fare
But, when I try to use the service I have the message : "Transforms.CategoricalHashOneHotVectorizer" not found int the line
model = pipeline.Train<Trazability, TrazabilityPrediction>();
I don't know how can obtain a correct response in the tutorial but when I tried to put the same code in a Web Api proyect obtain this wrong.
Here the code that I did:
Class 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}");
}
}
and here are the models
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;
}
Also here have the .csv (train.csv and 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
please help me

ColumnCopierworks butCategoricalHashOneHotVectorizerdoes not, given that they are in the same assembly. Were you able to run the same pipeline in a console app and get results?