Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ValueError: Index data must be 1-dimensional

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading