XGBClassifier num_class is invalid

后端 未结 1 1615
我在风中等你
我在风中等你 2021-01-05 06:51

I am using XGBClassifier (in xgboost) for a multi-class classification. Upon executing the classifier, I am receiving an error stating:

unexpected keyword a         


        
相关标签:
1条回答
  • 2021-01-05 07:48

    In the Sklearn XGB API you do not need to specify the num_class parameter explicitly. In case the target has more than 2 levels, XGBClassifier automatically switches to multiclass classification mode.

    evals_result = {}
    self.classes_ = list(np.unique(y))
    self.n_classes_ = len(self.classes_)
    
     if self.n_classes_ > 2:
     # Switch to using a multiclass objective in the underlying XGB instance
     xgb_options["objective"] = "multi:softprob"
     xgb_options['num_class'] = self.n_classes_
    

    Check the complete source code here: https://github.com/dmlc/xgboost/blob/master/python-package/xgboost/sklearn.py

    0 讨论(0)
提交回复
热议问题