def pred(facility, model, resolution): filename, columns, irrelevantColumns, targetColumns, traintime, testtime, columnOrder = configs.getConfig(facility, model, resolution) df = mlModule.initDataframe(filename, columns, irrelevantColumns) df_train, df_test = mlModule.getTestTrainSplit(traintime, testtime) X_train, y_train, X_test, y_test = mlModule.getFeatureTargetSplit(targetColumns) mlp_mae = mlModule.MLP('MLP 1x128 d0.2 mae mod'+model, layers=[128], dropout=0.2, loss='mean_absolute_error', metrics=['mean_absolute_error']) mlp_mse = mlModule.MLP('MLP 1x128 d0.2 mse mod'+model, layers=[128], dropout=0.2, loss='mean_squared_error', metrics=['mean_squared_error']) lstm_mae = mlModule.LSTM('LSTM 1x128 d0.2 mae mod'+model, layers=[128], dropout=0.2, recurrentDropout=0.2, enrolWindow=12, loss='mean_absolute_error', metrics=['mean_absolute_error']) lstm_mse = mlModule.LSTM('LSTM 1x128 d0.2 mse mod'+model, layers=[128], dropout=0.2, recurrentDropout=0.2, enrolWindow=12, loss='mean_squared_error', metrics=['mean_squared_error']) modelList = [ mlp_mae, mlp_mse, lstm_mae, lstm_mse, ] initTrainPredict(modelList)
def pred(facility, model, resolution): filename, columns, irrelevantColumns, targetColumns, traintime, testtime, columnOrder = configs.getConfig( facility, model, resolution) df = mlModule.initDataframe(filename, columns, irrelevantColumns) df_train, df_test = mlModule.getTestTrainSplit(traintime, testtime) X_train, y_train, X_test, y_test = mlModule.getFeatureTargetSplit( targetColumns) lstm_1_1 = mlModule.LSTM('LSTM 1x128 d0.0' + ' mod' + model, layers=[128], dropout=0.0, recurrentDropout=0.0, epochs=5000) lstm_1_2 = mlModule.LSTM('LSTM 1x128 d0.1' + ' mod' + model, layers=[128], dropout=0.1, recurrentDropout=0.1, epochs=5000) lstm_1_3 = mlModule.LSTM('LSTM 1x128 d0.2' + ' mod' + model, layers=[128], dropout=0.2, recurrentDropout=0.2, epochs=5000) lstm_1_4 = mlModule.LSTM('LSTM 1x128 d0.3' + ' mod' + model, layers=[128], dropout=0.3, recurrentDropout=0.3, epochs=5000) lstm_1_5 = mlModule.LSTM('LSTM 1x128 d0.4' + ' mod' + model, layers=[128], dropout=0.4, recurrentDropout=0.4, epochs=5000) lstm_1_6 = mlModule.LSTM('LSTM 1x128 d0.5' + ' mod' + model, layers=[128], dropout=0.5, recurrentDropout=0.5, epochs=5000) linear = mlModule.Linear_Regularized('Linear rCV mod' + model) initTrainPredict([ linear, lstm_1_1, lstm_1_2, lstm_1_3, lstm_1_4, lstm_1_5, lstm_1_6, ])
def performDropoutPrediction(facility, model, resolution, lookback=12, retrain=False): filename, columns, irrelevantColumns, targetColumns, traintime, testtime, columnOrder = configs.getConfig( facility, model, resolution) df = mlModule.initDataframe(filename, columns, irrelevantColumns) df_train, df_test = mlModule.getTestTrainSplit(traintime, testtime) X_train, y_train, X_test, y_test = mlModule.getFeatureTargetSplit( targetColumns) lstm = mlModule.LSTM('LSTMs 1x128 d0.2 mod' + model, layers=[128], training=True, dropout=0.2, recurrentDropout=0.2, enrolWindow=lookback) gru = mlModule.GRU('GRUs 1x128 d0.2 mod' + model, layers=[128], training=True, dropout=0.2, recurrentDropout=0.2, enrolWindow=lookback) modelList = [ lstm, gru, ] mlModule.initModels(modelList) mlModule.trainModels(retrain) predictions, means, stds = mlModule.predictWithModelsUsingDropout( numberOfPredictions=30) plotDropoutPrediction(modelList, predictions, means, stds, targetColumns, df_test, y_test, traintime)
testtime = ["2020-01-01 00:00:00", "2020-08-01 00:00:00"] df = mlModule.initDataframe(filename, columns, irrelevantColumns) df_train, df_test = mlModule.getTestTrainSplit(traintime, testtime) X_train, y_train, X_test, y_test = mlModule.getFeatureTargetSplit( targetColumns) mlp_1 = mlModule.MLP('MLP 1x64 d0.2 mod' + model, layers=[64], dropout=0.2) mlp_2 = mlModule.MLP('MLP 1x128 d0.2 mod' + model, layers=[128], dropout=0.2) mlp_3 = mlModule.MLP('MLP 2x64 d0.2 mod' + model, layers=[64, 64], dropout=0.2) mlp_4 = mlModule.MLP('MLP 2x128 d0.2 mod' + model, layers=[128, 128], dropout=0.2) lstm_1 = mlModule.LSTM('LSTM 1x64 d0.2 mod' + model, layers=[64], dropout=0.2, recurrentDropout=0.2, enrolWindow=12) lstm_2 = mlModule.LSTM('LSTM 1x128 d0.2 mod' + model, layers=[128], dropout=0.2, recurrentDropout=0.2, enrolWindow=12) lstm_3 = mlModule.LSTM('LSTM 2x64 d0.2 mod' + model, layers=[64, 64], dropout=0.2, recurrentDropout=0.2, enrolWindow=12) lstm_4 = mlModule.LSTM('LSTM 2x128 d0.2 mod' + model, layers=[128, 128], dropout=0.2,
def featureComparison( irrelevantColumnsList, filename, columns, traintime, testtime, targetColumns, enrolWindow, ): global colors, models columnsLists = [] deviationsLists = [] names = [] trainmetrics = [] testmetrics = [] for i, irrelevantColumns in enumerate(irrelevantColumnsList): mlModule.reset() df = mlModule.initDataframe(filename, columns, irrelevantColumns) df_train, df_test = mlModule.getTestTrainSplit(traintime, testtime) X_train, y_train, X_test, y_test = mlModule.getFeatureTargetSplit( targetColumns) mlp_1 = mlModule.MLP('MLP 1x64 d0.2 mod' + models[i], layers=[64], dropout=0.2) mlp_2 = mlModule.MLP('MLP 1x128 d0.2 mod' + models[i], layers=[128], dropout=0.2) mlp_3 = mlModule.MLP('MLP 2x64 d0.2 mod' + models[i], layers=[64, 64], dropout=0.2) mlp_4 = mlModule.MLP('MLP 2x128 d0.2 mod' + models[i], layers=[128, 128], dropout=0.2) lstm_1 = mlModule.LSTM('LSTM 1x64 d0.2 mod' + models[i], layers=[64], dropout=0.2, recurrentDropout=0.2, enrolWindow=12) lstm_2 = mlModule.LSTM('LSTM 1x128 d0.2 mod' + models[i], layers=[128], dropout=0.2, recurrentDropout=0.2, enrolWindow=12) lstm_3 = mlModule.LSTM('LSTM 2x64 d0.2 mod' + models[i], layers=[64, 64], dropout=0.2, recurrentDropout=0.2, enrolWindow=12) lstm_4 = mlModule.LSTM('LSTM 2x128 d0.2 mod' + models[i], layers=[128, 128], dropout=0.2, recurrentDropout=0.2, enrolWindow=12) linear = mlModule.Linear_Regularized('Linear rCV mod' + models[i]) modelList = [ mlp_1, mlp_2, mlp_3, mlp_4, lstm_1, lstm_2, lstm_3, lstm_4, linear, ] mlModule.initModels(modelList) retrain = False mlModule.trainModels(retrain) modelNames, metrics_train, metrics_test, columnsList, deviationsList = mlModule.predictWithModels( plot=True, score=True) if i < 1: columnsLists = columnsList deviationsLists = deviationsList all_names = modelNames all_train_metrics = metrics_train all_test_metrics = metrics_test else: for j_target in range(len(columnsList)): for k_model in range(1, len(columnsList[j_target])): columnsLists[j_target].append( columnsList[j_target][k_model]) for k_model in range(0, len(deviationsList[j_target])): deviationsLists[j_target].append( deviationsList[j_target][k_model]) all_names = [*all_names, *modelNames] all_train_metrics = [*all_train_metrics, *metrics_train] all_test_metrics = [*all_test_metrics, *metrics_test] names.append(modelNames) trainmetrics.append(metrics_train) testmetrics.append(metrics_test) indexColumn = mlModule._indexColumn columnDescriptions = mlModule._columnDescriptions columnUnits = mlModule._columnUnits traintime = mlModule._traintime for i in range(len(deviationsLists)): for j in range(len(deviationsLists[i])): deviationsLists[i][j][3] = colors[j] for i in range(len(columnsLists)): columnsList[i][0][3] = 'red' for j in range(1, len(columnsLists[i])): columnsLists[i][j][3] = colors[j - 1] printModelScores( all_names, all_train_metrics, all_test_metrics, ) plotModelPredictions( plt, deviationsLists, columnsLists, indexColumn, columnDescriptions, columnUnits, traintime, interpol=False, ) plotModelScores( plt, all_names, all_train_metrics, all_test_metrics, )