Skip to content

Instantly share code, notes, and snippets.

@keitazoumana
Created November 19, 2022 11:43
Show Gist options
  • Save keitazoumana/d8c2ce7ec3acc7a6144142ae166df28d to your computer and use it in GitHub Desktop.
Save keitazoumana/d8c2ce7ec3acc7a6144142ae166df28d to your computer and use it in GitHub Desktop.
"""
Individual imports
"""
from sklearn.metrics import precision_score, recall_score, f1_score
y_true = [0, 1, 2, 0, 1, 2]
y_pred = [0, 2, 1, 0, 0, 1]
print("Precision: ", precision_score(y_true, y_pred, average='macro'))
print("Recall: ", recall_score(y_true, y_pred, average='macro'))
print("F1 Score: ", f1_score(y_true, y_pred, average='macro'))
"""
Single Line import
"""
from sklearn.metrics import precision_recall_fscore_support
precision, recall, f1_score, _ = precision_recall_fscore_support(y_true,
y_pred,
average='macro')
print(f"Precision: {precision}")
print(f"Recall: {recall}")
print(f"F1 Score: {f1_score}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment