Ejemplo n.º 1
0
def trainModelsWithConfig(dirr, mod, res, retrain=False):
    filename, columns, irrelevantColumns, targetColumns, traintime, testtime, columnOrder = configs.getConfig(
        dirr, mod, res)

    relevantColumns, columnDescriptions, columnUnits, columnNames, df = mlModule.initDataframe(
        filename, columns, irrelevantColumns)
    df = df[columnOrder]
    df_train, df_test = mlModule.getTestTrainSplit(df, traintime, testtime)
    X_train, y_train, X_test, y_test = mlModule.getFeatureTargetSplit(
        df_train, df_test, targetColumns)

    mlp = mlModule.MLP('MLP 1x128 d0.2 ' + dirr + ' mod' + mod,
                       X_train,
                       y_train,
                       layers=[128],
                       dropout=0.2)
    lstm = mlModule.LSTM('LSTM 1x128 d0.2 ' + dirr + ' mod' + mod,
                         X_train,
                         y_train,
                         layers=[128],
                         dropout=0.2,
                         recurrentDropout=0.2,
                         enrolWindow=12)
    linear = mlModule.Linear_Regularized('Linear rCV ' + dirr + ' mod' + mod,
                                         X_train, y_train)

    modelList = [
        mlp,
        lstm,
        linear,
    ]

    maxEnrolWindow, indexColumn = mlModule.initModels(modelList, df_test)
    mlModule.trainModels(modelList, filename, targetColumns, retrain)

    return modelList
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def predictWithConfig(modelList, dirr, mod, res):
    filename, columns, irrelevantColumns, targetColumns, traintime, testtime, columnOrder = configs.getConfig(
        dirr, mod, res)

    relevantColumns, columnDescriptions, columnUnits, columnNames, df = mlModule.initDataframe(
        filename, columns, irrelevantColumns)
    df = df[columnOrder]
    df_train, df_test = mlModule.getTestTrainSplit(df, traintime, testtime)
    X_train, y_train, X_test, y_test = mlModule.getFeatureTargetSplit(
        df_train, df_test, targetColumns)
    maxEnrolWindow, indexColumn = mlModule.initModels(modelList, df_test)

    inputScaler = StandardScaler()
    inputScaler.fit(X_train)
    outputScaler = StandardScaler()
    outputScaler.fit(y_train)

    for model in modelList:
        model.inputScaler = inputScaler
        model.outputScaler = outputScaler

    modelNames, metrics_train, metrics_test, columnsList, deviationsList = mlModule.predictWithModels(
        modelList,
        X_train,
        y_train,
        X_test,
        y_test,
        targetColumns,
        indexColumn,
        columnDescriptions,
        columnUnits,
        traintime,
        plot=True,
        interpol=False,
    )
Ejemplo n.º 4
0
        columnsLists,
        indexColumn,
        columnDescriptions,
        columnUnits,
        traintime,
        interpol=False,
    )
    plotModelScores(
        plt,
        all_names,
        all_train_metrics,
        all_test_metrics,
    )


filename, columns, irrelevantColumns, targetColumns, traintime, testtime, columnOrder = configs.getConfig(
    'D', None, '30min')
targetColumns = [
    '50TT002',
]
irrelevantColumnsList = [
    #  Target: C T out
    #  Featers: P T in, P T out, P flow, C T in
    [
        '20PT001',
        '50PDT001',
        '50FT001',
        '50TV001',
        '50PT001',
        '20PDT001',
    ],
    #  Target: C T out
Ejemplo n.º 5
0
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,
    ])
