2
$\begingroup$

I am building my model in Python to classify customer in buyer/ non-buyer category. I used mutiple agorithms for this problem and then after evaluation selecting the best out of all.

sklearn package in python gives me an array of FPR,TPR and threshold for all my predicted records.

While analyzing the value of FPR,TPR and threshold I got confused how to interpret threshold value. I am getting threshold value for each record.

For example: My testing dataset consist of 100 records tehn I got array of size 100 for TPR,FPR and threshold.

How to decide the optimium threshold for my model using these values??

from sklearn import metrics
fpr, tpr,threshold = metrics.roc_curve( Y_test, status[:,1])
$\endgroup$

1 Answer 1

2
$\begingroup$

I’m willing to bet that you have a 100 value array for both the ROC and the data by coincidence. You aren’t getting a threshold for each data record but for each threshold evaluated.

At this point, you have to define what ‘optimal’ means in your context. By default (in many R packages at least), sensitivity and specificity are equally weighted, in which case the ‘optimal’ threshold corresponds roughly to the threshold where a 45 degree tangent line intersects the ROC curve. You can choose any threshold you want for a given ROC, depending on how you weight sense/spec. R has a few packages that help compute that; I’d be surprised if Python did not have an equivalent.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.