【干货】 xgboost如何自定义eval_metric ( feval ) ?
来源:互联网 发布:linux怎么运行多线程 编辑:程序博客网 时间:2024/05/21 11:07
,#【干货】 xgboost如何自定义eval_metric ( feval ) ?
转载请注明原文地址:http://blog.csdn.net/weixin_38100489/article/details/78714251
问题来源:xgboost的eval_metric里如果没有你要用的,比如kaggle里有用到的rmsle就没有就需要自己定义。
http://xgboost.readthedocs.io/en/latest/parameter.html
上代码:(把eval_metric变成rmsle的例子)
dtrain=xgb.DMatrix(train_x,train_y)dtest=xgb.DMatrix(test_x,test_y_real)watchlist=[(dtrain,'train'),(dtest,'test')]#############def evalerror(preds, dtrain): # written by myself labels = dtrain.get_label() # return a pair metric_name, result # since preds are margin(before logistic transformation, cutoff at 0) return 'error', math.sqrt(mean_squared_log_error(preds,labels))#############params = { 'objective': 'reg:gamma', 'eta': 0.1, 'seed': 0, #'eval_metric': 'rmse', # if it is useless, delete it 'missing': -999, 'silent' : 1, 'gamma' : 1, 'subsample' : 0.5, 'alpha' : 1, 'max_depth':10, 'min_child_weight':1 }num_rounds=500clf=xgb.train(params,dtrain,num_rounds,watchlist, feval=evalerror)
这样就可以啦,关键就是‘feval=’,在xgb.train内的实参是叫feval,不是叫eval_metric !!!
(上面代码参数我都可以改花了)
xgb.train(params, dtrain, num_boost_round, evals, obj, feval, maximize, early_stopping_rounds, evals_result, verbose_eval, learning_rates, xgb_model, callbacks)
中的第六个。
思路来源是https://www.zhihu.com/question/39496618 上的大神 lau phunter 的回答,https://github.com/dmlc/xgboost/blob/master/demo/guide-python/custom_objective.py
———————————————————————————————————————————————————————
~一把辛酸泪,可费劲了~
我的知乎:https://www.zhihu.com/people/xu-jian-zhi/activities
阅读全文
1 0
- 【干货】 xgboost如何自定义eval_metric ( feval ) ?
- matlab Feval
- feval,str2func
- 干货 | 机器学习集成算法:XGBoost模型构造
- 【干货】如何有效地提问
- xgboost
- xgboost
- xgboost
- xgboost
- xgboost
- xgboost
- xgboost
- XGBoost
- xgboost
- xgboost
- xgboost
- XGBoost
- xgboost
- String中的split(正则表达式)
- 编译原理
- 图解排序--选择排序,插入排序,冒泡排序
- C++智能指针
- 算法(ACM)学习的方法流程
- 【干货】 xgboost如何自定义eval_metric ( feval ) ?
- 【Scikit-Learn 中文文档】Pipeline(管道)和 FeatureUnion(特征联合): 合并的评估器
- numpy初识(1)----python的数据分析包
- ACdream 1073
- 线性回归
- Windows批处理(cmd/bat)常用命令小结
- HtmlAgilityPack官方文档(四)【Traversing】
- 电脑开机显示节电模式,显示器显示不了,是什么原因?
- 【hdu3710】Battle over Cities