想问一下决策树模型中如何导入做出的数据

#模型输出y
Churn_y=np.array(Churn).reshape(-1,1)

#模型输入x
SeniorCitizen_x=np.array(SeniorCitizen).reshape(-1,1)
Contract_x=Contract_dummies.values
InternetService_x=InternetService_dummies.values
PaymentMethod_x=np.array(PaymentMethod).reshape(-1,1)
OnlineSecurity_x=np.array(OnlineSecurity).reshape(-1,1)
OnlineBackup_x=np.array(OnlineBackup).reshape(-1,1)
DeviceProtection_x=np.array(DeviceProtection).reshape(-1,1)
TechSupport_x=np.array(TechSupport).reshape(-1,1)
tenure_x=tenure_dummies.values
MonthlyCharges_x=MonthlyCharges_dummies.values

X=np.concatenate([SeniorCitizen_x,Contract_x,InternetService_x,PaymentMethod_x,OnlineSecurity_x,\ OnlineBackup_x,DeviceProtection_x,TechSupport_x,tenure_x,MonthlyCharges_x],axis=1)
#数据导入
import pandas as pd
import numpy as np
data_frame=pd.read_excel("Save_X.xlsx")
X=np.array(data_frame.values[:,1:])
data_frame2=pd.read_excel("Save_y.xlsx")
y=np.array(data_frame2.values[:,1])
#模型训练
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
x_train, x_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)
tree = DecisionTreeClassifier(max_depth=6,random_state=0)
tree.fit(x_train,y_train)
print("training set score:{:.3f}".format(tree.score(x_train, y_train)))
print("test set score:{:.3f}".format(tree.score(x_test, y_test)))
print("Feature importances : \n{}".format(tree.feature_importances_))
 

这里的data_frame=pd.read_excel("Save_X.xlsx")

data_frame2=pd.read_excel("Save_y.xlsx")是怎么导入进去的

使用X.to_excel的时候会出现问题:

AttributeError: 'numpy.ndarray' object has no attribute 'to_excel'

代码中数据导入是通过读取xslx表格数据为数据框,然后取数据框中第一列后面所有列的数组赋值给X,把第一列数组赋值给y。因X是一个numpy数组,不是dataframe,没有to_excel方法,所以报错。numpy数组的保存方法,参考一下这里https://blog.csdn.net/leilei7407/article/details/107511187