Complete the code to import the function that creates a confusion matrix.
from sklearn.metrics import [1] # Now you can use confusion_matrix() to evaluate predictions
The confusion_matrix function from sklearn.metrics is used to compute the confusion matrix.
Complete the code to compute the confusion matrix for true and predicted labels.
y_true = [0, 1, 0, 1] y_pred = [0, 0, 0, 1] cm = [1](y_true, y_pred) print(cm)
The confusion_matrix function takes true labels and predicted labels to compute the matrix.
Fix the error in the code to correctly compute and print the confusion matrix.
from sklearn.metrics import confusion_matrix y_true = [1, 0, 1, 0] y_pred = [1, 1, 1, 0] cm = confusion_matrix(y_true, [1]) print(cm)
The second argument to confusion_matrix must be the predicted labels, y_pred.
Fill all three blanks to create a confusion matrix and extract true positives and false negatives.
cm = [1](y_true, y_pred) true_positives = cm[[2]][[2]] false_negatives = cm[[2]][[3]]
Use confusion_matrix to get the matrix. For binary classification, true positives are at row 1, column 1 (index 1,1).
False negatives are at row 1, column 0 (index 1,0).
Fill all three blanks to compute the confusion matrix and calculate accuracy manually.
cm = [1](y_true, y_pred) total = cm[[2]][[2]] + cm[[3]][[3]] + cm[[2]][[3]] + cm[[3]][[2]] accuracy = (cm[[2]][[2]] + cm[[3]][[3]]) / total print(f"Accuracy: {accuracy:.2f}")
Use confusion_matrix to get the matrix.
Indices 0 and 1 represent the two classes in binary classification.
Accuracy is the sum of true positives and true negatives divided by total samples.
