Пример #1
0
def neural_net_helper(data,
                      label=None,
                      eta=0.01,
                      iterations=100,
                      layer_structure=[],
                      regression=False,
                      tuning=False):

    if label == None:
        label = class_label

    f = 5  # fold-value
    tune = data['tune']
    perf = []

    start_time = time.time()
    for i in range(f):
        # set variable to determine if extra printing is required for network
        # since we're doing cross-validation, print for first fold only
        print_on = False

        all_folds = data['folds'].copy()

        if not tuning:
            holdout = all_folds[i]
        else:
            holdout = tune

        folds = all_folds
        folds.pop(i)
        training = pd.concat(folds)

        nn = NeuralNet(training, label, eta, iterations, layer_structure,
                       regression, print_on)
        nn.build()
        result = nn.test(holdout)

        if print_on:
            nn.pretty_print()

        perf.append(result)

    elapsed = time.time() - start_time
    print('\n======== avg. summary of performance ========')

    if regression:
        print_helper_regressor(perf, f)
    else:
        print_helper_classifier(perf, f)

    print('total execution time:\t{:.2f}s'.format(elapsed))