我正在尝试使用先知包来预测时间序列:
首先,我将月份和日期合并为一列:
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_changepoints
alec_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`.