Skip to content

Instantly share code, notes, and snippets.

@PranjalDureja0002
Created March 2, 2021 16:43
Show Gist options
  • Save PranjalDureja0002/0e028f5438a837e91a5cbbaeaa21effc to your computer and use it in GitHub Desktop.
Save PranjalDureja0002/0e028f5438a837e91a5cbbaeaa21effc to your computer and use it in GitHub Desktop.
model
def find_best_threshold(threshold, fpr, tpr):
t = threshold[np.argmax(tpr*(1-fpr))]
print("the maximum value of tpr*(1-fpr)", max(tpr*(1-fpr)), "for threshold", np.round(t,3))
return t
def predict_with_best_t(proba, threshold):
predictions = []
for i in proba:
if i>=threshold:
predictions.append(1)
else:
predictions.append(0)
return predictions
best_t = find_best_threshold(tr_thresholds, train_fpr, train_tpr)
best_t_test=find_best_threshold(te_thresholds, test_fpr, test_tpr)
the maximum value of tpr*(1-fpr) 0.9782132727235511 for threshold 0.298
the maximum value of tpr*(1-fpr) 0.9702060771618405 for threshold 0.331
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment