ium_434788/Zadanie_06_evaluate.py
2021-05-15 16:59:57 +02:00

61 lines
1.4 KiB
Python

import pandas as pd
import numpy as np
from tensorflow import keras
import matplotlib.pyplot as plt
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import StandardScaler, LabelEncoder
model = keras.models.load_model('wine_model.h5')
print('evaluating')
data =pd.read_csv('test.csv')
#########################################
y = data['quality']
x = data.drop('quality', axis=1)
citricacid = x['fixed acidity'] * x['citric acid']
citric_acidity = pd.DataFrame(citricacid, columns=['citric_accidity'])
density_acidity = x['fixed acidity'] * x['density']
density_acidity = pd.DataFrame(density_acidity, columns=['density_acidity'])
x = data.join(citric_acidity).join(density_acidity)
print(y)
bins = (2, 5, 8)
gnames = ['bad', 'nice']
y = pd.cut(y, bins = bins, labels = gnames)
enc = LabelEncoder()
yenc = enc.fit_transform(y)
scale = StandardScaler()
scaled_x = scale.fit_transform(x)
##################################
y_pred = model.predict(scaled_x)
y_pred = np.around(y_pred, decimals=0)
results = accuracy_score(yenc,y_pred)
with open('results.txt', 'a+', encoding="UTF-8") as f:
f.write(str(results) +"\n")
with open('results.txt', 'r', encoding="UTF-8") as f:
lines = f.readlines()
fig = plt.figure(figsize=(10,10))
chart = fig.add_subplot()
chart.set_ylabel("Accuracy")
chart.set_xlabel("Number of build")
x = np.arange(0, len(lines), 1)
y = [float(x) for x in lines]
print(y)
plt.plot(x,y,"ro")
plt.savefig("evaluation.png")