1from sklearn.metrics import confusion_matrix, plot_confusion_matrix
2
3clf = # define your classifier (Decision Tree, Random Forest etc.)
4clf.fit(X, y) # fit your classifier
5
6# make predictions with your classifier
7y_pred = clf.predict(X)
8
9# get true negative (tn), false positive (fp)
10# false negative (fn) and true positive (tp)
11# from confusion matrix
12M = confusion_matrix(y, y_pred)
13tn, fp, fn, tp = M.ravel()
14
15recall = tp / (tp + fn) # definition of recall
16precision = tp / (tp + fp) # definition of precision