您当前的位置: 首页 > 
  • 0浏览

    0关注

    2393博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ML:模型训练/模型评估中常用的两种方法代码实现(留一法一次性切分训练和K折交叉验证训练)

一个处女座的程序猿 发布时间:2021-04-14 20:09:58 ,浏览量:0

ML:模型训练/模型评估中常用的两种方法代码实现(留一法一次性切分训练和K折交叉验证训练)

目录

模型训练评估中常用的两种方法代码实现

T1、留一法一次性切分训练

T2、K折交叉验证训

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

关注
打赏
1664196048
查看更多评论
立即登录/注册

微信扫码登录

0.0442s