0
0
Computer Visionml~10 mins

Evaluation and confusion matrix in Computer Vision - 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.

Computer Vision
from sklearn.metrics import [1]
Drag options to blanks, or click blank then click option'
Atrain_test_split
Bconfusion_matrix
Cclassification_report
Daccuracy_score
Attempts:
3 left
💡 Hint
Common Mistakes
Importing accuracy_score instead of confusion_matrix
Importing train_test_split which is for splitting data
2fill in blank
medium

Complete the code to calculate accuracy from true and predicted labels.

Computer Vision
accuracy = sum(y_true == y_pred) / [1]
Drag options to blanks, or click blank then click option'
Alen(y_pred)
Bsum(y_pred)
Clen(y_true)
Dsum(y_true)
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by sum of predictions instead of total samples
Using length of predictions which might differ if data is inconsistent
3fill in blank
hard

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

Computer Vision
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
Passing undefined variable names
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that counts true positives for each class.

Computer Vision
true_positives = {cls: sum((y_true == cls) & ([1] == cls)) for cls in [2]
Drag options to blanks, or click blank then click option'
Ay_pred
By_true
Cclasses
Dlabels
Attempts:
3 left
💡 Hint
Common Mistakes
Using y_true instead of y_pred in the condition
Using undefined variable names for classes
5fill in blank
hard

Fill all three blanks to compute precision for each class from the confusion matrix.

Computer Vision
precision = {j: cm[[1], [2]] / sum(cm[:, [3]]) for j in classes}
Drag options to blanks, or click blank then click option'
Ai
Bj
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing row and column indices
Dividing by sum over rows instead of columns