我无法弄清楚如何使用目标函数'multi:softmax'将数量的类或eval指标传递给xgb.XGBClassifier。
我查看了许多文档,但是关于sklearn包装器的唯一讨论接受了n_class / num_class。
我目前的设置如下
scope.$watch('depts')
答案 0 :(得分:14)
您无需在scikit-learn API中为XGBoost分类设置num_class
。调用fit
时会自动完成。在fit
XGBClassifier
方法的开头xgboost/sklearn.py查看:
evals_result = {}
self.classes_ = np.unique(y)
self.n_classes_ = len(self.classes_)
xgb_options = self.get_xgb_params()
if callable(self.objective):
obj = _objective_decorator(self.objective)
# Use default value. Is it really not used ?
xgb_options["objective"] = "binary:logistic"
else:
obj = None
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_