0
0
ML Pythonprogramming~10 mins

Confusion matrix in ML Python - 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 creates a confusion matrix.

ML Python
from sklearn.metrics import [1]

# Now you can use confusion_matrix() to evaluate predictions
Drag options to blanks, or click blank then click option'
Aclassification_report
Bconfusion_matrix
Caccuracy_score
Droc_auc_score
Attempts:
3 left
2fill in blank
medium

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

ML Python
y_true = [0, 1, 0, 1]
y_pred = [0, 0, 0, 1]
cm = [1](y_true, y_pred)
print(cm)
Drag options to blanks, or click blank then click option'
Aaccuracy_score
Bprecision_score
Croc_auc_score
Dconfusion_matrix
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to correctly compute and print the confusion matrix.

ML Python
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)
Drag options to blanks, or click blank then click option'
Aconfusion_matrix
By_true
Cy_pred
Daccuracy_score
Attempts:
3 left
4fill in blank
hard

Fill all three blanks to create a confusion matrix and extract true positives and false negatives.

ML Python
cm = [1](y_true, y_pred)
true_positives = cm[[2]][[2]]
false_negatives = cm[[2]][[3]]
Drag options to blanks, or click blank then click option'
Aconfusion_matrix
B0
C1
Daccuracy_score
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to compute the confusion matrix and calculate accuracy manually.

ML Python
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}")
Drag options to blanks, or click blank then click option'
Aaccuracy_score
Bconfusion_matrix
C0
D1
Attempts:
3 left