我正在使用tensorflow2.1设计一个股票预测程序。我的变量在我的程序结束时应该是一个二维变量,但只是一个一维。返回的错误是:predictionsTraceback (most recent call last): File "/Users/owner/Desktop/algo/predict.py", line 120, in <module> valid['Predictions'] = predictions File "/usr/local/lib/python3.7/site-packages/pandas/core/frame.py", line 3487, in __setitem__ self._set_item(key, value) File "/usr/local/lib/python3.7/site-packages/pandas/core/frame.py", line 3563, in _set_item self._ensure_valid_index(value) File "/usr/local/lib/python3.7/site-packages/pandas/core/frame.py", line 3540, in _ensure_valid_index value = Series(value) File "/usr/local/lib/python3.7/site-packages/pandas/core/series.py", line 314, in __init__ data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True) File "/usr/local/lib/python3.7/site-packages/pandas/core/internals/construction.py", line 729, in sanitize_array raise Exception("Data must be 1-dimensional")Exception: Data must be 1-dimensional这个错误是由于Pandas,Numpy还是Tensorflow造成的?可以做些什么来满足这个错误陈述?我一直在GitHub上寻求帮助,但他们将我重定向到Stackoverflow。
2 回答
慕田峪7331174
TA贡献1828条经验 获得超13个赞
更改为 。错误应该消失。valid['Predictions'] = predictions
valid['Predictions'] = np.squeeze(predictions)
弑天下
TA贡献1818条经验 获得超8个赞
您的预测是列表的列表。
print(predictions)结果[[1597.7726]]
您可以使用numpy的挤压方法
...
print(predictions.shape)
predictions = np.squeeze(predictions)
...
或使用简单的解决方法
...
print(predictions.shape)
predictions = predictions[0]
...
以解决错误。
添加回答
举报
0/150
提交
取消