ML.net - CreateTimeSeriesEngine

问题描述 投票:0回答:1

我正在使用 ML.net 进行时间序列分析项目。在这里我尝试预测欧元兑美元的交易汇率。我从 CSV 文件加载数据并使用内存数据创建 IDataView。

List<RateData> infoList = new List<RateData>();
// populate list
infoList = FileParser(infoList);
IDataView data = mlContext.Data.LoadFromEnumerable<RateData>(infoList);

我设法像这样运行预测估计器

var forecastEstimator = mlContext.Forecasting.ForecastBySsa(
    outputColumnName: nameof(RatePrediction.CurrentRate),
    inputColumnName: nameof(RateData.HistoricalRate),
    windowSize: 14,
    seriesLength: numRateDataPoints,
    trainSize: numRateDataPoints, 
    horizon: 1, 
    confidenceLevel: 0.95f );

SsaForecastingTransformer forecaster = forecastEstimator.Fit(RateDataSeries);

然后我尝试创建这样的预测引擎

var ForecastEngine = Forecaster.CreateTimeSeriesEngine(mlContext);

这里我遇到了一些错误。 我的输入和输出类如下:

public class RateData
{
    public DateTime TransactionDate { get; set; }
    public float HistoricalRate { get; set; }
}
   
public class RatePrediction
{
  public float CurrentRate;
       
}

我有这样的错误

System.InvalidOperationException: Can't bind the IDataView column 'CurrentRate' of type 'Vector<Single, 1>' to field or property 'CurrentRate' of type 'System.Single'.
   at Microsoft.ML.Data.TypedCursorable`1..ctor(IHostEnvironment env, IDataView data, Boolean ignoreMissingColumns, InternalSchemaDefinition schemaDefn)
   at Microsoft.ML.Data.TypedCursorable`1.Create(IHostEnvironment env, IDataView data, Boolean ignoreMissingColumns, SchemaDefinition schemaDefinition)
   at Microsoft.ML.Transforms.TimeSeries.TimeSeriesPredictionEngine`2.PredictionEngineCore(IHostEnvironment env, InputRow`1 inputRow, IRowToRowMapper mapper, Boolean ignoreMissingColumns, SchemaDefinition outputSchemaDefinition, Action& disposer, IRowReadableAs`1& outputRow)
   at Microsoft.ML.PredictionEngineBase`2..ctor(IHostEnvironment env, ITransformer transformer, Boolean ignoreMissingColumns, SchemaDefinition inputSchemaDefinition, SchemaDefinition outputSchemaDefinition, Boolean ownsTransformer)
   at Microsoft.ML.Transforms.TimeSeries.TimeSeriesPredictionEngine`2..ctor(IHostEnvironment env, ITransformer transformer, Boolean ignoreMissingColumns, SchemaDefinition inputSchemaDefinition, SchemaDefinition outputSchemaDefinition)
   at Microsoft.ML.Transforms.TimeSeries.PredictionFunctionExtensions.CreateTimeSeriesEngine[TSrc,TDst](ITransformer transformer, IHostEnvironment env, Boolean ignoreMissingColumns, SchemaDefinition inputSchemaDefinition, SchemaDefinition outputSchemaDefinition)
   at USD_EURO_Conversion_rate.TimeSeriesModelHelper.FitAndSaveModel(MLContext mlContext, IDataView RateDataSeries, String outputModelPath) 
c# ml.net
1个回答
0
投票

预测类中的属性需要是

float[]
类型;向量/数组而不是单个值,例如

public class RatePrediction
{
  public float[] CurrentRate;
       
}

类似于此处的Microsoft 示例

© www.soinside.com 2019 - 2024. All rights reserved.