Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xgboost sklearn wrapper value 0for Parameter num_class should be greater equal to 1

Tags:

I am trying to use the XGBClassifier wrapper provided by sklearn for a multiclass problem. My classes are [0, 1, 2], the objective that I use is multi:softmax. When I am trying to fit the classifier I get

xgboost.core.XGBoostError: value 0for Parameter num_class should be greater equal to 1

If I try to set the num_class parameter the I get the error

got an unexpected keyword argument 'num_class'

Sklearn is setting this parameter automatically so I am not supposed to pass that argument. But why do I get the first error?

like image 231
LetsPlayYahtzee Avatar asked Oct 18 '16 19:10

LetsPlayYahtzee


1 Answers

You need to manually add the parameter num_class to the xgb_param

    # Model is an XGBClassifier
    xgb_param = model.get_xgb_params()
    xgb_param['num_class'] = 3
    cvresult = xgb.cv(xgb_param, ...)

The XGBClassifier does set this value automatically if you use its fit method, but does not in the cv method

like image 172
mxdbld Avatar answered Sep 29 '22 17:09

mxdbld