目录
模型训练评估中常用的两种方法代码实现
T1、留一法一次性切分训练
T2、K折交叉验证训
1. print("data split:") 2. if kfold_flag: #T1、采用K折交叉验证训练 3. kf = KFold(n_splits=2, shuffle=False) # K折交叉验证 4. for train_index, test_index in kf.split(X_train): 5. x_train_, y_train_ = X_train[train_index], y_train[train_index] 6. x_test_, y_test_ = X_train[test_index], y_train[test_index] 7. ModelC = ModelC_Train(XGBC_Best, x_train_,y_train_, x_test_,y_test_) 8. else: #T2、采用K折交叉训练 9. # train_test_split 10. x_train_, x_test_, y_train_, y_test_ = train_test_split(X_train, y_train, test_size=0.3, random_state=33) 11. ModelC = ModelC_Train(XGBC_Best, x_train_, x_test_, y_train_, y_test_)