Complete the code to calculate accuracy score using sklearn.
from sklearn.metrics import [1] accuracy = [1](y_true, y_pred) print(f"Accuracy: {accuracy:.2f}")
The accuracy_score function calculates the ratio of correct predictions to total predictions.
Complete the code to calculate precision score for binary classification.
from sklearn.metrics import precision_score precision = precision_score(y_true, y_pred, [1]=1) print(f"Precision: {precision:.2f}")
The pos_label parameter specifies which class is considered positive for precision calculation.
Fix the error in the code to calculate recall score correctly.
from sklearn.metrics import recall_score recall = recall_score(y_true, y_pred, average=[1]) print(f"Recall: {recall:.2f}")
For binary classification, the average parameter should be set to 'binary' to calculate recall correctly.
Fill both blanks to calculate F1 score with macro averaging.
from sklearn.metrics import f1_score f1 = f1_score(y_true, y_pred, [1]=[2]) print(f"F1 Score: {f1:.2f}")
The average parameter set to 'macro' calculates the F1 score by averaging scores for each class equally.
Fill all three blanks to create a dictionary of classification metrics.
metrics = {
'accuracy': [1](y_true, y_pred),
'precision': [2](y_true, y_pred, average='macro'),
'recall': [3](y_true, y_pred, average='macro')
}
print(metrics)This dictionary stores accuracy, precision, and recall scores using the correct sklearn functions.
