转自:https://segmentfault.com/a/1190000014040317

整体:

  1. # 1.调试n_estimators
  2. cv_params = {'n_estimators': [550, 575, 600, 650, 675]}
  3. other_params = {'learning_rate': 0.1, 'n_estimators': 600, 'max_depth': 5, 'min_child_weight': 1, 'seed': 0,
  4. 'subsample': 0.8, 'colsample_bytree': 0.8, 'gamma': 0, 'reg_alpha': 0, 'reg_lambda': 1}
  5. # 2.调试max_depth、min_child_weight
  6. # cv_params = {'max_depth': [3, 4, 5, 6, 7, 8, 9, 10], 'min_child_weight': [1, 2, 3, 4, 5, 6]}
  7. # other_params = {'learning_rate': 0.1, 'n_estimators': 550, 'max_depth': 5, 'min_child_weight': 1, 'seed': 0,
  8. # 'subsample': 0.8, 'colsample_bytree': 0.8, 'gamma': 0, 'reg_alpha': 0, 'reg_lambda': 1}
  9. # 3.调试gamma
  10. # cv_params = {'gamma': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]}
  11. # other_params = {'learning_rate': 0.1, 'n_estimators': 550, 'max_depth': 4, 'min_child_weight': 5, 'seed': 0,
  12. # 'subsample': 0.8, 'colsample_bytree': 0.8, 'gamma': 0, 'reg_alpha': 0, 'reg_lambda': 1}
  13. # 4.调试subsample、colsample_bytree
  14. # cv_params = {'subsample': [0.6, 0.7, 0.8, 0.9], 'colsample_bytree': [0.6, 0.7, 0.8, 0.9]}
  15. # other_params = {'learning_rate': 0.1, 'n_estimators': 550, 'max_depth': 4, 'min_child_weight': 5, 'seed': 0,
  16. # 'subsample': 0.8, 'colsample_bytree': 0.8, 'gamma': 0.1, 'reg_alpha': 0, 'reg_lambda': 1}
  17. # 5.调试reg_alpha、reg_lambda
  18. # cv_params = {'reg_alpha': [0.05, 0.1, 1, 2, 3], 'reg_lambda': [0.05, 0.1, 1, 2, 3]}
  19. # other_params = {'learning_rate': 0.1, 'n_estimators': 550, 'max_depth': 4, 'min_child_weight': 5, 'seed': 0,
  20. # 'subsample': 0.7, 'colsample_bytree': 0.7, 'gamma': 0.1, 'reg_alpha': 0, 'reg_lambda': 1}
  21. # 6.调试learning_rate
  22. # cv_params = {'learning_rate': [0.01, 0.05, 0.07, 0.1, 0.2]}
  23. # other_params = {'learning_rate': 0.1, 'n_estimators': 550, 'max_depth': 4, 'min_child_weight': 5, 'seed': 0,
  24. # 'subsample': 0.7, 'colsample_bytree': 0.7, 'gamma': 0.1, 'reg_alpha': 1, 'reg_lambda': 1}
  25.  
  26. model = xgb.XGBClassifier(**other_params)
  27. optimized_GBM = GridSearchCV(estimator=model, param_grid=cv_params, cv=5, verbose=1, n_jobs=4)
  28. optimized_GBM.fit(X_train, y_train)
  29. evalute_result = optimized_GBM.grid_scores_
  30. print('每轮迭代运行结果:{0}'.format(evalute_result))
  31. print('参数的最佳取值:{0}'.format(optimized_GBM.best_params_))
  32. print('最佳模型得分:{0}'.format(optimized_GBM.best_score_))

1.调节最大迭代次数n_estimators

  1. # 最佳迭代次数:n_estimators
  2. from xgboost import XGBRegressor
  3. from sklearn.model_selection import GridSearchCV
  4. cv_params = {'n_estimators': [20,30,40]}
  5. other_params = {'learning_rate': 0.1, 'n_estimators': 500, 'max_depth': 5, 'min_child_weight': 1, 'seed': 0,
  6. 'subsample': 0.8, 'colsample_bytree': 0.8, 'gamma': 0, 'reg_alpha': 0, 'reg_lambda': 1}
  7. model = XGBRegressor(**other_params)
  8. optimized_GBM = GridSearchCV(estimator=model, param_grid=cv_params, scoring='r2', cv=3, verbose=1, n_jobs=-1)
  9. optimized_GBM.fit(x_data, y_data)
  10. evalute_result =optimized_GBM.return_train_score
  11. print('每轮迭代运行结果:{0}'.format(evalute_result))
  12. print('参数的最佳取值:{0}'.format(optimized_GBM.best_params_))
  13. print('最佳模型得分:{0}'.format(optimized_GBM.best_score_))

