ValueError:索引数据必须是1维的
我正在尝试使用随机森林的实际数据框架。预测值和所有信息来自x_test
。
这是我的代码:
def makeDataframe(self):
self.df.index = self.X_test.reset_index()
self.df['type'] = self.y_test
self.df['prediction'] = self.y_pred
self.df['ax'] = self.X_test['ax']
self.df['ay'] = self.X_test['ay']
self.df['az'] = self.X_test['az']
print(self.df.head(10))
我想制作这样的数据框架:
type prediction. ax ay az
但是我遇到了这个错误:
ValueError: Index data must be 1-dimensional
解决此错误的任何想法。 Durther,我想确认我的预测索引和X_TEST数据集索引是匹配的。
我可以得到一些帮助吗?
谢谢
I am trying to make a dataframe with RANDOM FOREST actual . prediction value and all the information from X_test
.
This is my code:
def makeDataframe(self):
self.df.index = self.X_test.reset_index()
self.df['type'] = self.y_test
self.df['prediction'] = self.y_pred
self.df['ax'] = self.X_test['ax']
self.df['ay'] = self.X_test['ay']
self.df['az'] = self.X_test['az']
print(self.df.head(10))
I want to make a dataframe like this:
type prediction. ax ay az
But I am stuck with this error:
ValueError: Index data must be 1-dimensional
Any idea to solve this error.
Durther, I want to confirm that my prediction index and x_test dataset index are matched.
Can I get some help?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在遇到上述错误,因为reset_index()将返回数据框架,而不是1维数据,您可以用
self.x_test.index.values.values
替换它,或者创建一个dataframe,您可以使用词典像这样:You are getting the above error because reset_index() will return a DataFrame and not a 1-dimensional data you can replace it with
self.X_test.index.values
or To create a DataFrame you can use a Dictionary like this: