IKH

Sensitivity and Specificity in Python

In the last segment, you learnt the importance of having evaluation metrics other than accuracy. Thus, you were introduced to two new metrics – sensitivity and specificity. You learnt the theory of sensitivity and specificity and how to calculate them using a confusion matrix. Now, let’s learn how to calculate these metrics in Python as well.

As you saw in the code, you can access the different elements in the matrix using the following indexing – 

PowerShell
TP = confusion[1,1] # true positive 
TN = confusion[0,0] # true negatives
FP = confusion[0,1] # false positives
FN = confusion[1,0] # false negatives

And now, let’s rewrite the formulas of sensitivity and specificity using the labels of the confusion matrix.

Sensitivity=True Positives\True Positives+False Negatives

Specificity=True Negatives\True Negatives+False Positives

Coming Up

So your model seems to have high accuracy (80.475%) and high specificity (89.931%), but low sensitivity (53.768%) and since you’re interested in identifying the customers which might churn, you clearly need to deal with this. You’ll learn how to do this in the next section.

Report an error