Ejemplo n.º 6
0
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)

    mlpr_1_1 = mlModule.MLP('MLP 1x128 1.0' + ' mod' + model,
                            layers=[128],
                            l1_rate=1.0,
                            epochs=5000)
    mlpr_1_2 = mlModule.MLP('MLP 1x128 0.5' + ' mod' + model,
                            layers=[128],
                            l1_rate=0.5,
                            epochs=5000)
    mlpr_1_3 = mlModule.MLP('MLP 1x128 0.1' + ' mod' + model,
                            layers=[128],
                            l1_rate=0.1,
                            epochs=5000)
    mlpr_1_4 = mlModule.MLP('MLP 1x128 0.05' + ' mod' + model,
                            layers=[128],
                            l1_rate=0.05,
                            epochs=5000)
    mlpr_1_5 = mlModule.MLP('MLP 1x128 0.01' + ' mod' + model,
                            layers=[128],
                            l1_rate=0.01,
                            epochs=5000)
    mlpr_1_6 = mlModule.MLP('MLP 1x128 0.005' + ' mod' + model,
                            layers=[128],
                            l1_rate=0.005,
                            epochs=5000)
    mlpr_1_7 = mlModule.MLP('MLP 1x128 0.001' + ' mod' + model,
                            layers=[128],
                            l1_rate=0.001,
                            epochs=5000)
    mlpd_1_8 = mlModule.MLP('MLP 1x128 0.2' + ' mod' + model,
                            layers=[128],
                            dropout=0.2,
                            epochs=5000)

    linear_r = mlModule.Linear_Regularized('Linear rCV' + ' mod' + model)

    initTrainPredict([
        mlpr_1_1,
        mlpr_1_2,
        mlpr_1_3,
        mlpr_1_4,
        mlpr_1_5,
        mlpr_1_6,
        mlpr_1_7,
        mlpd_1_8,
        linear_r,
    ])

    initTrainPredict([
        mlpr_1_6,
        mlpr_1_7,
        mlpd_1_8,
        linear_r,
    ])
Ejemplo n.º 7
0
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_1x_16 = mlModule.MLP('MLP 1x16' + ' mod' + model,
                             layers=[16],
                             dropout=0.2,
                             epochs=1000)
    mlp_1x_32 = mlModule.MLP('MLP 1x32' + ' mod' + model,
                             layers=[32],
                             dropout=0.2,
                             epochs=1000)
    mlp_1x_64 = mlModule.MLP('MLP 1x64' + ' mod' + model,
                             layers=[64],
                             dropout=0.2,
                             epochs=1000)
    mlp_1x_128 = mlModule.MLP('MLP 1x128' + ' mod' + model,
                              layers=[128],
                              dropout=0.2,
                              epochs=1000)

    mlp_2x_16 = mlModule.MLP('MLP 2x16' + ' mod' + model,
                             layers=[16, 16],
                             dropout=0.2,
                             epochs=1000)
    mlp_2x_32 = mlModule.MLP('MLP 2x32' + ' mod' + model,
                             layers=[32, 32],
                             dropout=0.2,
                             epochs=1000)
    mlp_2x_64 = mlModule.MLP('MLP 2x64' + ' mod' + model,
                             layers=[64, 64],
                             dropout=0.2,
                             epochs=1000)
    mlp_2x_128 = mlModule.MLP('MLP 2x128' + ' mod' + model,
                              layers=[128, 128],
                              dropout=0.2,
                              epochs=1000)

    linear_cv = mlModule.Linear_Regularized('Linear rCV' + ' mod' + model)

    ensemble = mlModule.Ensemble('MLP 1x128 + Linear' + ' mod' + model,
                                 [mlp_1x_128, linear_cv])
    ensemble2 = mlModule.Ensemble('MLP 2x64 + Linear' + ' mod' + model,
                                  [mlp_2x_64, linear_cv])

    modelList = [
        linear_cv,
        mlp_1x_16,
        mlp_1x_32,
        mlp_2x_16,
        mlp_2x_32,
    ]

    initTrainPredict(modelList)

    modelList = [
        linear_cv,
        mlp_1x_64,
        mlp_1x_128,
        mlp_2x_64,
        mlp_2x_128,
    ]

    initTrainPredict(modelList)

    modelList = [
        linear_cv,
        ensemble,
        ensemble2,
    ]

    initTrainPredict(modelList)
Ejemplo n.º 8
0
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)