(
        model_to_tune=None,
        dataset=None,
        models=None,
        max_layers=10,
        min_layers=2,
        min_dense=32,
        max_dense=512,
        executions_per_trial=3,
        max_trials=1,
        activation='relu',
        loss='categorical_crossentropy',
        metrics='accuracy',
        seed=42,
        objective='val_accuracy',
        generate_plots=True,
        directory='my_dir',
        epochs=10,
        step=32,
        patience=1,
        verbose=0,
        test_size=0.2
)
return models
Helper function that calls the appropriate tuning function
    :param instruction: the objective that you want to reduce dimensions to maximize
    :return the updated models dictionary
Helper function that calls the appropriate tuning function
    :param instruction: the objective that you want to reduce dimensions to maximize
    :return the updated models dictionary
Helper function that calls the appropriate tuning function : param instruction : the objective that you want to reduce dimensions to maximize : return the updated models dictionary
def tune_helper(
        model_to_tune=None,
        dataset=None,
        models=None,
        max_layers=10,
        min_layers=2,
        min_dense=32,
        max_dense=512,
        executions_per_trial=3,
        max_trials=1,
        activation='relu',
        loss='categorical_crossentropy',
        metrics='accuracy',
        seed=42,
        objective='val_accuracy',
        generate_plots=True,
        directory='my_dir',
        epochs=10,
        step=32,
        patience=1,
        verbose=0,
        test_size=0.2
):
    '''
    Helper function that calls the appropriate tuning function
    :param instruction: the objective that you want to reduce dimensions to maximize
    :return the updated models dictionary
    '''
    print("")
    logger("Getting target model for tuning...")

    # checks to see which requested model is in the self.models

    # processing for regression feed forward NN
    if model_to_tune == 'regression_ANN':
        logger("Reading in data")
        logger("Tuning model hyperparameters...")
        dataReader = DataReader(dataset)
        data = dataReader.data_generator()
        target = models['regression_ANN']['target']
        target_column = data[models['regression_ANN']['target']]
        data = models['regression_ANN']['preprocessor'].transform(
            data.drop(target, axis=1))
        returned_model, returned_pms, history, X_test, y_test = tuneReg(
            data.values,
            target_column.values,
            max_layers=max_layers,
            min_layers=min_layers,
            min_dense=min_dense,
            max_dense=max_dense,
            executions_per_trial=executions_per_trial,
            max_trials=max_trials,
            epochs=epochs,
            activation=activation,
            step=step,
            directory=directory,
            verbose=verbose,
            test_size=test_size
        )
        plots = {}
        logger("->", 'Best Hyperparameters Found: {}'.format(returned_pms.values))
        if generate_plots:
            logger("Generating updated plots")
            init_plots, plot_names = generate_regression_plots(
                history, data, target_column)
            for x in range(len(plot_names)):
                plots[str(plot_names[x])] = init_plots[x]

        models['regression_ANN'] = {
            'id': models['regression_ANN']['id'],
            'model': returned_model,
            'target': target,
            "plots": plots,
            'preprocessor': models['regression_ANN']['preprocessor'],
            'interpreter': models['regression_ANN']['interpreter'],
            'test_data': {'X' : X_test, 'y' : y_test},
            'hyperparameters': returned_pms.values,
            'losses': {
                'training_loss': history.history['loss'],
                'val_loss': history.history['val_loss']}
        }
        logger("Re-stored model under 'regression_ANN' key")

        # processing for classification feed forward NN
    elif model_to_tune == "classification_ANN":
        logger("Reading in data")
        logger("Tuning model hyperparameters...")
        dataReader = DataReader(dataset)
        data = dataReader.data_generator()
        target = models['classification_ANN']['target']
        target_column = data[models['classification_ANN']['target']]
        data = models['classification_ANN']['preprocessor'].transform(
            data.drop(target, axis=1))
        returned_model, returned_pms, history, X_test, y_test = tuneClass(
            data,
            target_column,
            models['classification_ANN']['num_classes'],
            max_layers=max_layers,
            min_layers=min_layers,
            min_dense=min_dense,
            max_dense=max_dense,
            executions_per_trial=executions_per_trial,
            max_trials=max_trials,
            activation=activation,
            loss=loss,
            directory=directory,
            metrics=metrics,
            epochs=epochs,
            step=step,
            verbose=verbose,
            test_size=test_size
        )
        plots = {}
        logger("->", 'Best Hyperparameters Found: {}'.format(returned_pms.values))
        if generate_plots:
            logger("Generating updated plots")
            plots = generate_classification_plots(history)


        logger("Re-stored model under 'classification_ANN' key")
        models['classification_ANN'] = {
            'id': models['classification_ANN']['id'],
            'model': returned_model,
            'hyperparameters': returned_pms.values,
            'plots': plots,
            'preprocessor': models['classification_ANN']['preprocessor'],
            'interpreter': models['classification_ANN']['interpreter'],
            'test_data': {'X' : X_test, 'y': y_test},
            'target': target,
            'losses': {
                'training_loss': history.history['loss'],
                'val_loss': history.history['val_loss']},
            'accuracy': {
                'training_accuracy': history.history['accuracy'],
                'validation_accuracy': history.history['val_accuracy']
            }
        }

    elif model_to_tune == "convolutional_NN":
        logger("Tuning model hyperparameters...")
        X_train, X_test, height, width, num_classes = get_image_data(models)
        logger('Located image data')
        model, returned_pms, history = tuneCNN(
            X_train,
            X_test,
            height,
            width,
            num_classes,
            executions_per_trial=executions_per_trial,
            max_trials=max_trials,
            seed=seed,
            objective=objective,
            directory=directory,
            patience=patience,
            epochs=epochs,
            verbose=verbose,
            test_size=test_size
        )
        logger("->", "Optimal image size identified: {}".format((height, width, 3)))
        logger('Packaging HyperModel')
        logger("->", 'Best Hyperparameters Found: {}'.format(returned_pms.values))
        logger("Re-stored model under 'convolutional_NN' key")

        models['convolutional_NN'] = {
            'id': models['convolutional_NN']['id'],
            'data_type': models['convolutional_NN']['data_type'],
            'data_path': models['convolutional_NN']['data_path'],
            'data': {'train': X_train, 'test': X_test},
            'shape': models['convolutional_NN']['shape'],
            'model': model,
            'num_classes': models['convolutional_NN']['num_classes'],
            'data_sizes': models['convolutional_NN']['data_sizes'],
            'losses': {
                'training_loss': history.history['loss'],
                'val_loss': history.history['val_loss']},
            'accuracy': {
                'training_accuracy': history.history['accuracy'],
                'validation_accuracy': history.history['val_accuracy']}
        }
    clearLog()
    return models
