ium_464979/IUM_06-metrics.py

26 lines
840 B
Python
Raw Normal View History

2024-05-06 09:17:27 +02:00
import pandas as pd
2024-05-06 19:39:44 +02:00
from sklearn.metrics import accuracy_score, precision_recall_fscore_support, mean_squared_error
from math import sqrt
2024-05-06 20:28:28 +02:00
import sys
2024-05-06 09:17:27 +02:00
2024-05-06 19:39:44 +02:00
# Load the predictions data
data = pd.read_csv('beer_review_sentiment_predictions.csv')
y_pred = data['Predictions']
y_test = data['Actual']
2024-05-06 19:55:12 +02:00
y_test_binary = (y_test >= 3).astype(int)
2024-05-06 09:17:27 +02:00
2024-05-06 20:28:28 +02:00
build_number = sys.argv[1]
2024-05-06 19:39:44 +02:00
# Calculate metrics
2024-05-06 19:55:12 +02:00
accuracy = accuracy_score(y_test_binary, y_pred.round())
2024-05-06 19:58:49 +02:00
precision, recall, f1, _ = precision_recall_fscore_support(y_test_binary, y_pred.round(), average='micro')
2024-05-06 19:39:44 +02:00
rmse = sqrt(mean_squared_error(y_test, y_pred))
2024-05-06 09:17:27 +02:00
2024-05-06 19:39:44 +02:00
print(f'Accuracy: {accuracy}')
print(f'Micro-avg Precision: {precision}')
print(f'Micro-avg Recall: {recall}')
print(f'F1 Score: {f1}')
2024-05-06 20:28:28 +02:00
print(f'RMSE: {rmse}')
with open(r"beer_metrics.txt", "a") as f:
f.write(f"{accuracy},{build_number}\n")