Skip to content

Instantly share code, notes, and snippets.

@PranjalDureja0002
Created March 3, 2021 08:52
Show Gist options
  • Save PranjalDureja0002/38f80781fa9639415111db688503d2f6 to your computer and use it in GitHub Desktop.
Save PranjalDureja0002/38f80781fa9639415111db688503d2f6 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