Question - Write a function that when called with a confusion matrix for a binary classification model returns a dictionary with its precision and recall.
Answer -
We can use the below for this purpose:
def calculate_precsion_and_recall(matrix):
true_positive = matrix[0][0]
false_positive = matrix[0][1]
false_negative = matrix[1][0]
return {
'precision': (true_positive) / (true_positive + false_positive),
'recall': (true_positive) / (true_positive + false_negative)
}