首页 > 解决方案 > ML.NET Timeseries ForecastBySsa hoirzon: 7 如何知道未来多少时间是第一个预测?

问题描述

我用于我的预测预测时间序列 mlContext.Forecasting.ForecastBySSA。

现在我想知道下一个预测是从什么时候开始的。

当我使用:

     var forecastingPipeline = mlContext.Forecasting.ForecastBySsa(
            outputColumnName: "ForecastedFillLevel",
            inputColumnName: "FillLevel",
            windowSize: 7,
            seriesLength: 30,
            trainSize: 100,
            horizon: 7,
            confidenceLevel: 0.95f,
            confidenceLowerBoundColumn: "LowerBoundFillLevel",
            confidenceUpperBoundColumn: "UpperBoundFillLevel");

它将在未来预测 7 个值,但我想知道预测基于哪个 DateTime。

在我的数据集中,一天中的数据差异与一天中 4-10 个数据行的差异。

现在我使用这段代码。

 static void Forecast(IDataView testData, int horizon, TimeSeriesPredictionEngine<ModelInput, ModelOutput> forecaster, MLContext mlContext)
    {

        ModelOutput forecast = forecaster.Predict();




        IEnumerable<string> forecastOutput =
            mlContext.Data.CreateEnumerable<ModelInput>(testData, reuseRowObject: false)
                .Take(horizon)
                .Select((ModelInput Message, int index) =>
                {
                    string rentalDate = Message.DateTime.ToShortDateString();
                    //float actualRentals = rental.FillLevel;
                    float lowerEstimate = Math.Max(0, forecast.LowerBoundFillLevel[index]);
                    float estimate = forecast.ForecastedFillLevel[index];
                    float upperEstimate = forecast.UpperBoundFillLevel[index];
                    return $"Date: {rentalDate}\n" +
                   // $"Actual Rentals: {actualRentals}\n" +
                    $"Lower Estimate: {lowerEstimate}\n" +
                    $"Forecast: {estimate}\n" +
                    $"Upper Estimate: {upperEstimate}\n";
                });

        // Output predictions
        Console.WriteLine("Rental Forecast");
        Console.WriteLine("---------------------");
        foreach (var prediction in forecastOutput)
        {
            Console.WriteLine(prediction);
        }

       
       
    }

但是打印出来的 DateTime 是我数据集中的前 7 个日期时间值。预测值很好,并且基于最后的数据行。

所以我的问题是如何为预测打印正确的 DateTime 值

标签: c#time-seriesforecastingml.netforecast

解决方案


推荐阅读