【问题标题】:Why does XGBoost only support binary classification为什么 XGBoost 只支持二分类
【发布时间】:2020-05-08 12:57:46
【问题描述】:

我注意到 XGBoost 在 Python 和 R 中的实现仅支持分类目标变量的二进制分类。

  • 我已经为我的分类问题实现了随机森林和极端随机树

为什么我不能使用这种方法对来自多个类别的目标进行分类?

是否可以对我的多类数据集进行调整以使用 XGBoost?

【问题讨论】:

    标签: python machine-learning decision-tree xgboost multiclass-classification


    【解决方案1】:

    它确实支持多类分类。下面是代码:

    param = {
        'max_depth': 3,  # the maximum depth of each tree
        'eta': 0.3,  # the training step for each iteration
        'silent': 1,  # logging mode - quiet
        'objective': 'multi:softprob',  # error evaluation for multiclass training
        'num_class': 3}  # the number of classes that exist in this dataset
    

    您可以在 Python 中使用 num_class 作为参数进行多类分类。

    【讨论】:

      【解决方案2】:

      来自XGboost documentation page

      指定学习任务和相应的学习目标。
      目标选项如下:

      • 目标 [default=reg:squarederror]

        • [...]

        • multi:softmax:设置 XGBoost 使用 softmax 目标进行多类分类,您还需要设置 num_class(number of classes)

        • multi:softprob:和softmax一样,但是输出一个ndata * nclass的向量,可以进一步reshape成ndata * nclass矩阵。结果包含属于每个类的每个数据点的预测概率。
        • [...]
      • eval_metric [根据目标默认]
        • [...]
        • merror:多类分类错误率。计算方式为#(错误案例)/#(所有案例)。
        • mlogloss:多类对数损失。

      看起来多类分类有很多选择,只需选择你的武器:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-19
        • 1970-01-01
        相关资源
        最近更新 更多