2.调试的参数是min_child_weight以及max_depth:

  1. # 调试的参数是min_child_weight以及max_depth:
  2. cv_params = {'max_depth': [3, 4, 5, 6, 7, 8, 9, 10], 'min_child_weight': [6,7,8]}
  3. other_params = {'learning_rate': 0.1, 'n_estimators': 20, 'max_depth': 5, 'min_child_weight': 1, 'seed': 0,
  4. 'subsample': 0.8, 'colsample_bytree': 0.8, 'gamma': 0, 'reg_alpha': 0, 'reg_lambda': 1}
  5. model = XGBRegressor(**other_params)
  6. optimized_GBM = GridSearchCV(estimator=model, param_grid=cv_params, scoring='r2', cv=3, verbose=1, n_jobs=-1)
  7. optimized_GBM.fit(x_data, y_data)
  8. evalute_result =optimized_GBM.return_train_score
  9. print('每轮迭代运行结果:{0}'.format(evalute_result))
  10. print('参数的最佳取值:{0}'.format(optimized_GBM.best_params_))
  11. print('最佳模型得分:{0}'.format(optimized_GBM.best_score_))

3.调试参数:gamma:

  1. # 调试参数:gamma:
  2. cv_params = {'gamma': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]}
  3. other_params = {'learning_rate': 0.1, 'n_estimators': 20, 'max_depth': 4, 'min_child_weight': 6, 'seed': 0,
  4. 'subsample': 0.8, 'colsample_bytree': 0.8, 'gamma': 0, 'reg_alpha': 0, 'reg_lambda': 1}
  5. model = XGBRegressor(**other_params)
  6. optimized_GBM = GridSearchCV(estimator=model, param_grid=cv_params, scoring='r2', cv=3, verbose=1, n_jobs=-1)
  7. optimized_GBM.fit(x_data, y_data)
  8. evalute_result =optimized_GBM.return_train_score
  9. print('每轮迭代运行结果:{0}'.format(evalute_result))
  10. print('参数的最佳取值:{0}'.format(optimized_GBM.best_params_))
  11. print('最佳模型得分:{0}'.format(optimized_GBM.best_score_))

4. 调试subsample以及colsample_bytree:

  1. # 调试subsample以及colsample_bytree:
  2. cv_params = {'subsample': [0.6, 0.7, 0.8, 0.9], 'colsample_bytree': [0.6, 0.7, 0.8, 0.9]}
  3. other_params = {'learning_rate': 0.1, 'n_estimators': 20, 'max_depth': 4, 'min_child_weight': 6, 'seed': 0,
  4. 'subsample': 0.8, 'colsample_bytree': 0.8, 'gamma': 0.2, 'reg_alpha': 0, 'reg_lambda': 1}
  5. model = XGBRegressor(**other_params)
  6. optimized_GBM = GridSearchCV(estimator=model, param_grid=cv_params, scoring='r2', cv=3, verbose=1, n_jobs=4)
  7. optimized_GBM.fit(x_data, y_data)
  8. evalute_result =optimized_GBM.return_train_score
  9. print('每轮迭代运行结果:{0}'.format(evalute_result))
  10. print('参数的最佳取值:{0}'.format(optimized_GBM.best_params_))
  11. print('最佳模型得分:{0}'.format(optimized_GBM.best_score_))

5.调试reg_alpha以及reg_lambda:

  1. # 调试reg_alpha以及reg_lambda:
  2. cv_params = {'reg_alpha': [0.05, 0.1, 1, 2, 3], 'reg_lambda': [0.05, 0.1, 1, 2, 3]}
  3. other_params = {'learning_rate': 0.1, 'n_estimators': 20, 'max_depth': 4, 'min_child_weight': 6, 'seed': 0,
  4. 'subsample': 0.8, 'colsample_bytree': 0.9, 'gamma': 0.2, 'reg_alpha': 0, 'reg_lambda': 1}
  5. model = XGBRegressor(**other_params)
  6. optimized_GBM = GridSearchCV(estimator=model, param_grid=cv_params, scoring='r2', cv=3, verbose=1, n_jobs=4)
  7. optimized_GBM.fit(x_data, y_data)
  8. evalute_result =optimized_GBM.return_train_score
  9. print('每轮迭代运行结果:{0}'.format(evalute_result))
  10. print('参数的最佳取值:{0}'.format(optimized_GBM.best_params_))
  11. print('最佳模型得分:{0}'.format(optimized_GBM.best_score_))

6.调试learning_rate:

  1. # 调试learning_rate,一般这时候要调小学习率来测试:
  2. cv_params = {'learning_rate': [0.01, 0.05, 0.07, 0.1, 0.2]}
  3. other_params = {'learning_rate': 0.1, 'n_estimators': 20, 'max_depth': 4, 'min_child_weight': 6, 'seed': 0,
  4. 'subsample': 0.8, 'colsample_bytree': 0.9, 'gamma': 0.2, 'reg_alpha': 0.1, 'reg_lambda': 1}
  5. model = XGBRegressor(**other_params)
  6. optimized_GBM = GridSearchCV(estimator=model, param_grid=cv_params, scoring='r2', cv=3, verbose=1, n_jobs=4)
  7. optimized_GBM.fit(x_data, y_data)
  8. evalute_result =optimized_GBM.return_train_score
  9. print('每轮迭代运行结果:{0}'.format(evalute_result))
  10. print('参数的最佳取值:{0}'.format(optimized_GBM.best_params_))
  11. print('最佳模型得分:{0}'.format(optimized_GBM.best_score_))

