xgboost 二分类 选出最好的F1

from sklearn import metrics
#valid_predict是0到1的值,未进行设定阈值划分为0和1
precision, recall, thresholds = metrics.precision_recall_curve(valid_label, valid_predict)
all_f1 = []
for i in range(len(thresholds)):
    f1 = 2*precision[i]*recall[i]/(precision[i]+recall[i])
    all_f1.append(f1)
print("Best F1:"+str(np.max(all_f1)))

你可能感兴趣的:(机器学习,数据挖掘)