我正在尝试计算数据集的均方误差,但给出了误差。然后我尝试打印该列以解决问题,但在打印过程中发生相同的错误
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
我已经在Google上搜索了此错误,但是在这里找不到解决方法是代码
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]))))