ml.net time series prediction: How to get prediction that occurs after a leap

14 views Asked by At

Both codes found here seems to produce predictions directly after trained model data:

According to sample code from ChatGPT (below) When I do ask ml.net

predictionEngine.Predict();
  • Can anyone confirms me that results from "Predict" are based on time that occurs immediatly after trained model TimesSeries Data?
  • How to ask ml.net to produce prediction with a leap in time? For example, I want predictions for next year, skiping the next 365 days, and my data is at 5 minutes. So for 1 year there is 12 *24 * 365 = 105120 data points. Do I have to ask for 2x (year to skip and year wanted) 105120 points ?
  • In short: Is there a way to get predictions for a specific time window?

Chat GPT answer (which seems to be a summary of Micrsoft link):

using System;
using Microsoft.ML;
using Microsoft.ML.Data;
using Microsoft.ML.Transforms.TimeSeries;

class Program
{
    static void Main(string[] args)
    {
        // Step 1: Prepare your data
        var data = new[] {
            new TimeSeriesData { Timestamp = new DateTime(2023, 3, 25), Value = 10 },
            // Add more historical data here...
        };

        // Step 2: Define your model
        var mlContext = new MLContext();
        var dataView = mlContext.Data.LoadFromEnumerable(data);
        var forecastingPipeline = mlContext.Forecasting.ForecastBySsa(
            outputColumnName: "Forecast",
            inputColumnName: "Value",
            windowSize: 10,
            seriesLength: 20,
            trainSize: data.Length,
            horizon: 5);

        // Step 3: Train your model
        var model = forecastingPipeline.Fit(dataView);

        // Step 4: Evaluate your model (optional)
        // Add evaluation code if needed

        // Step 5: Make predictions
        var predictionEngine = mlContext.Model.CreateTimeSeriesEngine<TimeSeriesData, TimeSeriesPrediction>(model);
        var forecast = predictionEngine.Predict();
        Console.WriteLine($"Forecast for the next 5 time points: {string.Join(", ", forecast.Forecast)}");
    }
}

public class TimeSeriesData
{
    [LoadColumn(0)]
    public DateTime Timestamp { get; set; }

    [LoadColumn(1)]
    public float Value { get; set; }
}

public class TimeSeriesPrediction
{
    [VectorType(5)]
    public float[] Forecast { get; set; }
}
0

There are 0 answers