def fit_tensorflow(strategy_dictionary, data_to_predict, fitting_inputs,
                   fitting_targets):
    toc = tic()

    train_indices, test_indices, validation_indices = train_test_validation_indices(
        fitting_inputs, strategy_dictionary['train_test_validation_ratios'])

    if strategy_dictionary['sequence_flag']:
        fitting_dictionary, error = tensorflow_sequence_fitting(
            '/tmp/test', train_indices, test_indices, validation_indices,
            fitting_inputs, fitting_targets, strategy_dictionary)

    else:
        fitting_dictionary, error = tensorflow_fitting(train_indices,
                                                       test_indices,
                                                       validation_indices,
                                                       fitting_inputs,
                                                       fitting_targets)

    fitting_dictionary['train_indices'] = train_indices
    fitting_dictionary['test_indices'] = test_indices
    fitting_dictionary['validation_indices'] = validation_indices

    fitting_dictionary = post_process_training_results(strategy_dictionary,
                                                       fitting_dictionary,
                                                       data_to_predict)

    profit_factor = output_strategy_results(strategy_dictionary,
                                            fitting_dictionary,
                                            data_to_predict, toc)
    return fitting_dictionary, error, profit_factor
def meta_fitting(fitting_inputs, fitting_targets, strategy_dictionary):
    error = []
    fitting_dictionary = {}
    train_indices, test_indices, validation_indices = train_test_validation_indices(
        fitting_inputs, strategy_dictionary['train_test_validation_ratios'])
    if strategy_dictionary['ml_mode'] == 'svm':
        fitting_dictionary, error = svm_fitting(
            fitting_inputs, fitting_targets, train_indices, test_indices, validation_indices, strategy_dictionary)

    elif strategy_dictionary['ml_mode'] == 'randomforest':
        fitting_dictionary, error = random_forest_fitting(
            fitting_inputs, fitting_targets, train_indices, test_indices, validation_indices, strategy_dictionary)

    elif strategy_dictionary['ml_mode'] == 'adaboost':
        fitting_dictionary, error = adaboost_fitting(
            fitting_inputs, fitting_targets, train_indices, test_indices, validation_indices, strategy_dictionary)

    elif strategy_dictionary['ml_mode'] == 'gradientboosting':
        fitting_dictionary, error = gradient_boosting_fitting(
            fitting_inputs, fitting_targets, train_indices, test_indices, validation_indices, strategy_dictionary)

    elif strategy_dictionary['ml_mode'] == 'extratreesfitting':
        fitting_dictionary, error = extra_trees_fitting(
            fitting_inputs, fitting_targets, train_indices, test_indices, validation_indices, strategy_dictionary)

    fitting_dictionary['train_indices'] = train_indices
    fitting_dictionary['test_indices'] = test_indices
    fitting_dictionary['validation_indices'] = validation_indices
    fitting_dictionary['error'] = error

    return fitting_dictionary
def meta_fitting(fitting_inputs, fitting_targets, strategy_dictionary):
    error = []
    model = []
    train_indices, test_indices, validation_indices = train_test_validation_indices(
        fitting_inputs,
        strategy_dictionary['train_test_validation_ratios'])

    target_scaler = StandardScaler()

    if strategy_dictionary['regression_mode'] == 'regression':
        fitting_targets = target_scaler.fit_transform(fitting_targets.reshape(-1, 1)).ravel()

    if strategy_dictionary['ml_mode'] == 'svm':
        model, error = svm_fitting(
            fitting_inputs,
            fitting_targets,
            train_indices,
            strategy_dictionary)

    elif strategy_dictionary['ml_mode'] == 'randomforest':
        model, error = random_forest_fitting(
            fitting_inputs,
            fitting_targets,
            train_indices,
            strategy_dictionary)

    elif strategy_dictionary['ml_mode'] == 'adaboost':
        model, error = adaboost_fitting(
            fitting_inputs,
            fitting_targets,
            train_indices,
            strategy_dictionary)

    elif strategy_dictionary['ml_mode'] == 'gradientboosting':
        model, error = gradient_boosting_fitting(
            fitting_inputs,
            fitting_targets,
            train_indices,
            strategy_dictionary)

    elif strategy_dictionary['ml_mode'] == 'extratreesfitting':
        model, error = extra_trees_fitting(
            fitting_inputs,
            fitting_targets,
            train_indices,
            strategy_dictionary)

    if len(test_indices) != 0:
        training_strategy_score = model.predict(fitting_inputs[train_indices, :])
        fitted_strategy_score = model.predict(fitting_inputs[test_indices, :])
        validation_strategy_score = model.predict(fitting_inputs[validation_indices, :])

    else:
        fitted_strategy_score = []
        validation_strategy_score = []

    if strategy_dictionary['regression_mode'] == 'regression':
        fitting_dictionary = {
            'training_strategy_score': training_strategy_score,
            'fitted_strategy_score': fitted_strategy_score,
            'validation_strategy_score':validation_strategy_score,
            'train_indices': train_indices,
            'test_indices': test_indices,
            'validation_indices': validation_indices,
            'error': error}

    elif strategy_dictionary['regression_mode'] == 'classification':
        fitting_dictionary = {
            'training_strategy_score': training_strategy_score,
            'fitted_strategy_score': fitted_strategy_score,
            'validation_strategy_score': validation_strategy_score,
            'train_indices': train_indices,
            'test_indices': test_indices,
            'validation_indices': validation_indices,
            'error': error}

    return fitting_dictionary