Skip to content

Instantly share code, notes, and snippets.

@ahmedshahriar
Created June 8, 2020 17:52
Show Gist options
  • Save ahmedshahriar/56652aa1d92515a0a389bd45b090a950 to your computer and use it in GitHub Desktop.
Save ahmedshahriar/56652aa1d92515a0a389bd45b090a950 to your computer and use it in GitHub Desktop.
This sample code works on binary classification to generatre True Positive Rate and False Positive Rate (TPR, FPR) by class.
"""This sample code works on binary classification to generatre True Positive Rate and False Positive Rate (TPR, FPR) by class.
Yes denotes positive class and No denotes negative class.
Default value 0 and 1.
Created by Ahmed Shahriar Sakib @ahmedshahriar on 06.08.2020 """
yes_tp = 0
yes_fp = 0
no_tp = 0
no_fp = 0
yes_instances =0
no_instances = 0
for i in range(len(predictions)):
if y_test[i] == 0:
no_instances+=1
if predictions[i]==y_test[i]:
no_tp+=1
else:
yes_fp+=1
# print("for 0 : ",predictions[i]==y[i])
if y_test[i] == 1:
yes_instances+=1
if predictions[i]==y_test[i]:
yes_tp+=1
else:
no_fp+=1
# print("for 1 : ",predictions[i]==y[i],y[i],y_test[i],predictions[i])
print("Yes Class -- TP : {} , FP : {} , Instances : {}\nNo Class -- TP : {} , FP : {} , Instances : {}".format(yes_tp,yes_fp,yes_instances,no_tp,no_fp,no_instances))
print("Yes class -- tpr : {},\tfpr : {} ".format(yes_tp/yes_instances,yes_fp/no_instances))
print("No class -- tpr : {},\tfpr : {} ".format(no_tp/no_instances, no_fp/yes_instances))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment