0

我正在尝试使用先知包来预测时间序列:

首先,我将月份和日期合并为一列:

df1['Date'] = pd.to_datetime(df1.Ano.astype(str) + '-' + df1.Meses.astype(str))

我的数据框:

          Date     Values
11259 2017-01-01  23.818044
11286 2017-02-01  20.275252
11313 2017-03-01  22.347278
11340 2017-04-01  23.837490
11367 2017-05-01  23.460605
11394 2017-06-01  22.307115
11421 2017-07-01  23.643994
11448 2017-08-01  23.791720
11475 2017-09-01  23.643933
11502 2017-10-01  20.771269
11529 2017-11-01  21.317947
11556 2017-12-01  22.361570
33723 2018-01-01  24.336259
33750 2018-02-01  19.926928
33777 2018-03-01  22.714901
33804 2018-04-01  23.605119
33831 2018-05-01  23.653298
33858 2018-06-01  23.052182
33885 2018-07-01  24.377920
33912 2018-08-01  24.576733
33939 2018-09-01  24.376775
33966 2018-10-01  21.256970
33993 2018-11-01  21.969202
34020 2018-12-01  22.970637

然后我尝试使用以下功能:

sub_model = Prophet(interval_width=0.95)
sub_model.fit(df1)

然后我收到以下错误:

KeyError: 'y'

During handling of the above exception, another exception occurred:

    KeyError                                  Traceback (most recent call last)
<ipython-input-6-a31a513027be> in <module>()
     31 
     32 sub_model = Prophet(interval_width=0.95)
---> 33 sub_model.fit(df1)
     34

我的年月日专栏有什么问题与先知功能冲突吗?

更新:正如 Vasil 建议的那样,第一个解决方案是将日期列名称更改为“ds”,将变量列更改为“y”。

现在,出现错误消息:

 INFO:fbprophet.forecaster:n_changepoints greater than number of observations.Using 18.0.

指的是这个函数:

# the history.
hist.size <- floor(nrow(m$history) * .8)
if (m$n.changepoints + 1 > hist.size) {
  m$n.changepoints <- hist.size - 1
  message('n.changepoints greater than number of observations. Using ',
          m$n.changepoints)
}

更新:第二个问题已解决,添加n_changepointsalec_djinn 建议的参数

最后一个问题是第二条消息:

Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
4

1 回答 1

3

默认情况下,先知假设您有每日数据。在您的情况下,它是每月一次。

如果你想预测每月数据,你应该这样写:

sub_model  = Prophet(weekly_seasonality=False, daily_seasonality=False).fit(df1)
future = sub_model.make_future_dataframe(periods=1, freq='M')
fcst = sub_model.predict(future)

另一个重要的点是您传递给 phrophet 的列的名称。您的日期列必须命名为“ds”,并且您要预测的变量列必须是“y”

于 2018-05-15T14:08:21.043 回答