コード例 #1
0
def initTrainPredict(modelList, retrain=False, plot=True, score=True):
    mlModule.initModels(modelList)
    mlModule.trainModels(retrain)

    modelNames, metrics_train, metrics_test, columnsList, deviationsList = mlModule.predictWithModels(
        plot=plot,
        score=score,
    )
コード例 #2
0
def initTrainPredict(modelList, retrain=False, plot=True, interpol=False):
    # 4. Initiate and train models
    mlModule.initModels(modelList)
    mlModule.trainModels(retrain)
    
    # 5. Predict
    modelNames, metrics_train, metrics_test, columnsList, deviationsList = mlModule.predictWithModels(
        plot=plot,
        interpol=interpol,
    )
コード例 #3
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)
コード例 #4
0
    mlp_1,
    mlp_2,
    mlp_3,
    mlp_4,
    lstm_1,
    lstm_2,
    lstm_3,
    lstm_4,
    ensemble1,
    ensemble2,
]

# Define whether to retrain models or not
retrain = False

mlModule.initModels(modelList)
mlModule.trainModels(retrain)

modelNames, metrics_train, metrics_test, columnsList, deviationsList = mlModule.predictWithModels(
    plot=True,
    interpol=False,
    score=True,
)

import src.utils.utilities as utils
import src.utils.plots as plots
import matplotlib.pyplot as plt

df_fouling = utils.readDataFile('../master-thesis-db/datasets/D/foulingC.csv')
df_fouling = utils.getDataWithTimeIndex(df_fouling)
コード例 #5
0
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,
    )