首页 > 解决方案 > KeyError:进行预测时无

问题描述

我有以下代码来进行 DNN 预测

forecast = []
for time in range(len(series) - window_size):
  forecast.append(model.predict(series[time:time + window_size][np.newaxis]))

forecast = forecast[split_time-window_size:]
results = np.array(forecast)[:, 0, 0]


plt.figure(figsize=(10, 6))

plot_series(time_valid, x_valid)
plot_series(time_valid, results)


KeyError                                  Traceback (most recent call last)
pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: -9223372036854775808

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2897             try:
-> 2898                 return self._engine.get_loc(casted_key)
   2899             except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

KeyError: NaT

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
5 frames
KeyError: NaT

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/datetimes.py in get_loc(self, key, method, tolerance)
    625             return Index.get_loc(self, key, method, tolerance)
    626         except KeyError as err:
--> 627             raise KeyError(orig_key) from err
    628 
    629     def _maybe_cast_for_get_loc(self, key) -> Timestamp:

KeyError: None

我的时间变量是日期

series=df['Close']
time=pd.to_datetime(df.index)
time

谢谢

标签: pythonpandasdataframekerastf.keras

解决方案


推荐阅读