我正在尝试使用 scikit-learn 中的 f-score 作为 xgb 分类器中的评估指标。这是我的代码:
clf = xgb.XGBClassifier(max_depth=8, learning_rate=0.004,
n_estimators=100,
silent=False, objective='binary:logistic',
nthread=-1, gamma=0,
min_child_weight=1, max_delta_step=0, subsample=0.8,
colsample_bytree=0.6,
base_score=0.5,
seed=0, missing=None)
scores = []
predictions = []
for train, test, ans_train, y_test in zip(trains, tests, ans_trains, ans_tests):
clf.fit(train, ans_train, eval_metric=xgb_f1,
eval_set=[(train, ans_train), (test, y_test)],
early_stopping_rounds=900)
y_pred = clf.predict(test)
predictions.append(y_pred)
scores.append(f1_score(y_test, y_pred))
def xgb_f1(y, t):
t = t.get_label()
return "f1", f1_score(t, y)
但是有一个错误:Can't handle mix of binary and continuous