我有一个关于带有 sklearn API 的 xgboost 分类器的问题。似乎它有一个参数来告诉应该返回多少概率为 True,但我找不到它。
通常,xgb.predict将返回布尔值并xgb.predict_proba返回区间 [0,1] 内的概率。我认为结果是相关的。应该有一个概率阈值来决定样本的类别。
dtrain, dtest = train_test_split(data, test_size=0.1, random_state=22)
param_dict={'base_score': 0.5,
'booster': 'gbtree',
'colsample_bylevel': 1,
'colsample_bytree': 1,
'gamma': 0,
'learning_rate': 0.1,
'max_delta_step': 0,
'max_depth': 4,
'min_child_weight': 6,
'missing': None,
'n_estimators': 1000,
'objective': 'binary:logistic',
'reg_alpha': 0,
'reg_lambda': 1,
'scale_pos_weight': 1,
'subsample': 1}
xgb = XGBClassifier(**param_dict,n_jobs=2)
xgb.fit(dtrain[features], dtrain['target'])
result_boolean = xgb.predict(dtest[features])
print(np.sum(result_boolean))
Output:936
result_proba = xgb.predict_proba(dtest[features])
result_boolean2= (result_proba[:,1] > 0.5)
print(np.sum(result_boolean2))
Output:936
Run Code Online (Sandbox Code Playgroud)
看起来默认概率阈值为 0.5,因此结果数组具有相同数量的 True。但是我在代码中找不到调整它的位置。
predict(data, output_margin=False, ntree_limit=None, validate_features=True)另外,我已经测试过base_score …