ium_434784/evaluation.py

55 lines
1.2 KiB
Python
Raw Normal View History

2021-05-16 21:19:00 +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
from sklearn.metrics import mean_squared_error
2021-05-16 22:53:52 +02:00
from tensorflow.keras import layers
from tensorflow.keras.layers.experimental import preprocessing
import tensorflow as tf
2021-05-16 21:19:00 +02:00
2021-05-16 22:22:32 +02:00
train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')
validate = pd.read_csv('validate.csv')
2021-05-16 21:19:00 +02:00
2021-05-16 22:53:52 +02:00
X_train = train.loc[:, train.columns != 'suicides_no']
y_train = train[['suicides_no']]
X_test = test.loc[:, train.columns != 'suicides_no']
y_test = test[['suicides_no']]
normalizer = preprocessing.Normalization()
normalizer.adapt(np.array(X_train))
model = tf.keras.Sequential([
normalizer,
layers.Dense(units=1)
])
model.summary()
model.load_weights('suicide_model.h5')
2021-05-16 22:58:56 +02:00
predictions = model.predict(X_test)
2021-05-16 21:19:00 +02:00
2021-05-16 22:58:56 +02:00
error = mean_squared_error(y_test, predictions)
2021-05-16 21:19:00 +02:00
2021-05-16 22:58:56 +02:00
with open('results.txt', 'a') as f:
f.write(str(error) + "\n")
2021-05-16 23:06:27 +02:00
with open('results.txt', 'r') as f:
lines = f.readlines()
fig = plt.figure(figsize=(10, 5))
chart = fig.add_subplot()
chart.set_ylabel("Mean Squared Error")
chart.set_xlabel("Build number")
x = np.arange(0, len(lines), 1)
y = [float(val) for val in lines]
plt.plot(x, y, "bo")
plt.savefig("plot.png")