I am using XGBClassifier (in xgboost) for a multi-class classification. Upon executing the classifier, I am receiving an error stating:
unexpected keyword argument 'num_class'
Code that caused this error is listed below (params is a valid set of parameters for xgb):
xgb.XGBClassifier(params, num_class=100)
I searched a bit and found that 'num_class' parameter is named 'n_classes' for scikit implementation of XGBClassifier. I tried this change and received a similar error:
unexpected keyword argument 'n_classes'
Code that caused this error is listed below:
xgb.XGBClassifier(params, num_class=100)
Any help in fixing this error is appreciated!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With