Here we are going to see calculations of Error Metrics in python.
Import confusion matrix from sklearn library.
from sklearn.metrics import confusion_matrix
CM1 = confusion_matrix(y_test,predictions) // passing arguements (predictions and actual values)
Build confusion matrix using crosstab function.
CM1 = pd.crosstab(y_test, predictions)
Now let us save True Positive, True Negative, False Positive, False Negative
TP = CM2.iloc[1:1]
TN = CM2.iloc[0:0]
FP = CM2.iloc[0:1]
FN = CM2.iloc[1:0]
Here
TP = 4
TN = 4
FP = 0
FN = 0
Now let us calculate classification error metrics.
Classification Metrics
- Confusion Matrix
- Accuracy
- Misclassification Error
- Specificity
Recall
- we built confusion matrix.
- Accuracy = TP+ TN/ Total Observations (TP+TN+FP+FN) = ((4+4) / 8 )*100 = 100% here.
- Misclassification Error = FP+FN / Total = 0+0 / 8 = 0 here.
- Specificity = TN/TN+FP = (4/4+0 )*100= 100% here.
- Recall = TP/TP+FN = (4/4+0) *100 = 100% here.
- False Negative Rate = FN100/FN +TP = 0100 / 0+4 = 0% here.
See below screenshot for python implementation.