Xgboost fit won't recognize my custom eval_metric. Why?
Do you know why my custom_eval_metric doesn't work? I get the error:
XGBoostError: [07:56:32] C:\Users\Administrator\workspace\xgboost-win64_release_1.4.0\src\metric\metric.cc:49: Unknown metric function custom_eval_metric
def custom_eval_metric(preds, dtrain):
labels = dtrain.get_label()
preds = preds.reshape(-1, 3)
preds_binary = []
for element in range(0,len(preds)):
tmp = []
tmp = preds[element][2]
preds_binary.append(tmp)
labels_adj = [0 if x == 1 else x for x in labels]
labels_adj = [1 if x == 2 else x for x in labels_adj]
preds_binary = np.asarray([preds_binary])
labels_adj = np.asarray([labels_adj])
return 'ndcg score', metrics.ndcg_score(new_items, preds)
clf_xgb_out_of_sample = xgb.XGBClassifier(objective = multi:softmax,
num_class=3,
seed = 42,
n_estimators=2,
max_depth = 8,
learning_rate = 0.1,
gamma = 0.25,
colsample_bytree = 0.8,
use_label_encoder=False)
clf_xgb_out_of_sample.fit(X_train,
y_train,
sample_weight=weights,
verbose = True,
early_stopping_rounds = 10,
eval_metric='custom_eval_metric',
eval_set = [(X_test, y_test['Target'])])
Topic error-handling classification
Category Data Science