Complete the code to calculate accuracy from predictions and labels.
accuracy = sum(predictions == [1]) / len(predictions)
Accuracy compares predicted labels to the true labels.
Complete the code to compute precision score using sklearn.
precision = precision_score([1], predictions)Precision compares true labels (first argument) to predictions.
Fix the error in computing F1 score by filling the missing argument.
f1 = f1_score(labels, predictions, average=[1])For binary classification, average='binary' is required.
Fill both blanks to create a dictionary of recall scores for each class.
recall_scores = {cls: recall_score(labels, predictions, average=[1], labels=[cls]) for cls in [2]Recall per class uses average='binary' and iterates over classes.
Fill all three blanks to compute a confusion matrix and extract true positives.
cm = confusion_matrix([1], [2]) true_positives = cm[[3], [3]]
The confusion matrix compares true labels and predictions. True positives for class 0 are at cm[0, 0].
