Saving artificial sklearn data as an excel file

Viewed 64

I am 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?

1 Answers

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)
Related