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

Saving artificial sklearn data as an excel file

I am very new to Python and trying to save, as an Excel file, the dataset generated by the following code:

from sklearn.datasets import make_classification
import pandas as pd

X, y = make_classification(random_state=0)

Any help would be most appreciated!

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

>Solution :

Use numpy to concatenate X and y then create your dataframe:

from sklearn.datasets import make_classification
import pandas as pd
import numpy as np

X, y = make_classification(random_state=0)
df = pd.DataFrame(np.concatenate([X, np.vstack(y)], axis=1))
df.to_excel('output.xlsx', index=False)
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