Complete the code to import the function that computes the confusion matrix.
from sklearn.metrics import [1]
The confusion_matrix function from sklearn.metrics is used to compute the confusion matrix.
Complete the code to compute the confusion matrix from true and predicted labels.
cm = [1](y_true, y_pred)The confusion_matrix function takes true labels and predicted labels to compute the confusion matrix.
Fix the error in the code to plot the confusion matrix using matplotlib.
import matplotlib.pyplot as plt plt.imshow(cm, cmap=[1]) plt.colorbar() plt.show()
The cmap argument expects a colormap name like 'viridis' to color the matrix visually.
Fill both blanks to add axis labels to the confusion matrix plot.
plt.xlabel([1]) plt.ylabel([2])
The x-axis shows predicted labels and the y-axis shows true labels in a confusion matrix plot.
Fill all three blanks to create a normalized confusion matrix and plot it with labels.
cm_norm = cm / cm.sum(axis=[1], keepdims=[2]) plt.imshow(cm_norm, cmap=[3]) plt.xlabel('Predicted label') plt.ylabel('True label') plt.colorbar() plt.show()
Normalizing by rows (axis=1) with keepdims=True keeps the matrix shape. 'Blues' is a good colormap for normalized matrices.