Xgboost参数调节的更多相关文章

  1. XGBoost参数调优

    XGBoost参数调优 http://blog.csdn.net/hhy518518/article/details/54988024 摘要: 转载:http://blog.csdn.NET/han_ ...

  2. XGBoost参数调优完全指南(附Python代码)

    XGBoost参数调优完全指南(附Python代码):http://www.2cto.com/kf/201607/528771.html https://www.zhihu.com/question/ ...

  3. XGBoost参数

    XGBoost参数 转自http://blog.csdn.net/zc02051126/article/details/46711047 在运行XGboost之前,必须设置三种类型成熟:general ...

  4. linux 内核参数VM调优 之 参数调节和场景分析

    1. pdflush刷新脏数据条件 (linux IO 内核参数调优 之 原理和参数介绍)上一章节讲述了IO内核调优介个重要参数参数. 总结可知cached中的脏数据满足如下几个条件中一个或者多个的时 ...

  5. xgboost 参数

    XGBoost 参数 在运行XGBoost程序之前,必须设置三种类型的参数:通用类型参数(general parameters).booster参数和学习任务参数(task parameters). ...

  6. (转)linux IO 内核参数调优 之 参数调节和场景分析

    1. pdflush刷新脏数据条件 (linux IO 内核参数调优 之 原理和参数介绍)上一章节讲述了IO内核调优介个重要参数参数. 总结可知cached中的脏数据满足如下几个条件中一个或者多个的时 ...

  7. inux IO 内核参数调优 之 参数调节和场景分析

    http://backend.blog.163.com/blog/static/2022941262013112081215609/ http://blog.csdn.net/icycode/arti ...

  8. 【转】XGBoost参数调优完全指南(附Python代码)

    xgboost入门非常经典的材料,虽然读起来比较吃力,但是会有很大的帮助: 英文原文链接:https://www.analyticsvidhya.com/blog/2016/03/complete-g ...

  9. 机器学习——XGBoost大杀器,XGBoost模型原理,XGBoost参数含义

    0.随机森林的思考 随机森林的决策树是分别采样建立的,各个决策树之间是相对独立的.那么,在我们得到了第k-1棵决策树之后,能否通过现有的样本和决策树的信息, 对第m颗树的建立产生有益的影响呢?在随机森 ...

随机推荐

  1. Same Tree 深度优先

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  2. Mac终端打开AndroidStudio已创建模拟器

    目的 偶尔我们只是想运行模拟器,并不想打开AndroidStudio,这时我们可以从终端找到emulator,通过emulator来启动指定名称的模拟器 步骤 1.找到emulator所在位置 fin ...

  3. 【Mysql的那些事】数据库之ORM操作

    1:ORM的基础操作(必会) <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 <3> get(* ...

  4. 【UTR #1】ydc的大树

    [UTR #1]ydc的大树 全网唯一一篇题解我看不懂 所以说一下我的O(nlogn)做法: 以1号点为根节点 一个黑点如果有多个相邻的节点出去都能找到最远的黑点,那么这个黑点就是无敌的 所以考虑每个 ...

  5. LA 4119 Always an integer (数论+模拟)

    ACM-ICPC Live Archive 一道模拟题,题意是问一个给出的多项式代入正整数得到的值是否总是整数. 这题是一道数论题,其实对于这个式子,我们只要计算1~最高次项是否都满足即可. 做的时候 ...

  6. Project Euler Problem 7-10001st prime

    素数线性筛 MAXN = 110100 prime = [0 for i in range(210000)] for i in range(2,MAXN): if prime[i] == 0: pri ...

  7. Python--day24--继承

    A_son.__bases__查看继承的父类是哪些 A. object是所有类的祖宗,所有的类都默认继承了object类. python中可以多继承 继承与抽象,先抽象再继承: example:

  8. [转]C#操作word模板插入文字、图片及表格详细步骤

    c#操作word模板插入文字.图片及表格 1.建立word模板文件 person.dot用书签 标示相关字段的填充位置 2.建立web应用程序 加入Microsoft.Office.Interop.W ...

  9. 【js】vue 2.5.1 源码学习 (七) 初始化之 initState 响应式系统基本思路

    大体思路(六) 本节内容: 一.生命周期的钩子函数的实现 ==> callHook(vm , 'beforeCreate') beforeCreate 实例创建之后 事件数据还未创建 二.初始化 ...

  10. js基础——面向对象(构造函数)

    1.面向对象:类的标志,通过类可创建多个具有相同属性和方法的对象 2.创建对象 1)工厂模式方式:避免重复实例化但未能解决识别问题  function boss(name, age) {       ...