From cd0b31d1b322e55b0b75023a040f5d987146704f Mon Sep 17 00:00:00 2001 From: Andrew Hurst Date: Mon, 4 May 2020 04:38:19 -0700 Subject: [PATCH 1/2] Optimization of training model (by val_loss/epoch) --- emelia/classify_tickets.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/emelia/classify_tickets.py b/emelia/classify_tickets.py index 0632301..ae2b98c 100644 --- a/emelia/classify_tickets.py +++ b/emelia/classify_tickets.py @@ -30,10 +30,27 @@ def classify_data(alarm_data, classification_label_data, filepath, # Epochs pass the data n times through the system history = model.fit(x_train, y_train, - epochs=20, + epochs=40, batch_size=20, - validation_data=(x_test, y_test), - verbose=2) + validation_data=(x_test, y_test) #, + #verbose=2 + ) + + # Epoch with lowest validation loss value is found from history of model + + ##print(history.history['val_loss']) + ##print(len(history.history['val_loss'])) + + # best epoch is stored variable to retrain model + best_epoch = history.history['val_loss'].index(min(history.history['val_loss'])) + print('Optimized validation loss value: epoch -' , best_epoch) + + # Model retrained with best epoch and entire training data + history_optimized_alldata = model.fit(x_data, + y_data, + epochs= best_epoch, + batch_size=20, + verbose=2) # saves the model in the filepath listed model.save('./models/' + filepath) From 127dbb63104f8f10773014d1efc343d872356b35 Mon Sep 17 00:00:00 2001 From: Andrew Hurst Date: Mon, 4 May 2020 23:22:30 -0700 Subject: [PATCH 2/2] added recompile of optimized model. refactor model data display --- emelia/classify_tickets.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/emelia/classify_tickets.py b/emelia/classify_tickets.py index ae2b98c..15e2788 100644 --- a/emelia/classify_tickets.py +++ b/emelia/classify_tickets.py @@ -45,21 +45,24 @@ def classify_data(alarm_data, classification_label_data, filepath, best_epoch = history.history['val_loss'].index(min(history.history['val_loss'])) print('Optimized validation loss value: epoch -' , best_epoch) + # recompile model to retrain optimized model + optimized_model = get_compiled_model(input_dimension, input_num, dropout, output) + # Model retrained with best epoch and entire training data - history_optimized_alldata = model.fit(x_data, - y_data, - epochs= best_epoch, - batch_size=20, - verbose=2) + history_optimized_alldata = optimized_model.fit(x_data, + y_data, + epochs= best_epoch, + batch_size=20, + verbose=2) # saves the model in the filepath listed - model.save('./models/' + filepath) + optimized_model.save('./models/' + filepath) # Eval accuracy of model on test data using the test labels in the file - test_results = model.evaluate(x_test, y_test) - train_results = model.evaluate(x_train, y_train) + test_results = optimized_model.evaluate(x_test, y_test) + train_results = optimized_model.evaluate(x_train, y_train) - print(history.model) + print(history_optimized_alldata.model) print("Test Evaluation: " + str(test_results)) print("Train Evaluation: " + str(train_results))