Answers for "confusion matrix precision recall f1 score"

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

Code answers related to "confusion matrix precision recall f1 score"

Python Answers by Framework

Browse Popular Code Answers by Language