def Find_Optimal_Cutoff(TPR, FPR, threshold):y = TPR - FPRYouden_index = np.argmax(y)#阈值optimal_threshold = threshold[Youden_index]#阈值对应的点point = [FPR[Youden_index], TPR[Youden_index]]return optimal_threshold, pointtest_fpr, test_tpr, test_thresholds = roc_curve(y_test_two_model, y_test_predict_proba, pos_label=1)optimal_th, optimal_point = Find_Optimal_Cutoff(TPR=test_tpr, FPR=test_fpr, threshold=test_thresholds)plt.title('ROC Validation')
plt.plot(test_fpr, test_tpr, 'b', label=str(clfsname[n])+' AUC = %0.3f' % test_roc_auc)
plt.legend(loc='lower right')
plt.plot([0, 1], [0, 1], 'r--')
plt.plot(optimal_point[0], optimal_point[1], marker='o', color='r')
plt.text(optimal_point[0], optimal_point[1], f'Threshold:{optimal_th:.2f}')
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.ylabel('True Positive Rate')
plt.xlabel('False Positive Rate')
plt.savefig(temp_path + str(clfsname[n]) +'预测率曲线.jpg')
plt.show()