ValueError:索引数据必须是1维的

发布于 2025-01-28 05:17:33 字数 632 浏览 1 评论 0原文

我正在尝试使用随机森林的实际数据框架。预测值和所有信息来自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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

被翻牌 2025-02-04 05:17:33

您正在遇到上述错误,因为reset_index()将返回数据框架,而不是1维数据,您可以用self.x_test.index.values.values替换它,或者创建一个dataframe,您可以使用词典像这样:

def makeDataframe(self):
    data = {}
    data.update({'index': self.X.index.values})
    data.update({'type': self.y_test.values})
    data.update({'prediction': self.y_pred})
    data.update({'ax': self.X_test['ax']})
    data.update({'ay': self.X_test['ay']})
    data.update({'az': self.X_test['az']}) 
    self.df = pd.DataFrame(data)
    print(self.df.head(10))

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:

def makeDataframe(self):
    data = {}
    data.update({'index': self.X.index.values})
    data.update({'type': self.y_test.values})
    data.update({'prediction': self.y_pred})
    data.update({'ax': self.X_test['ax']})
    data.update({'ay': self.X_test['ay']})
    data.update({'az': self.X_test['az']}) 
    self.df = pd.DataFrame(data)
    print(self.df.head(10))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文