def tune_helper ( model_to_tune = None , dataset = None , models = None , max_layers = 10 , min_layers = 2 , min_dense = 32 , max_dense = 512 , executions_per_trial = 3 , max_trials = 1 , activation = 'relu' , loss = 'categorical_crossentropy' , metrics = 'accuracy' , seed = 42 , objective = 'val_accuracy' , generate_plots = True , directory = 'my_dir' , epochs = 10 , step = 32 , patience = 1 , verbose = 0 , test_size = 0.2 ) : print ( "" ) logger ( "Getting target model for tuning..." ) # checks to see which requested model is in the self.models # processing for regression feed forward NN if model_to_tune == 'regression_ANN' : logger ( "Reading in data" ) logger ( "Tuning model hyperparameters..." ) dataReader = DataReader ( dataset ) data = dataReader . data_generator ( ) target = models [ 'regression_ANN' ] [ 'target' ] target_column = data [ models [ 'regression_ANN' ] [ 'target' ] ] data = models [ 'regression_ANN' ] [ 'preprocessor' ] . transform ( data . drop ( target , axis = 1 ) ) returned_model , returned_pms , history , X_test , y_test = tuneReg ( data . values , target_column . values , max_layers = max_layers , min_layers = min_layers , min_dense = min_dense , max_dense = max_dense , executions_per_trial = executions_per_trial , max_trials = max_trials , epochs = epochs , activation = activation , step = step , directory = directory , verbose = verbose , test_size = test_size ) plots = { } logger ( "->" , 'Best Hyperparameters Found: {}' . format ( returned_pms . values ) ) if generate_plots : logger ( "Generating updated plots" ) init_plots , plot_names = generate_regression_plots ( history , data , target_column ) for x in range ( len ( plot_names ) ) : plots [ str ( plot_names [ x ] ) ] = init_plots [ x ] models [ 'regression_ANN' ] = { 'id' : models [ 'regression_ANN' ] [ 'id' ] , 'model' : returned_model , 'target' : target , "plots" : plots , 'preprocessor' : models [ 'regression_ANN' ] [ 'preprocessor' ] , 'interpreter' : models [ 'regression_ANN' ] [ 'interpreter' ] , 'test_data' : { 'X' : X_test , 'y' : y_test } , 'hyperparameters' : returned_pms . values , 'losses' : { 'training_loss' : history . history [ 'loss' ] , 'val_loss' : history . history [ 'val_loss' ] } } logger ( "Re-stored model under 'regression_ANN' key" ) # processing for classification feed forward NN elif model_to_tune == "classification_ANN" : logger ( "Reading in data" ) logger ( "Tuning model hyperparameters..." ) dataReader = DataReader ( dataset ) data = dataReader . data_generator ( ) target = models [ 'classification_ANN' ] [ 'target' ] target_column = data [ models [ 'classification_ANN' ] [ 'target' ] ] data = models [ 'classification_ANN' ] [ 'preprocessor' ] . transform ( data . drop ( target , axis = 1 ) ) returned_model , returned_pms , history , X_test , y_test = tuneClass ( data , target_column , models [ 'classification_ANN' ] [ 'num_classes' ] , max_layers = max_layers , min_layers = min_layers , min_dense = min_dense , max_dense = max_dense , executions_per_trial = executions_per_trial , max_trials = max_trials , activation = activation , loss = loss , directory = directory , metrics = metrics , epochs = epochs , step = step , verbose = verbose , test_size = test_size ) plots = { } logger ( "->" , 'Best Hyperparameters Found: {}' . format ( returned_pms . values ) ) if generate_plots : logger ( "Generating updated plots" ) plots = generate_classification_plots ( history ) logger ( "Re-stored model under 'classification_ANN' key" ) models [ 'classification_ANN' ] = { 'id' : models [ 'classification_ANN' ] [ 'id' ] , 'model' : returned_model , 'hyperparameters' : returned_pms . values , 'plots' : plots , 'preprocessor' : models [ 'classification_ANN' ] [ 'preprocessor' ] , 'interpreter' : models [ 'classification_ANN' ] [ 'interpreter' ] , 'test_data' : { 'X' : X_test , 'y' : y_test } , 'target' : target , 'losses' : { 'training_loss' : history . history [ 'loss' ] , 'val_loss' : history . history [ 'val_loss' ] } , 'accuracy' : { 'training_accuracy' : history . history [ 'accuracy' ] , 'validation_accuracy' : history . history [ 'val_accuracy' ] } } elif model_to_tune == "convolutional_NN" : logger ( "Tuning model hyperparameters..." ) X_train , X_test , height , width , num_classes = get_image_data ( models ) logger ( 'Located image data' ) model , returned_pms , history = tuneCNN ( X_train , X_test , height , width , num_classes , executions_per_trial = executions_per_trial , max_trials = max_trials , seed = seed , objective = objective , directory = directory , patience = patience , epochs = epochs , verbose = verbose , test_size = test_size ) logger ( "->" , "Optimal image size identified: {}" . format ( ( height , width , 3 ) ) ) logger ( 'Packaging HyperModel' ) logger ( "->" , 'Best Hyperparameters Found: {}' . format ( returned_pms . values ) ) logger ( "Re-stored model under 'convolutional_NN' key" ) models [ 'convolutional_NN' ] = { 'id' : models [ 'convolutional_NN' ] [ 'id' ] , 'data_type' : models [ 'convolutional_NN' ] [ 'data_type' ] , 'data_path' : models [ 'convolutional_NN' ] [ 'data_path' ] , 'data' : { 'train' : X_train , 'test' : X_test } , 'shape' : models [ 'convolutional_NN' ] [ 'shape' ] , 'model' : model , 'num_classes' : models [ 'convolutional_NN' ] [ 'num_classes' ] , 'data_sizes' : models [ 'convolutional_NN' ] [ 'data_sizes' ] , 'losses' : { 'training_loss' : history . history [ 'loss' ] , 'val_loss' : history . history [ 'val_loss' ] } , 'accuracy' : { 'training_accuracy' : history . history [ 'accuracy' ] , 'validation_accuracy' : history . history [ 'val_accuracy' ] } } clearLog ( ) return models