xgboost 查看 学习曲线

1.首先升级xgboost的版本

我的是1.5.2

查看版本代码:

import xgboost

xgboost.__version__

2.其次查看可以使用的metric:https://xgboost.readthedocs.io/en/latest/parameter.html#learning-task-parametersicon-default.png?t=M276https://xgboost.readthedocs.io/en/latest/parameter.html#learning-task-parameters

另外可以自己写metric函数:

Custom Objective and Evaluation Metric — xgboost 1.6.0-dev documentationicon-default.png?t=M276https://xgboost.readthedocs.io/en/latest/tutorials/custom_metric_obj.html可参考:

r - What is difference between eval_metric and feval in xgboost? - Stack Overflowhttps://stackoverflow.com/questions/40159415/what-is-difference-between-eval-metric-and-feval-in-xgboost

3.怎么设置

代码如下,其中顺便查看了r方的值:

evalset = [(X_train_0328_651990, y_train_0328_651990), (X_test_0328_651990,y_test_0328_651990)]
my_model_0328_651990 = XGBRegressor(n_estimators=100, max_depth=5, min_child_weight=1,learning_rate=0.1,gpu_id='0',seed=42)#(n_estimators=1000, learning_rate=0.05,gpu_id='0')
my_model_0328_651990.fit(X_train_0328_651990, y_train_0328_651990,eval_set=evalset,eval_metric='mae')

y_pred = my_model_0328_651990.predict(X_test_0328_651990)
mse = mean_absolute_error(y_test_0328_651990, y_pred)
r2=r2_score(y_true=y_test_0328_651990, y_pred=y_pred)
print(mse,r2)

results = my_model_0328_651990.evals_result()
# plot learning curves
print(results.keys(),results['validation_0'].keys())
plt.plot(results['validation_0']['mae'], label='train')
plt.plot(results['validation_1']['mae'], label='test')
# show the legend
plt.legend()
# show the plot
plt.show()

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值