import pandas as pd import numpy as np from tensorflow import keras import matplotlib.pyplot as plt from keras import backend as K from sklearn.metrics import mean_squared_error # zaladowanie modelu avocado_model = 'avocado-model.h5' 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']] # prediction predictions = model.predict(X_test) #pd.DataFrame(predictions).to_csv('prediction_results.csv') # ewaluacja error = mean_squared_error(y_test, predictions) print('Error: ', error) with open('eval_results.txt', 'a') as f: f.write(str(error) + "\n") # wykres with open('results.txt', 'r') as f: 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")