Answers for "recall formula confusion matrix"

0

precision and recall from confusion matrix python

from sklearn.metrics import confusion_matrix, plot_confusion_matrix

clf = # define your classifier (Decision Tree, Random Forest etc.)
clf.fit(X, y) # fit your classifier

# make predictions with your classifier
y_pred = clf.predict(X) 
        
# get true negative (tn), false positive (fp)
# false negative (fn) and true positive (tp) 
# from confusion matrix
M = confusion_matrix(y, y_pred)
tn, fp, fn, tp = M.ravel() 

recall = tp / (tp + fn)       # definition of recall
precision = tp / (tp + fp)    # definition of precision
Posted by: Guest on July-14-2021
0

recall calculate confusion matrix .ravel()

# tn = True Negative
# fp = False Positive
# fn = False Negative
# tp = True Positive

tn, fp, fn, tp = confusion_matrix(y_test,y_pred).ravel()

#Specificity
specificity = tn/(tn+fp)

# Recall
recall = tp/(tp+fn)
Posted by: Guest on January-22-2022

Python Answers by Framework

Browse Popular Code Answers by Language