-1

我有一个数据框,其中包含时间作为索引,格式为 HH:MM:SS。数据框只有一列 Y,其中包含一个浮点值。我的数据集是:

09:37:57            121
09:39:05             73
09:40:40             91
09:40:45            101
09:47:40             69
09:52:13             81
09:58:35             83
10:00:30            428
10:11:28            184
10:13:20            231
10:14:18            577
10:19:44             92
10:23:17             67
10:23:40            156
10:24:21             76
10:24:31             95
10:26:38            180
10:26:43             65
10:27:11            130
10:28:28             90
10:29:53            293
10:31:26            132
10:36:21             67
10:38:22            118
10:39:37            110
10:41:03             65
10:43:49             71
10:43:57             90
10:45:17             93
10:45:44             74

我想使用 (2,1,2) 顺序的 ARIMA 模型预测 Y 值。但我收到以下错误:

 model = ARIMA(endog=dt, order=(2, 1, 2))
  File "C:\Users\Moushmi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\statsmodels\tsa\arima_model.py", line 1000, in __new__
    mod.__init__(endog, order, exog, dates, freq, missing)
  File "C:\Users\Moushmi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\statsmodels\tsa\arima_model.py", line 1015, in __init__
    super(ARIMA, self).__init__(endog, (p, q), exog, dates, freq, missing)
  File "C:\Users\Moushmi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\statsmodels\tsa\arima_model.py", line 452, in __init__
    super(ARMA, self).__init__(endog, exog, dates, freq, missing=missing)
  File "C:\Users\Moushmi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\statsmodels\tsa\base\tsa_model.py", line 44, in __init__
    self._init_dates(dates, freq)
  File "C:\Users\Moushmi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\statsmodels\tsa\base\tsa_model.py", line 56, in _init_dates
    dates = to_datetime(dates)
  File "C:\Users\Moushmi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\tools\datetimes.py", line 514, in to_datetime
    result = _convert_listlike(arg, box, format, name=arg.name)
  File "C:\Users\Moushmi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\tools\datetimes.py", line 435, in _convert_listlike
    require_iso8601=require_iso8601
  File "pandas\_libs\tslib.pyx", line 2355, in pandas._libs.tslib.array_to_datetime (pandas\_libs\tslib.c:46617)
  File "pandas\_libs\tslib.pyx", line 2583, in pandas._libs.tslib.array_to_datetime (pandas\_libs\tslib.c:46321)
  File "pandas\_libs\tslib.pyx", line 2516, in pandas._libs.tslib.array_to_datetime (pandas\_libs\tslib.c:45268)
TypeError: <class 'datetime.time'> is not convertible to datetime

我的代码是:

model = ARIMA(endog=dt, order=(2, 1, 2))

results_ARIMA = model.fit()
print(results_ARIMA) plt.plot(model.resid) plt.show()

这里dt是数据框。需要建议来解决问题。我的问题与此处输入链接描述非常相似但没有解决方案。

4

1 回答 1

0

本质上,您必须了解错误消息。首先,您有一系列时间对象,例如

import pandas as pd
s = pd.Series(pd.datetime(2017, 5, 3, 11,11,11).time())

0    11:11:11
dtype: object

现在让我们尝试将其转换为日期时间

pd.to_datetime(s)

这提供了与您相同的错误消息

pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime 
(pandas\_libs\tslib.c:46617)()

pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime 
(pandas\_libs\tslib.c:46321)()

pandas\_libs\tslib.pyx in pandas._libs.tslib.array_to_datetime 
(pandas\_libs\tslib.c:45268)()

TypeError: <class 'datetime.time'> is not convertible to datetime

因此,毫不奇怪,我们不能将时间对象转换为日期时间对象,因为日期部分完全丢失了。本质上,您需要在那里提供一些日期。

于 2017-07-19T12:42:01.540 回答