Custom Evaluation Function based on F1 for use in xgboost - Python API
问题 I have written the following custom evaluation function to use with xgboost, in order to optimize F1. Umfortuantely it returns an exception when run with xgboost. The evaluation function is the following: def F1_eval(preds, labels): t = np.arange(0, 1, 0.005) f = np.repeat(0, 200) Results = np.vstack([t, f]).T P = sum(labels == 1) for i in range(200): m = (preds >= Results[i, 0]) TP = sum(labels[m] == 1) FP = sum(labels[m] == 0) if (FP + TP) > 0: Precision = TP/(FP + TP) Recall = TP/P if