True Positive = output labels that are predicted to be True and they are actually True = 4
True Negative = the output labels that are predicted to be False and they are actually False also = 4
False Positive = the output labels that are predicted to be True but they are actually False = 1
False Negative = output labels that are predicted to be False but they are actually True = 1
Precision in machine learning is defined as:
And recall in machine learning is defined as:
So, in our example, TP = 4, FP = 1, FN = 1
So,
And
How to calculate precision and recall using the sklearn Python library?
We can use the following Python code to calculate the precision and recall of a machine learning model.
from sklearn.metrics import precision_score, recall_score
Ya = [False, False, True, True, True, False, True, False, False, True]
Y = [True, False, True, True, False, False, True, False, False, True]
precision = precision_score(Ya, Y)
recall = recall_score(Ya, Y)
print("Precision: ", precision)
print("Recall: ", recall)
Please note that here Ya is the actual or expected output. And Y is the predicted or calculated output. The output of the above program will be:
Precision: 0.8 Recall: 0.8








































0 Comments