0
0
ML Pythonprogramming~10 mins

Classification evaluation (accuracy, precision, recall, F1) 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 calculate accuracy score using sklearn.

ML Python
from sklearn.metrics import [1]

accuracy = [1](y_true, y_pred)
print(f"Accuracy: {accuracy:.2f}")
Drag options to blanks, or click blank then click option'
Aaccuracy_score
Bprecision_score
Crecall_score
Df1_score
Attempts:
3 left
2fill in blank
medium

Complete the code to calculate precision score for binary classification.

ML Python
from sklearn.metrics import precision_score

precision = precision_score(y_true, y_pred, [1]=1)
print(f"Precision: {precision:.2f}")
Drag options to blanks, or click blank then click option'
Azero_division
Baverage
Clabels
Dpos_label
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to calculate recall score correctly.

ML Python
from sklearn.metrics import recall_score

recall = recall_score(y_true, y_pred, average=[1])
print(f"Recall: {recall:.2f}")
Drag options to blanks, or click blank then click option'
A'binary'
B'micro'
C'macro'
D'weighted'
Attempts:
3 left
4fill in blank
hard

Fill both blanks to calculate F1 score with macro averaging.

ML Python
from sklearn.metrics import f1_score

f1 = f1_score(y_true, y_pred, [1]=[2])
print(f"F1 Score: {f1:.2f}")
Drag options to blanks, or click blank then click option'
Aaverage
B'macro'
C'binary'
D'weighted'
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a dictionary of classification metrics.

ML Python
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)
Drag options to blanks, or click blank then click option'
Aaccuracy_score
Bprecision_score
Crecall_score
Df1_score
Attempts:
3 left