ML.Net数组数据输入

ML.Net array data input

我很难通过使用 Microsoft .ML 输入的每日销售数据来预测每月销售额

    class Data
        {
            [Column(ordinal: "0", name: "Label")]
            public float PredictedProfit;
            [Column(ordinal: "Month")]
            public int Month;
            [Column(ordinal: "DayOfMonth")]
            public int DayOfMonth;
            [Column(ordinal: "Sales")]
            public double[] Sales;
            [Column(ordinal: "MonthlyProfit")]
            public double MonthlyProfit;
    }
    ...........................
     MLContext mlContext = new MLContext(seed: 0);
    List<VData> listData;
    VData row=new VData();
    .....
    fill row
    .....
    listData.Add(row);
    var trainData = mlContext.CreateStreamingDataView<VData>(listData);   

    var pipeline = mlContext.Transforms.CopyColumns("Label", "MonthlyProfit");            

    pipeline.Append(mlContext.Transforms.Concatenate("Features", "MonthlyProfit", "Sales", "Month", "DayOfMonth");

    pipeline.Append(mlContext.Regression.Trainers.FastTree());

    var model = pipeline.Fit(trainData);

    var dataView = mlContext.CreateStreamingDataView<VData>(listData);
    var predictions = model.Transform(dataView);
    var metrics = mlContext.Regression.Evaluate(predictions, "Label", "MonthlyProfit");

指标值始终为零,并且没有预测数据

ML.NET 中的管道是不可变的:调用 pipeline.Append return 新的更新管道,但不要更改原始管道。

修改代码以执行:

var pipeline = mlContext.Transforms.CopyColumns("Label", "MonthlyProfit");            

pipeline = pipeline.Append(mlContext.Transforms.Concatenate("Features", "MonthlyProfit", "Sales", "Month", "DayOfMonth");

pipeline = pipeline.Append(mlContext.Regression.Trainers.FastTree());

此外,您使用的 [Column] 属性无效。为了更改标签列的名称,您可以使用 [ColumnName("Label")]。所有其他属性完全没有必要。