Question - Write code to calculate the accuracy of a binary classification algorithm using its confusion matrix.
Answer -
We can use the code given below to calculate the accuracy of a binary classification algorithm:
def accuracy_score(matrix):
true_positives = matrix[0][0]
true_negatives = matrix[1][1]
total_observations = sum(matrix[0]) + sum(matrix[1])
return (true_positives + true_negatives) / total_observations