开发者社区> 问答> 正文

类型错误:整数标量数组只能转换为标量索引

我试图计算我的数据集的平均平方误差,但它给出了错误。然后我尝试打印该列以达到问题,但在打印过程中出现了相同的错误

  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

展开
收起
kun坤 2019-12-27 10:25:31 582 0
1 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载