我试图计算我的数据集的平均平方误差,但它给出了错误。然后我尝试打印该列以达到问题,但在打印过程中出现了相同的错误
Traceback (most recent call last):
File "C:\Users\SCS\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-1ee3cafdfd42>", line 1, in <module>
runfile('C:/Users/SCS/Desktop/RNN/Rne2.py', wdir='C:/Users/SCS/Desktop/RNN')
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/SCS/Desktop/RNN/Rne2.py", line 54, in <module>
print("pred[i]:\n",pred[i])
File "C:\Users\SCS\Anaconda3\lib\site-packages\pandas\core\frame.py", line 2973, in __getitem__
return self._get_item_cache(key)
File "C:\Users\SCS\Anaconda3\lib\site-packages\pandas\core\generic.py", line 3270, in _get_item_cache
values = self._data.get(item)
File "C:\Users\SCS\Anaconda3\lib\site-packages\pandas\core\internals\managers.py", line 960, in get
return self.iget(loc)
File "C:\Users\SCS\Anaconda3\lib\site-packages\pandas\core\internals\managers.py", line 977, in iget
block = self.blocks[self._blknos[i]]
TypeError: only integer scalar arrays can be converted to a scalar index
我已经在谷歌上搜索了这个错误,但无法找到解决方案,这里是代码
train = data[:int(0.8*(len(data)))]
valid = data[int(0.8*(len(data))):]
#fit the model
model = VAR(endog=train)
model_fit = model.fit()
# make prediction on validation
prediction = model_fit.forecast(model_fit.y, steps=len(valid))
pred = pd.DataFrame(index=range(0,len(prediction)),columns=[cols])
#converting predictions to dataframe
print("Data\n",data)
# pred = pd.DataFrame(index=range(0,len(prediction)),columns=[cols])
for j in range(0,17):
for i in range(0, len(prediction)):
pred.iloc[i][j] = prediction[i][j]
#check rmse
for i in cols:
print("pred[i]:\n",pred[i]) // error on this line
print("valid[i]:\n",valid[i])
#print('rmse value for', i, 'is : ', math.sqrt(mean_squared_error((pred[i], valid[i]))))
问题来源StackOverflow 地址:/questions/59383407/typeerror-integer-scalar-arrays-can-only-be-converted-to-a-scalar-index
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。