首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Web中的ML.net

Web中的ML.net
EN

Stack Overflow用户
提问于 2018-09-25 18:01:24
回答 1查看 462关注 0票数 0

我尝试使用ML.net,因为我使用了Web,我遵循了ML.net in https://learn.microsoft.com/es-es/dotnet/machine-learning/tutorials/taxi-fare教程的所有步骤

但是,当我尝试使用该服务时,我收到了一条消息:"Transforms.CategoricalHashOneHotVectorizer“未在行中找到

代码语言:javascript
复制
model = pipeline.Train<Trazability, TrazabilityPrediction>();

我不知道如何在本教程中获得正确的响应,但是当我试图将相同的代码放在中时,就会发现这是错误的。

在这里,我做的代码:

类Program.cs

代码语言:javascript
复制
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}");

    }


}

下面是模型

代码语言:javascript
复制
 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)

代码语言:javascript
复制
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

请帮帮我

EN

回答 1

Stack Overflow用户

发布于 2018-12-01 14:27:55

我使用您提供的代码和示例数据创建了一个POC,在运行application.Please注意事项时,我能够获得以下输出:我使用的是ML.NET版本5.0

我认为您的应用程序很好,但是ML.NET的不同版本,也就是problem.There,在最近的版本中发生了一些变化。

如果需要使用以前版本中的特性,可以使用Microsoft.ML.Legacy命名空间。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52504255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档