ium_434695/evaluation.py
s434695 a2b9b274b2
Some checks failed
s434695-evaluation/pipeline/head There was a failure building this commit
evaluation
2021-05-16 23:02:31 +02:00

38 lines
954 B
Python

import pandas as pd
import numpy as np
from tensorflow import keras
import matplotlib.pyplot as plt
from sklearn.metrics import mean_squared_error
vgsales_model = 'vgsales_model.h5'
model = keras.models.load_model(vgsales_model)
vgsales_test = pd.read_csv('test.csv')
vgsales_test['Nintendo'] = vgsales_test['Publisher'].apply(lambda x: 1 if x=='Nintendo' else 0)
X_test = vgsales_test.drop(['Rank','Name','Platform','Year','Genre','Publisher'],axis = 1)
y_test = vgsales_test[['Nintendo']]
predictions = model.predict(X_test)
error = mean_squared_error(y_test, predictions)
print('Error: ', error)
with open('results.txt', 'a') as f:
f.write(str(error) + "\n")
with open('results.txt', 'r') as f:
lines = f.readlines()
fig = plt.figure(figsize=(5,5))
chart = fig.add_subplot()
chart.set_ylabel("MSE")
chart.set_xlabel("Build")
x = np.arange(0, len(lines), 1)
y = [float(x) for x in lines]
plt.plot(x, y, "ro")
plt.savefig("plot.png")