ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(四)

目录

Step 3: Tune gamma步骤3:伽马微调

Step 4: Tune subsample and colsample_bytree第4步:调整subsample和colsample_bytree

Step 5: Tuning Regularization Parameters步骤5:调整正则化参数

Step 6: Reducing Learning Rate第6步:降低学习率

​​​​​​​尾注/End Notes


​​​​​​​

原文题目:《Complete Guide to Parameter Tuning in XGBoost with codes in Python》
原文地址:https://www.analyticsvidhya.com/blog/2016/03/complete-guide-parameter-tuning-xgboost-with-codes-python/
所有权为原文所有,本文只负责翻译。

相关文章
ML之XGBoost:XGBoost算法模型(相关配图)的简介(XGBoost并行处理)、关键思路、代码实现(目标函数/评价函数)、安装、使用方法、案例应用之详细攻略
ML之XGBoost:Kaggle神器XGBoost算法模型的简介(资源)、安装、使用方法、案例应用之详细攻略
ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(一)
ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(二)
ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(三)
ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(四)

Step 3: Tune gamma
步骤3:伽马微调

Now lets tune gamma value using the parameters already tuned above. Gamma can take various values but I’ll check for 5 values here. You can go into more precise values as.
现在让我们使用上面已经调整过的参数来调整gamma值。gamma可以取不同的值,但我在这里检查5个值。您可以使用更精确的值。

param_test3 = {'gamma':[i/10.0 for i in range(0,5)]
}
gsearch3 = GridSearchCV(estimator = XGBClassifier( learning_rate =0.1, n_estimators=140, max_depth=4,min_child_weight=6, gamma=0, subsample=0.8, colsample_bytree=0.8,objective= 'binary:logistic', nthread=4, scale_pos_weight=1,seed=27), param_grid = param_test3, scoring='roc_auc',n_jobs=4,iid=False, cv=5)
gsearch3.fit(train[predictors],train[target])
gsearch3.grid_scores_, gsearch3.best_params_, gsearch3.best_score_

This shows that our original value of gamma, i.e. 0 is the optimum one. Before proceeding, a good idea would be to re-calibrate the number of boosting rounds for the updated parameters.
这表明我们的伽玛原值,即0是最佳值。在继续之前,一个好主意是为更新的参数重新校准助boosting的数量。

xgb2 = XGBClassifier(learning_rate =0.1,n_estimators=1000,max_depth=4,min_child_weight=6,gamma=0,subsample=0.8,colsample_bytree=0.8,objective= 'binary:logistic',nthread=4,scale_pos_weight=1,seed=27)
modelfit(xgb2, train, predictors)

Here, we can see the improvement in score. So the final parameters are:
在这里,我们可以看到分数的提高。所以最终参数是

  • max_depth: 4
  • min_child_weight: 6
  • gamma: 0

Step 4: Tune subsample and colsample_bytree
第4步:调整subsample和colsample_bytree

The next step would be try different subsample and colsample_bytree values. Lets do this in 2 stages as well and take values 0.6,0.7,0.8,0.9 for both to start with.
下一步将尝试不同的子样本和列样本树值。让我们分两个阶段来完成这项工作,从0.6、0.7、0.8、0.9开始。

param_test4 = {'subsample':[i/10.0 for i in range(6,10)],'colsample_bytree':[i/10.0 for i in range(6,10)]
}
gsearch4 = GridSearchCV(estimator = XGBClassifier( learning_rate =0.1, n_estimators=177, max_depth=4,min_child_weight=6, gamma=0, subsample=0.8, colsample_bytree=0.8,objective= 'binary:logistic', nthread=4, scale_pos_weight=1,seed=27), param_grid = param_test4, scoring='roc_auc',n_jobs=4,iid=False, cv=5)
gsearch4.fit(train[predictors],train[target])
gsearch4.grid_scores_, gsearch4.best_params_, gsearch4.best_score_

Here, we found 0.8 as the optimum value for both subsample and colsample_bytree. Now we should try values in 0.05 interval around these.
在这里,我们发现0.8是子样本和colsample_bytree的最佳值。现在我们应该在0.05间隔内尝试这些值。

param_test5 = {'subsample':[i/100.0 for i in range(75,90,5)],'colsample_bytree':[i/100.0 for i in range(75,90,5)]
}
gsearch5 = GridSearchCV(estimator = XGBClassifier( learning_rate =0.1, n_estimators=177, max_depth=4,min_child_weight=6, gamma=0, subsample=0.8, colsample_bytree=0.8,objective= 'binary:logistic', nthread=4, scale_pos_weight=1,seed=27), param_grid = param_test5, scoring='roc_auc',n_jobs=4,iid=False, cv=5)
gsearch5.fit(train[predictors],train[target])

Again we got the same values as before. Thus the optimum values are:
我们又得到了和以前一样的值。因此,最佳值为:

  • subsample: 0.8
  • colsample_bytree: 0.8

Step 5: Tuning Regularization Parameters
​​​​​​​步骤5:调整正则化参数

Next step is to apply regularization to reduce overfitting. Though many people don’t use this parameters much as gamma provides a substantial way of controlling complexity. But we should always try it. I’ll tune ‘reg_alpha’ value here and leave it upto you to try different values of ‘reg_lambda’.
下一步是应用正则化来减少过拟合。虽然许多人不使用这个参数,因为gamma提供了一种控制复杂性的实质性方法。但我们应该经常尝试。我将在这里调整“reg_alpha”值,并让您尝试不同的“reg_lambda”值。

param_test6 = {'reg_alpha':[1e-5, 1e-2, 0.1, 1, 100]
}
gsearch6 = GridSearchCV(estimator = XGBClassifier( learning_rate =0.1, n_estimators=177, max_depth=4,min_child_weight=6, gamma=0.1, subsample=0.8, colsample_bytree=0.8,objective= 'binary:logistic', nthread=4, scale_pos_weight=1,seed=27), param_grid = param_test6, scoring='roc_auc',n_jobs=4,iid=False, cv=5)
gsearch6.fit(train[predictors],train[target])
gsearch6.grid_scores_, gsearch6.best_params_, gsearch6.best_score_

We can see that the CV score is less than the previous case. But the values tried are very widespread, we should try values closer to the optimum here (0.01) to see if we get something better.
我们可以看到CV的分数低于前一个案例。但是尝试的值非常广泛,我们应该尝试接近最佳值的值(0.01),看看我们是否能得到更好的结果。

param_test7 = {'reg_alpha':[0, 0.001, 0.005, 0.01, 0.05]
}
gsearch7 = GridSearchCV(estimator = XGBClassifier( learning_rate =0.1, n_estimators=177, max_depth=4,min_child_weight=6, gamma=0.1, subsample=0.8, colsample_bytree=0.8,objective= 'binary:logistic', nthread=4, scale_pos_weight=1,seed=27), param_grid = param_test7, scoring='roc_auc',n_jobs=4,iid=False, cv=5)
gsearch7.fit(train[predictors],train[target])
gsearch7.grid_scores_, gsearch7.best_params_, gsearch7.best_score_

You can see that we got a better CV. Now we can apply this regularization in the model and look at the impact:
你可以看到我们有更好的CV。现在,我们可以在模型中应用此正则化,并查看影响:

xgb3 = XGBClassifier(learning_rate =0.1,n_estimators=1000,max_depth=4,min_child_weight=6,gamma=0,subsample=0.8,colsample_bytree=0.8,reg_alpha=0.005,objective= 'binary:logistic',nthread=4,scale_pos_weight=1,seed=27)
modelfit(xgb3, train, predictors)

Again we can see slight improvement in the score.
我们可以再次看到分数略有提高。

Step 6: Reducing Learning Rate
第6步:降低学习率

