ium_434742/avocado-evaluation.py
patrycjalazna 298d134b46
All checks were successful
s434742-training/pipeline/head This commit looks good
evaluation corrected
2021-05-10 21:33:33 +02:00

42 lines
1.5 KiB
Python

import pandas as pd
import numpy as np
from tensorflow import keras
import matplotlib.pyplot as plt
from keras import backend as K
def recall_m(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
def precision_m(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
def f1_m(y_true, y_pred):
precision = precision_m(y_true, y_pred)
recall = recall_m(y_true, y_pred)
return 2*((precision*recall)/(precision+recall+K.epsilon()))
# 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']]
# ewaluacja
loss, accuracy, f1_score, precision, recall = model.evaluate(X_test, y_test, verbose=0)
# with open('')