'how do I calculate TAR (%) @ FAR = 0.1% in Python?
I was reading a paper and the results in the paper are presented in the following way:
I want to have a similar table for my model. Using the below code I got FAR and TAR values.
from sklearn import metrics
test = [0, 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,1, 0]
pred = [0.04172871, 0.01611879, 0.01073375, 0.03344169 ,0.04172871, 0.04172871, 0.00430162 ,0.04172871 ,0.04172871 ,0.04172871 ,0.07977659, 0.905772,0.9396076, 0.03344169, 0.04172871, 0.09125287, 0.02964183, 0.0641269,0.04172871 ,0.04172871, 0.04172871, 0.0641269 , 0.04172871, 0.04172871,0.9919831 , 0.04172871, 0.01611879 ,0.04172871, 0.37865442 ,0.00240888]
far, tar, thresholds = metrics.roc_curve(Y_test,p)
How should I fix FAR = 0.1% and How do I calculate TAR% @FAR = 0.1% using Python?
Solution 1:[1]
If you're familiar with ROC curve you know the curve itself does not give any specific value of TRP (True Positive Rate) and FPR (False positive Rate) for you model. It Simply track the evolution of TPR against FPR as you move some threshold over the distribution produced by the model.
So, if you want to calculate TPR at FPR=0.1% you have a couple of choices:
You either have the value FPR = 0.1% in far and you just have to retrieve its index to get the corresponding TRP or tar at the same position.
Or you do not have the exact value FPR=0.1% in far and in this case you can get the corresponding tuple (far, tar) below and above the value 0.1% and perform linear interpolation to compute the exact value.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yoan B. M.Sc |

