使用ML.Net进行数组数据输入以预测月度销售

我很难使用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");

metrics的值总是零,并且没有预测数据


回答:

ML.NET中的管道是不可变的:对pipeline.Append的调用会返回一个新的更新后的管道,但不会更改原始管道。

修改你的代码如下:

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")]。所有其他属性都是完全不必要的。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注