Workflow:Dotnet Machinelearning Time Series Forecasting
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Time_Series, Forecasting |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
End-to-end process for building a time series forecasting model using ML.NET's Singular Spectrum Analysis (SSA) to predict future values from historical sequential data.
Description
This workflow outlines the procedure for forecasting future values in a time series using ML.NET's SSA (Singular Spectrum Analysis) forecasting transform. SSA decomposes a time series into trend, seasonality, and noise components using eigenvalue decomposition, then extrapolates the identified patterns to generate predictions for future time periods. The workflow covers data loading with temporal ordering, configuring the SSA parameters (window size, series length, training horizon), fitting the model on historical data, generating forecasts with confidence intervals, and optionally detecting anomalies (spikes and change points) in the series.
Usage
Execute this workflow when you have sequential time-stamped data and need to predict future values. Typical scenarios include sales forecasting, demand planning, stock price prediction, power consumption estimation, server load prediction, and any domain where historical patterns repeat over time.
Execution Steps
Step 1: Load and Prepare Time Series Data
Load the sequential data ensuring temporal ordering is preserved. The data should contain at minimum a timestamp column and a value column representing the metric to forecast. Convert the data into an IDataView with the value column typed as Single (float).
Key considerations:
- Data must be sorted chronologically; ML.NET does not auto-sort
- Missing values should be imputed before training (forward fill, interpolation, or mean)
- The value column must be of type Single (float)
- Larger historical datasets generally improve forecast accuracy
- Reserve recent data as a holdout set for evaluating forecast quality
Step 2: Configure SSA Forecasting Parameters
Set the key SSA parameters that control how the model decomposes and extrapolates the time series. The critical parameters are window size (determines the decomposition granularity), series length (the length of historical data to analyze), and training window size (how many recent data points to use for model fitting).
Key considerations:
- Window size should be roughly half the dominant seasonal period (e.g., 6 for monthly data with yearly seasonality)
- Series length should cover at least 2-3 complete seasonal cycles
- Training window size controls how much history influences the model; larger values capture long-term trends
- The horizon parameter specifies how many future steps to predict
- Confidence level (e.g., 95%) controls the width of prediction intervals
Step 3: Fit Forecasting Model
Create the SSA forecasting estimator with the configured parameters and fit it to the training data. The fitting process performs eigenvalue decomposition on the trajectory matrix derived from the time series, identifying the dominant signal components (trend and seasonal patterns) while filtering noise.
Key considerations:
- The Fit() call performs the SSA decomposition and stores the model state
- The model captures both trend and seasonal components automatically
- Fitting is deterministic given the same data and parameters
- The resulting model is a TimeSeriesPredictionEngine that supports incremental updates
Step 4: Generate Forecasts
Use the fitted model to produce forecasts for future time periods. The model outputs predicted values along with upper and lower confidence bounds for each forecasted step. The forecast extends from the last observed data point forward by the specified horizon.
Key considerations:
- Forecasts include point predictions and confidence intervals
- Prediction uncertainty increases for time steps further into the future
- The model can be updated incrementally with new observations using Checkpoint and LoadFrom
- For real-time applications, use TimeSeriesPredictionEngine which supports streaming updates
Step 5: Evaluate Forecast Quality
Compare forecasted values against the held-out test data using error metrics such as MAE (Mean Absolute Error), RMSE (Root Mean Squared Error), and MAPE (Mean Absolute Percentage Error). Visualize the forecast against actuals to assess trend and seasonality capture.
Key considerations:
- MAPE provides an interpretable percentage-based error measure
- Evaluate whether confidence intervals contain the actual values at the specified confidence level
- If accuracy is insufficient, adjust window size and series length parameters
- Consider combining with anomaly detection (spike and change point) to flag unusual observations
Step 6: Save and Deploy Model
Save the trained forecasting model for production use. The model can be loaded and used for batch forecasting or integrated into a streaming application that updates predictions as new data arrives.
Key considerations:
- The model state includes the decomposition matrices and recent observations
- TimeSeriesPredictionEngine supports checkpointing for incremental model updates
- For production deployment, periodically retrain or update the model with new data
- The model is serializable and portable across platforms