ium_444517/nn_train_eval.py
Kamila 192b486982
Some checks failed
s444517-training/pipeline/head This commit looks good
s444517-evaluation/pipeline/head There was a failure building this commit
task 2 first half
2022-05-03 12:59:33 +02:00

43 lines
1.1 KiB
Python

from sklearn.metrics import accuracy_score, recall_score
import matplotlib.pyplot as plt
# reading data
def read_data(file_name):
y_pred = []
y_true = []
with open(file_name, encoding="utf-8") as file:
for line in file.readlines():
y_pred.append(line.split(",")[0])
y_true.append(line.split(",")[1][:-1])
return y_pred, y_true
# saving new values
def new_metrics():
y_pred, y_true = read_data("results.txt")
acc = accuracy_score(y_true, y_pred)
recc = recall_score(y_true, y_pred, average='macro')
with open("metrics.txt", 'a') as f:
f.write(f"{acc},{recc}\n")
f.close()
# drawing a plot
def draw_plt():
acc, recc = read_data("metrics.txt")
no_of_entries = list(range(1, len(acc)+1))
print(acc)
print(recc)
plt.plot(no_of_entries, acc, color='green', lw=2, label='Accuracy')
plt.plot(no_of_entries, recc, color='blue', lw=2, label='Recall')
plt.xlabel('Number of builds')
plt.ylabel('Metrics')
plt.legend()
plt.savefig("output.jpg")
new_metrics()
draw_plt()