0
0
TensorFlowml~10 mins

Confusion matrix analysis 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 a confusion matrix.

TensorFlow
from sklearn.metrics import [1]
Drag options to blanks, or click blank then click option'
Aaccuracy_score
Bconfusion_matrix
Cclassification_report
Droc_auc_score
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 = confusion_matrix([1], y_pred)
Drag options to blanks, or click blank then click option'
Apredictions
By_pred
Clabels
Dy_true
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping true and predicted labels
Using variable names that do not exist in the code
3fill in blank
hard

Fix the error in the code to display the confusion matrix as a heatmap using matplotlib.

TensorFlow
import matplotlib.pyplot as plt
import seaborn as sns
sns.heatmap([1], annot=True, fmt='d')
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.show()
Drag options to blanks, or click blank then click option'
Acm
By_true
Cy_pred
Dconfusion_matrix
Attempts:
3 left
💡 Hint
Common Mistakes
Passing true or predicted labels instead of the matrix
Passing the function name instead of the matrix variable
4fill in blank
hard

Fill both blanks to calculate precision and recall from the confusion matrix.

TensorFlow
precision = cm[[1], [2]] / cm[:, [2]].sum()
Drag options to blanks, or click blank then click option'
A1
B0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices for true positives
Summing over rows instead of columns
5fill in blank
hard

Fill all three blanks to calculate recall from the confusion matrix.

TensorFlow
recall = cm[[1], [2]] / cm[[3], :].sum()
Drag options to blanks, or click blank then click option'
A1
B0
Attempts:
3 left
💡 Hint
Common Mistakes
Using column sums instead of row sums
Using wrong indices for true positives