0
0
TensorFlowml~10 mins

Confusion matrix visualization in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function that computes the confusion matrix.

TensorFlow
from sklearn.metrics import [1]
Drag options to blanks, or click blank then click option'
Aclassification_report
Broc_auc_score
Caccuracy_score
Dconfusion_matrix
Attempts:
3 left
💡 Hint
Common Mistakes
Importing accuracy_score instead of confusion_matrix
Using classification_report which summarizes metrics but does not return the matrix
Trying to import from tensorflow instead of sklearn.metrics
2fill in blank
medium

Complete the code to compute the confusion matrix from true and predicted labels.

TensorFlow
cm = [1](y_true, y_pred)
Drag options to blanks, or click blank then click option'
Aconfusion_matrix
Bmean_squared_error
Caccuracy_score
Droc_curve
Attempts:
3 left
💡 Hint
Common Mistakes
Using accuracy_score which returns a scalar accuracy value
Using mean_squared_error which is for regression
Using roc_curve which returns false positive and true positive rates
3fill in blank
hard

Fix the error in the code to plot the confusion matrix using matplotlib.

TensorFlow
import matplotlib.pyplot as plt
plt.imshow(cm, cmap=[1])
plt.colorbar()
plt.show()
Drag options to blanks, or click blank then click option'
A'viridis'
B'blue'
C'red'
D'gray'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single color name like 'blue' which is invalid for cmap
Passing a list or tuple instead of a string
Omitting the cmap argument causing default colors
4fill in blank
hard

Fill both blanks to add axis labels to the confusion matrix plot.

TensorFlow
plt.xlabel([1])
plt.ylabel([2])
Drag options to blanks, or click blank then click option'
A'Predicted label'
B'True label'
C'Accuracy'
D'Loss'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping true and predicted labels
Using metric names like 'Accuracy' instead of axis labels
Omitting axis labels
5fill in blank
hard

Fill all three blanks to create a normalized confusion matrix and plot it with labels.

TensorFlow
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()
Drag options to blanks, or click blank then click option'
A1
BTrue
C'Blues'
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using axis=0 which normalizes columns instead of rows
Setting keepdims=False causing shape errors
Using an invalid colormap name