python - 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
谢谢
解决方案
推荐阅读
- python - 如何从 JSON 文件中的列对象中的置信度值创建热图?(通过图片链接)
- android - android 9 上的 ad.loadclass 崩溃
- algorithm - Jarvis March 最佳案例与凸包下限
- python - 如何使用 docker 使 python 日志记录持久化
- python - Python逐个对象写入json文件对象
- string - LabVIEW 搜索多个字符串
- python - Keras 模型无法预测是否在线程中调用
- java - Springboot/Cucumber集成-如何在步骤定义类中使用@Autowired(或其他SB标签)?
- php - 我不明白如何使用 PHP 配置 REST API Sinch
- html - 如果 .html 文件不包含标记,IIS 不会返回内容