Added method for manual testing of hyperparameters
This commit is contained in:
@@ -13,7 +13,7 @@ from pipeline import (
|
||||
prepare_user_data,
|
||||
train_models,
|
||||
evaluate_models,
|
||||
prepare_data_for_model, model_type_gru, model_type_lstm, model_type_bilstm, train_models_v2
|
||||
prepare_data_for_model, model_type_gru, model_type_lstm, model_type_bilstm, train_models_v2, train_one_model
|
||||
)
|
||||
|
||||
year_str = 'Year'
|
||||
@@ -321,11 +321,53 @@ def test(model_type):
|
||||
ignore_index=True)
|
||||
print(results)
|
||||
|
||||
def manual_tuning(model_type):
|
||||
# load dataset
|
||||
sequence_length = 20
|
||||
data_filename = 'ALL32USERS15MIN_WITHTHRESHOLD.xlsx'
|
||||
timespan_id = min_timespan_str
|
||||
threshold_id = with_threshold_str
|
||||
|
||||
file_path = os.path.join(dataset_path, data_filename)
|
||||
df = load_dataset(file_path)
|
||||
df = remove_covid_data(df)
|
||||
|
||||
tr, val, te = split_data_by_userdata_percentage(df, percentages=(80, 10, 10), sample=20)
|
||||
tr = reduce_columns(tr, data_filename)
|
||||
val = reduce_columns(val, data_filename)
|
||||
te = reduce_columns(te, data_filename)
|
||||
|
||||
user_data_train = prepare_user_data(tr)
|
||||
user_data_val = prepare_user_data(val)
|
||||
|
||||
# fit and evaluate model
|
||||
# config
|
||||
repeats = 5
|
||||
n_batch = 4
|
||||
n_epochs = 500
|
||||
n_neurons = 1
|
||||
|
||||
history_list = list()
|
||||
# run diagnostic tests
|
||||
for i in range(repeats):
|
||||
history = train_one_model(user_data_train, user_data_val, n_batch, n_epochs, n_neurons,
|
||||
sequence_length=sequence_length,
|
||||
model_type=model_type)
|
||||
history_list.append(history)
|
||||
for metric in ['p', 'r', 'f1']:
|
||||
for history in history_list:
|
||||
plt.plot(history['train_'+metric], color='blue')
|
||||
plt.plot(history['test_'+metric], color='orange')
|
||||
plt.savefig(figure_path+metric+'_epochs_diagnostic.png')
|
||||
plt.clf()
|
||||
print('Done')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# main_two_v1()
|
||||
# visualise_results_v1()
|
||||
test(model_type=model_type_gru)
|
||||
#test(model_type=model_type_gru)
|
||||
# main_two_v2(model_type=model_type_gru)
|
||||
#visualise_results_v2()
|
||||
manual_tuning(model_type=model_type_lstm)
|
||||
print('Done')
|
||||
|
||||
Reference in New Issue
Block a user