Task: Generate a Confusion Matrix
Your task is to implement the function confusion_matrix(data) that generates a confusion matrix for a binary classification problem. The confusion matrix provides a summary of the prediction results on a classification problem, allowing you to visualize how many data points were correctly or incorrectly labeled.
Input:
- A list of lists, where each inner list represents a pair
[y_true, y_pred]for one observation.y_trueis the actual label, andy_predis the predicted label.
Output:
- A 2×2 confusion matrix represented as a list of lists.
Examples
Example 1:
Input:
data = [[1, 1], [1, 0], [0, 1], [0, 0], [0, 1]]
print(confusion_matrix(data))Output:
[[1, 1], [2, 1]]Explanation: The confusion matrix shows the counts of true positives, false negatives, false positives, and true negatives.
Starter Code
from collections import Counter
def confusion_matrix(data):
# Implement the function here
pass
Python3
ReadyLines: 1Characters: 0
Ready