Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
2fill in blank
mediumComplete 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'
Attempts:
3 left
3fill in blank
hardFix 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'
Attempts:
3 left
4fill in blank
hardFill 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'
Attempts:
3 left
5fill in blank
hardFill 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'
Attempts:
3 left