📜  混淆矩阵python代码示例的精度和召回率

📅  最后修改于: 2022-03-11 14:45:21.954000             🧑  作者: Mango

代码示例1
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