ium_444354/evaluation.py

46 lines
1.3 KiB
Python
Raw Normal View History

2022-05-03 22:47:51 +02:00
import pandas as pd
import re
from sklearn import metrics
import numpy as np
2022-05-07 04:46:30 +02:00
import csv
2022-05-07 05:17:49 +02:00
import matplotlib.pyplot as plt
2022-05-09 11:06:01 +02:00
f = open("pytorch/result.txt", "r")
2022-05-03 22:47:51 +02:00
list_result, list_predicted=[],[]
for x in f:
data = x.split(' ')
result = re.findall(r'\d+', data[1])
predicted = re.findall(r'\d+', data[5])
result=int(result[0])
predicted=float('.'.join(predicted))
list_result.append(result)
list_predicted.append(predicted)
2022-05-07 04:46:30 +02:00
metrics = metrics.mean_absolute_error(list_result, list_predicted), metrics.mean_squared_error(list_result, list_predicted),np.sqrt(metrics.mean_absolute_error(list_result, list_predicted))
print("MAE: ", metrics[0])
print("MSE: ",metrics[1])
print("RMSE: ",metrics[2])
with open('eval.csv', 'a+', newline='') as f:
2022-05-07 04:46:30 +02:00
writer = csv.writer(f)
writer.writerow((metrics[0],metrics[1], metrics[2]))
2022-05-07 05:17:49 +02:00
MAE,MSE,RMSE=[],[],[]
with open('eval.csv', 'r') as r:
for row in r:
# row variable is a list that represents a row in csv
row=row.split(',')
MAE.append(float(row[0]))
MSE.append(float(row[1]))
RMSE.append(float(row[2]))
2022-05-07 05:30:34 +02:00
plt.xlabel('build')
2022-05-07 05:25:40 +02:00
plt.plot(np.arange(0, len(MAE)), MAE, label="MAE")
plt.plot(np.arange(0, len(MSE)), MSE, label="MSE")
plt.plot(np.arange(0, len(RMSE)), RMSE, label="RMSE")
2022-05-07 05:30:34 +02:00
plt.legend()
2022-05-07 05:17:49 +02:00
plt.savefig('metrics.png')