ium_434780/eval-tensorflow.py
sadurska@trui.pl 7a59073183
All checks were successful
s434780-evaluation/pipeline/head This commit looks good
Evaluation
2021-05-17 12:37:21 +02:00

41 lines
986 B
Python

import pandas as pd
import numpy as np
from tensorflow import keras
from sklearn.metrics import accuracy_score, f1_score
import matplotlib.pyplot as plt
model = keras.models.load_model('trained_model')
test_df = pd.read_csv('test.csv')
test_x = test_df['reviews.text'].to_numpy()
test_y = test_df['reviews.doRecommend'].to_numpy()
# print(test_y.shape)
# print(test_x.shape)
predictions = model.predict(test_x)
predictions = [1 if p > 0.5 else 0 for p in predictions]
accuracy = accuracy_score(test_y, predictions)
f1 = f1_score(test_y, predictions)
file = open('evaluation.txt', 'a')
file.writelines(accuracy.__str__() + '\n')
file.close()
with open('evaluation.txt', 'r') as f:
lines = f.readlines()
fig = plt.figure(figsize=(10, 5))
chart = fig.add_subplot()
chart.set_title("Accuracy")
chart.set_ylabel("Accuracy value")
chart.set_xlabel("Build number")
x = np.arange(0, len(lines), 1)
y = [float(x) for x in lines]
plt.plot(x, y)
plt.savefig("evaluation-chart.png")