I've created a Time Series model using the method described here resulting in this code:
var data = items.ToArray();
var trainData = mlContext.Data.LoadFromEnumerable(data);
var estimator = mlContext.Forecasting.ForecastBySsa(
nameof(FooPrediction.BarPrediction),
nameof(FooInput.Bar),
12,
data.Length,
data.Length,
2,
confidenceLowerBoundColumn: nameof(FooPrediction.ConfidenceLowerBound),
confidenceUpperBoundColumn: nameof(FooPrediction.ConfidenceUpperBound));
var transformer = estimator.Fit(trainData);
using var engine = transformer.CreateTimeSeriesEngine<FooInput, FooPrediction>(mlContext);
engine.CheckPoint(mlContext, "model.zip");
where items
is IEnumerable<FooInput>
. These are my model classes:
public class FooPrediction
{
public float[] BarPrediction { get; set; }
public float[] ConfidenceLowerBound { get; set; }
public float[] ConfidenceUpperBound { get; set; }
}
public class FooInput
{
public float Bar { get; set; }
public float Baz { get; set; }
}
In my Startup
, I add a PredictionEnginePool
thus:
services.AddPredictionEnginePool<FooInput, FooPrediction>().FromFile(String.Empty, "model.zip", true);
In my middleware service, I inject the PredictionEnginePool
and then call:
var prediction = items.Select(i => predictionEnginePool.Predict(i));
where items
is IEnumerable<FooInput>
.
This results in an ArgumentOutOfRangeException
being thrown in PredictionEngineBase.TransformerChecker
:
Must be a row to row mapper (Parameter 'transformer')
Debugging into the code, I can see there is a check for IsRowToRowMapper
on the ITransformer
object being true. However, when the model is created, an SsaForecastingTransformer
is created which has this property set to false.
Am I doing something wrong, or does PredictionEnginePool
not support Time Series models?
I've also tried this with AddPredictionEnginePool<IEnumerable<FooInput>, FooPrediction>
and then calling predictionEnginePool.Predict(items)
, but this also results in the same exception.