Skip to content

Instantly share code, notes, and snippets.

@PranjalDureja0002
Created March 15, 2021 10:08
Show Gist options
  • Save PranjalDureja0002/8d030d51a6ac5aa973613f2225caad77 to your computer and use it in GitHub Desktop.
Save PranjalDureja0002/8d030d51a6ac5aa973613f2225caad77 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment