我正在学习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.

推荐答案

如果我理解正确的话,错误是说你在代码中缺少了一个步骤. 当你开始:

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等于Nonen_forecasts高于1.不

要解决这个问题,你需要设置模型的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

Python相关问答推荐

如何用symy更新分段函数

无法使用equals_html从网址获取全文

acme错误-Veritas错误:模块收件箱没有属性linear_util'

运行Python脚本时,用作命令行参数的SON文本

从dict的列中分钟

组/群集按字符串中的子字符串或子字符串中的字符串轮询数据框

为什么抓取的HTML与浏览器判断的元素不同?

在含噪声的3D点网格中识别4连通点模式

转换为浮点,pandas字符串列,混合千和十进制分隔符

Python导入某些库时非法指令(核心转储)(beautifulsoup4."" yfinance)

如何在Python中使用Pandas将R s Tukey s HSD表转换为相关矩阵''

使用Python异步地持久跟踪用户输入

如何在Python 3.9.6和MacOS Sonoma 14.3.1下安装Pyregion

获取git修订版中每个文件的最后修改时间的最有效方法是什么?

如何在PythonPandas 中对同一个浮动列进行逐行划分?

为什么dict. items()可以快速查找?

来自Airflow Connection的额外参数

为什么在Python中00是一个有效的整数?

Polars定制函数返回多列

是否需要依赖反转来确保呼叫方和被呼叫方之间的分离?