xgboost python分类_xgboost(python)中的多类分类

我不知道如何用目标函数“multi:softmax”将类数或求值度量传递给xgb.XGBClassifier。

我看了很多文档,但只谈到了接受núclass/numúclass的sklearn包装器。

我当前的设置看起来像kf = cross_validation.KFold(y_data.shape[0], \

n_folds=10, shuffle=True, random_state=30)

err = [] # to hold cross val errors

# xgb instance

xgb_model = xgb.XGBClassifier(n_estimators=_params['n_estimators'], \

max_depth=params['max_depth'], learning_rate=_params['learning_rate'], \

min_child_weight=_params['min_child_weight'], \

subsample=_params['subsample'], \

colsample_bytree=_params['colsample_bytree'], \

objective='multi:softmax', nthread=4)

# cv

for train_index, test_index in kf:

xgb_model.fit(x_data[train_index], y_data[train_index], eval_metric='mlogloss')

predictions = xgb_model.predict(x_data[test_index])

actuals = y_data[test_index]

err.append(metrics.accuracy_score(actuals, predictions))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python使用XGBoost进行多分类任务,首先需要导入xgboost库和sklearn.metrics库。接下来,你可以使用xgboost库提供的XGBClassifier类来创建一个分类器模型。在创建模型时,需要设置参数n_classes来指定分类的数量。然后,使用fit方法拟合模型并使用predict方法进行预测。最后,可以使用sklearn.metrics库的accuracy_score函数来评估模型的准确性。这个函数可以将预测结果与真实标签进行比较并计算出准确率。 需要注意的是,如果你想使用XGBoost的分布式版本(pyspark)来进行多分类任务,可以参考xgboost的分布式版本(pyspark)使用测试。在使用分布式版本时,还需要确保xgboost的版本号和sparkxgb内的内容相对应。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Spark实现xgboost分类(python)](https://blog.csdn.net/rosefun96/article/details/107081994)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [XGBoost 分类模型的Python实现](https://blog.csdn.net/Oscar6280868/article/details/81117567)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值