使用 NeuralProphet 绘制置信区间时出错

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

我正在遵循 NeuralProphet 中有关分位数回归的教程,但在绘制预测时出现问题。

confidence_lv = 0.9
quantile_list = [round(((1 - confidence_lv) / 2), 2), round((confidence_lv + (1 - confidence_lv) / 2), 2)]


m = NeuralProphet(
    yearly_seasonality=True,
    weekly_seasonality=True,
    daily_seasonality=False,  
    quantiles=quantile_list,
    n_lags=30,
    epochs=10,
    n_forecasts=30,
)

m.set_plotting_backend('plotly')
metrics = m.fit(df)

df_future = m.make_future_dataframe(
    df, 
    n_historic_predictions=True,   
    periods=30, 
)

forecast = m.predict(df_future)

m.plot(forecast, forecast_in_focus=30)

我收到以下错误。我没有找到他们在上面这些函数中任何地方提到的参数(我使用的是版本

0.6.2
)。

in NeuralProphet.plot(self, fcst, df_name, ax, xlabel, ylabel, figsize, forecast_in_focus, plotting_backend)
   1886 if len(self.config_train.quantiles) > 1:
   1887     if (self.highlight_forecast_step_n) is None and (
   1888         self.n_forecasts > 1 or self.n_lags > 0
   1889     ):  # rather query if n_forecasts >1 than n_lags>1
-> 1890         raise ValueError(
   1891             "Please specify step_number using the highlight_nth_step_ahead_of_each_forecast function"
   1892             " for quantiles plotting when auto-regression enabled."
   1893         )
   1894     if (self.highlight_forecast_step_n or forecast_in_focus) is not None and self.n_lags == 0:
   1895         log.warning("highlight_forecast_step_n is ignored since auto-regression not enabled.")

ValueError: Please specify step_number using the highlight_nth_step_ahead_of_each_forecast function for quantiles plotting when auto-regression enabled.
python deep-learning neural-network time-series
1个回答
0
投票

如果我理解正确,该错误表明您在代码中缺少一个步骤。 当您开始时:

m = NeuralProphet(
    yearly_seasonality=True,
    weekly_seasonality=True,
    daily_seasonality=False,  
    quantiles=quantile_list,
    n_lags=30,
    epochs=10,
    n_forecasts=30,
)

您正在设置

n_forecasts=30
。这样做会触发以下 if 语句:

if (self.highlight_forecast_step_n) is None and (
    self.n_forecasts > 1 or self.n_lags > 0

您未能设置

highlight_forecast_step_n
并拥有
n_forecasts=30
,因此 if 语句为
True

要解决此问题,您需要设置模型的

highlight_forecast_step_n
属性。这可以通过使用类函数
highlight_nth_step_ahead_of_each_forecast
来完成。

这样的事情会起作用:

m.highlight_nth_step_ahead_of_each_forecast(step_number=10)

参考:highlight_nth_step_ahead_of_each_forecast

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