Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
755 B
2
Indexable
Never
import pandas as pd
from sklearn.metrics import precision_score, recall_score, accuracy_score, f1_score

# Assuming you have a DataFrame 'df' with true labels 'y_true' and predicted labels 'y_pred'
y_true = df['true_labels']
y_pred = df['predicted_labels']

# Calculate accuracy
accuracy = accuracy_score(y_true, y_pred)

# Calculate precision
precision = precision_score(y_true, y_pred, average='weighted')

# Calculate recall (sensitivity)
recall = recall_score(y_true, y_pred, average='weighted')

# Calculate F1-score (harmonic mean of precision and recall)
f1score = f1_score(y_true, y_pred, average='weighted')

print(f"Accuracy: {accuracy:.4f}")
print(f"Precision: {precision:.4f}")
print(f"Recall: {recall:.4f}")
print(f"F1 Score: {f1score:.4f}")
Leave a Comment