Lastly, we should lower the learning rate and add more trees. Lets use the cv function of XGBoost to do the job again.
最后,我们应该降低学习率,增加更多的树。让我们再次使用xgboost的cv功能来完成这项工作。

xgb4 = XGBClassifier(learning_rate =0.01,n_estimators=5000,max_depth=4,min_child_weight=6,gamma=0,subsample=0.8,colsample_bytree=0.8,reg_alpha=0.005,objective= 'binary:logistic',nthread=4,scale_pos_weight=1,seed=27)
modelfit(xgb4, train, predictors)

Now we can see a significant boost in performance and the effect of parameter tuning is clearer.
​​​​​​​现在我们可以看到性能的显著提高,参数调整的效果也更加明显。

As we come to the end, I would like to share 2 key thoughts:
最后,我想分享2个关键思想:

  1. It is difficult to get a very big leap in performance by just using parameter tuning or slightly better models. The max score for GBM was 0.8487 while XGBoost gave 0.8494. This is a decent improvement but not something very substantial.
    仅仅使用参数调整或稍好的型号,很难在性能上获得很大的飞跃。GBM最高得分为0.8487,XGBoost最高得分为0.8494。这是一个不错的改进,但不是很实质的改进。
  2. A significant jump can be obtained by other methods like feature engineering, creating ensemble of models, stacking, etc
    通过其他方法,如特征工程、创建模型集成、叠加等,可以获得显著的提升。

You can also download the iPython notebook with all these model codes from my GitHub account. For codes in R, you can refer to this article.
您也可以从我的Github帐户下载包含所有这些型号代码的ipython笔记本。有关R中的代码,请参阅本文。

​​​​​​​尾注/End Notes

This article was based on developing a XGBoost model end-to-end. We started with discussing why XGBoost has superior performance over GBM which was followed by detailed discussion on the various parameters involved. We also defined a generic function which you can re-use for making models.
本文基于开发一个xgboost模型端到端。我们首先讨论了xgboost为什么比gbm有更好的性能,然后详细讨论了所涉及的各种参数。我们还定义了一个通用函数,您可以使用它来创建模型。

Finally, we discussed the general approach towards tackling a problem with XGBoost and also worked out the AV Data Hackathon 3.x problem through that approach.
最后,我们讨论了解决xgboost问题的一般方法,并通过该方法解决了av data hackathon 3.x问题。

I hope you found this useful and now you feel more confident to apply XGBoost in solving a data science problem. You can try this out in out upcoming hackathons.
我希望您发现这一点很有用,现在您对应用XGBoost解决数据科学问题更有信心。你可以在即将到来的黑客攻击中尝试一下。

Did you like this article? Would you like to share some other hacks which you implement while making XGBoost models? Please feel free to drop a note in the comments below and I’ll be glad to discuss.
​​​​​​​你喜欢这篇文章吗?您是否愿意分享一些其他的黑客,在制作XGBoost模型时您实现这些黑客?请在下面的评论中留言,我很乐意与您讨论。

You want to apply your analytical skills and test your potential? Then participate in our Hackathons and compete with Top Data Scientists from all over the world.
你想运用你的分析能力来测试你的潜力吗?然后参与我们的黑客活动并与来自世界各地的顶尖数据科学家竞争。

ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(四)相关推荐

  1. ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(三)

    ML之XGBoost:XGBoost参数调优的优秀外文翻译-<XGBoost中的参数调优完整指南(带python中的代码)>(三) 目录 3. 参数微调案例/Parameter Tunin ...

  2. ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(二)

    ML之XGBoost:XGBoost参数调优的优秀外文翻译-<XGBoost中的参数调优完整指南(带python中的代码)>(二) 目录 2. xgboost参数/XGBoost Para ...

  3. ML之XGBoost:XGBoost参数调优的优秀外文翻译—《XGBoost中的参数调优完整指南(带python中的代码)》(一)

    ML之XGBoost:XGBoost参数调优的优秀外文翻译-<XGBoost中的参数调优完整指南(带python中的代码)>(一) 目录 概述/Overview 介绍/Introducti ...

  4. python 超参数_完整介绍用于Python中自动超参数调剂的贝叶斯优化

    完整介绍用于Python中自动超参数调剂的贝叶斯优化-1.jpg (109.5 KB, 下载次数: 0) 2018-7-4 23:45 上传 调剂机器学习超参数是一项繁琐但至关重要的任务,因为算法的性 ...

  5. [转载] 【python】Python中*args和**kwargs的区别(在Python中如何使用可变长参数列表)

    参考链接: Python中的*args 和 **kwargs 博客已经搬家到"捕获完成": https://www.v2python.com 或者可以叫做,在Python中如何使用 ...

  6. 比xgboost强大的LightGBM:调参指南(带贝叶斯优化代码)

    向AI转型的程序员都关注了这个号??? 大数据挖掘DT数据分析  公众号: datadw xgboost的出现,让数据民工们告别了传统的机器学习算法们:RF.GBM.SVM.LASSO........ ...

  7. Python中使用元组对ndarray矩阵的某个维度进行选取和调序的操作

    大家应该都知道,numpy库中的ndarray可以用所谓的三帽号规则进行切片操作(详情可见我之前写的博文,链接 https://blog.csdn.net/wenhao_ir/article/deta ...

  8. python中如何画logistic_如何在 Python 中建立和训练线性和 logistic 回归 ML 模型?

    原标题:如何在 Python 中建立和训练线性和 logistic 回归 ML 模型? 英语原文: 翻译:(Key.君思) 线性回归与logistic回归,是. 在我的里,你们已经学习了线性回归机器学 ...

  9. Python中json模块的load/loads方法实战及参数详解

    文章目录 前言 正文 1. loads方法与load方法的异同 1.1不相同点: 1.2 相同点 1.3 例子 2. 转换成Python对象 3. json.load(s)的参数 3.1 s参数 3. ...

最新文章

  1. 我是怎么读源码的,授之以渔
  2. pipe读写前设置O_NOATIME
  3. HDFS上传文件报错java.lang.InterruptedException
  4. Python模块:日志输出—logging模块
  5. java instance变量_java 类方法和实例方法 以及 类变量和实例变量
  6. Redis 分布式集群搭建2022版本+密码(linux环境)
  7. Scrapy 调用chrome浏览器的middleware
  8. 二本学医还是学计算机,二本医学院毕业的医学生,最后都去了哪里?看完莫名心酸!...
  9. UNIX 环境高级编程(四)—— dirent.h
  10. 怎么用EasyRecovery恢复sd卡中的数据
  11. iOS转前端之仿写宠物网(适配不同尺寸)
  12. ant下载与本地配置
  13. 【JAVAEE框架】浅谈 Spring 框架的两大核心思想 AOP 与 IOP
  14. 安卓游戏优化加速器v1.0.5
  15. Thread.currentThread()方法、进程、线程、多线程相关总结(二)
  16. 编辑PDF【没有PDF编辑器的会员时,且无破解软件】
  17. iOS 微信universalLink 配置
  18. wing101 缩进不管用_与lg wing一起使用最有用的双屏手机
  19. win10下禁用全角半角Kill-Shift-Space
  20. i5 13600K和i5 12600k差距

热门文章

  1. python 指针_指针篇 | 指针的灵活让我想起了Python
  2. 提醒一下技术人,你是不是陷入局部最优了
  3. hibernate3.4+struts1.3分页封装,有兴趣者可以看一下
  4. DBA(二):percona软件、innobackupex备份与恢复
  5. 记录一个ansible高级用法与shell结合
  6. CentOS 7安装Nginx
  7. LAN WAN WLAN 的区别
  8. 面试问到 Redis 事务,我脸都绿了。。
  9. 轻松理解https,So easy!
  10. 聊聊 MySql 索引那些事儿