Implementation:Dotnet Machinelearning SsaForecastingEstimator Fit
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Time Series, .NET |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
The Fit method on SsaForecastingEstimator trains the SSA model on a provided IDataView and returns a stateful SsaForecastingTransformer containing the trained recurrence model.
Description
SsaForecastingEstimator.Fit consumes the training data and produces a SsaForecastingTransformer. Internally, it extracts the time series values from the input column, constructs the trajectory matrix, performs SVD, selects the signal rank, derives the recurrence coefficients, and packages the result into a transformer that implements IStatefulTransformer.
The returned SsaForecastingTransformer wraps an AdaptiveSingularSpectrumSequenceModelerInternal object, which contains:
- The trained SVD decomposition
- The recurrence coefficients for forecasting
- The internal buffer holding recent observations
- The confidence interval estimation state
SsaForecastingTransformer extends SsaForecastingBaseWrapper which extends TimeSeriesTransformBase<float, VBuffer<float>>, inheriting the stateful transformer infrastructure. This class hierarchy ensures proper state management for sequential data processing.
The transformer is not used directly via .Transform() for forecasting. Instead, it is wrapped in a TimeSeriesPredictionEngine which provides the stateful prediction interface with support for adaptive updates and variable-horizon forecasting.
Usage
Call .Fit(dataView) on the configured estimator. The IDataView must contain a float column matching the inputColumnName specified during estimator configuration. After fitting, use transformer.CreateTimeSeriesEngine<TSrc, TDst>(mlContext) to create the prediction engine.
Code Reference
Source Location
- Repository: ML.NET
- File:
src/Microsoft.ML.TimeSeries/SSaForecasting.cs:L318-321(Fit method) - File:
src/Microsoft.ML.TimeSeries/SSaForecasting.cs:L29-204(SsaForecastingTransformer) - File:
src/Microsoft.ML.TimeSeries/SsaForecastingBase.cs:L19-314(base class)
Signature
// SsaForecastingEstimator.Fit
public SsaForecastingTransformer Fit(IDataView input)
Import
using Microsoft.ML;
using Microsoft.ML.Transforms.TimeSeries;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| input | IDataView | Yes | Data view containing the time series column. The column specified by inputColumnName (from the estimator configuration) must be of type Single (float). The first trainSize rows are used for SVD fitting.
|
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | SsaForecastingTransformer | A stateful transformer implementing IStatefulTransformer. Contains the trained AdaptiveSingularSpectrumSequenceModelerInternal with SVD results, recurrence coefficients, and internal buffer. Produces forecast values, and optionally confidence bounds, as VBuffer<float> output columns.
|
Usage Examples
Basic Example
using Microsoft.ML;
using Microsoft.ML.Transforms.TimeSeries;
var mlContext = new MLContext(seed: 42);
// Define input schema
public class TimeSeriesInput
{
public float Value { get; set; }
}
// Load data
IDataView dataView = mlContext.Data.LoadFromTextFile<TimeSeriesInput>(
path: "daily_values.csv",
separatorChar: ',',
hasHeader: true);
// Configure the SSA estimator
var estimator = mlContext.Forecasting.ForecastBySsa(
outputColumnName: "Forecast",
inputColumnName: "Value",
windowSize: 7,
seriesLength: 30,
trainSize: 365,
horizon: 7,
confidenceLowerBoundColumn: "LowerBound",
confidenceUpperBoundColumn: "UpperBound");
// Fit the model — performs SVD and builds recurrence model
SsaForecastingTransformer model = estimator.Fit(dataView);
// The model is now ready to be wrapped in a TimeSeriesPredictionEngine
Full Pipeline Example
// Fit and immediately create a prediction engine
var model = estimator.Fit(dataView);
var forecastEngine = model.CreateTimeSeriesEngine<TimeSeriesInput, ForecastOutput>(mlContext);
// forecastEngine is ready for stateful prediction
Dependencies
- Microsoft.ML.TimeSeries NuGet package