Created
January 21, 2018 05:01
-
-
Save zaxcie/fbcaaa9cd77ebafe1ef1af83a2906d55 to your computer and use it in GitHub Desktop.
Find the cut off point of a binary classification python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Find_Optimal_Cutoff(target, predicted): | |
""" Find the optimal probability cutoff point for a classification model related to event rate | |
Parameters | |
---------- | |
target : Matrix with dependent or target data, where rows are observations | |
predicted : Matrix with predicted data, where rows are observations | |
Returns | |
------- | |
list type, with optimal cutoff value | |
""" | |
fpr, tpr, threshold = roc_curve(target, predicted) | |
i = np.arange(len(tpr)) | |
roc = pd.DataFrame({'tf' : pd.Series(tpr-(1-fpr), index=i), 'threshold' : pd.Series(threshold, index=i)}) | |
roc_t = roc.ix[(roc.tf-0).abs().argsort()[:1]] | |
return list(roc_t['threshold']) |
This is the source code. What are you looking for exactly?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any source code of this function available
plz hepl