将人工 sklearn 数据保存为 excel 文件

Saving artificial sklearn data as an excel file

我正在尝试将以下代码生成的数据集另存为 Excel 文件:

from sklearn.datasets import make_classification
import pandas as pd

X, y = make_classification(random_state=0)

有什么帮助吗?

使用 numpy 连接 Xy,然后创建数据框:

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)