【问题标题】:Prophet Python ValueError: Regressor missing from dataframeProphet Python ValueError:数据框中缺少回归量
【发布时间】:2018-08-23 23:27:26
【问题描述】:

我正在尝试为 Python 使用最新的(第二个)0.3 版本的 Prophet 包。

我的模型应该包含一个外生回归量,但我收到一个 ValueError,指出数据帧中确实缺少现有的回归量。这是一个错误还是我做错了什么?

#Random Dataset Preparation

import random
random.seed(a=1)

df = pandas.DataFrame(data = None, columns = ['ds', 'y', 'ex'], index = range(50))
datelist = pandas.date_range(pandas.datetime.today(), periods = 50).tolist()

y = numpy.random.normal(0, 1, 50)
ex = numpy.random.normal(0, 2, 50)

df['ds'] = datelist
df['y'] = y
df['ex'] = ex

#Model
prophet_model = Prophet(seasonality_prior_scale = 0.1)
Prophet.add_regressor(prophet_model, 'ex')
prophet_model.fit(df)
prophet_forecast_step = prophet_model.make_future_dataframe(periods=1)

#Result-df
prophet_x_df = pandas.DataFrame(data=None, columns=['Date_x', 'Res'], index = range(int(len(y))))

#Error
prophet_x_df.iloc[0,1] = prophet_model.predict(prophet_forecast_step).iloc[0,0] 

【问题讨论】:

  • 您找到解决方案了吗?

标签: python facebook-prophet


【解决方案1】:

您需要先创建一个包含回归量值的列,该值需要同时出现在拟合和预测数据帧中。
Refer prophet docs

【讨论】:

    【解决方案2】:

    make_future_dataframe 生成仅包含 ds 列的数据帧。 您需要将 'ex' 列添加到先知_forecast_step 数据帧中才能将其用作回归器

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-23
      • 2021-02-11
      • 2012-11-25
      • 1970-01-01
      • 2014-03-14
      • 2021-02-02
      • 2021-12-14
      • 1970-01-01
      相关资源
      最近更新 更多