Search code examples
pythonmachine-learningdecision-treexgboostmulticlass-classification

Why does XGBoost only support binary classification


I have noticed that the implementations for XGBoost both in Python and R support only binary classification of a categorical target variable.

  • I have implemented both Random Forest and Extremely Randomised Trees for my classification problem

Why can I not use this method to classify targets coming from multiple categories?

Are there adjustments that can be made to my multiclass dataset in order to use XGBoost?


Solution

  • It does support multi class classification. Below is the code:

    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
    

    You can use num_class as parameter in Python for Multi Class Classification.