2021-05-08 13:28:34 +02:00
|
|
|
import pandas as pd
|
|
|
|
import numpy as np
|
|
|
|
from tensorflow import keras
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
from keras import backend as K
|
2021-05-13 17:05:07 +02:00
|
|
|
from sklearn.metrics import mean_squared_error
|
2021-05-08 13:28:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
# zaladowanie modelu
|
2021-05-13 17:42:16 +02:00
|
|
|
avocado_model = 'avocado_model.h5'
|
2021-05-08 13:28:34 +02:00
|
|
|
model = keras.models.load_model(avocado_model)
|
|
|
|
|
|
|
|
# odczytanie danych z plikow
|
|
|
|
avocado_train = pd.read_csv('avocado_train.csv')
|
|
|
|
avocado_test = pd.read_csv('avocado_test.csv')
|
|
|
|
avocado_validate = pd.read_csv('avocado_validate.csv')
|
|
|
|
|
|
|
|
# podzial na X i y
|
|
|
|
X_train = avocado_train[['average_price', 'total_volume', '4046', '4225', '4770', 'total_bags', 'small_bags', 'large_bags', 'xlarge_bags']]
|
|
|
|
y_train = avocado_train[['type']]
|
|
|
|
X_test = avocado_test[['average_price', 'total_volume', '4046', '4225', '4770', 'total_bags', 'small_bags', 'large_bags', 'xlarge_bags']]
|
|
|
|
y_test = avocado_test[['type']]
|
|
|
|
|
2021-05-13 17:05:07 +02:00
|
|
|
# prediction
|
|
|
|
predictions = model.predict(X_test)
|
|
|
|
#pd.DataFrame(predictions).to_csv('prediction_results.csv')
|
|
|
|
|
2021-05-08 13:28:34 +02:00
|
|
|
# ewaluacja
|
2021-05-13 17:05:07 +02:00
|
|
|
error = mean_squared_error(y_test, predictions)
|
|
|
|
print('Error: ', error)
|
|
|
|
|
|
|
|
with open('eval_results.txt', 'a') as f:
|
|
|
|
f.write(str(error) + "\n")
|
|
|
|
|
|
|
|
# wykres
|
2021-05-13 17:57:54 +02:00
|
|
|
with open('eval_results.txt', 'r') as f:
|
2021-05-13 17:05:07 +02:00
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
|
|
|
|
fig = plt.figure(figsize=(5,5))
|
|
|
|
chart = fig.add_subplot()
|
|
|
|
chart.set_ylabel("RMSE")
|
|
|
|
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("eval_plot.png")
|