예제 #1
0
def train_custom(conf, plot_path, debug, verbose, gs_params=None, callbacks=default_callbacks):
    global config, plot, train_errors, valid_errors
    plot = plot_path

    train_errors = np.zeros(conf['epochs'])
    valid_errors = np.zeros(conf['epochs'])
    all_ = list()
    for x in ['all', 'md', 'mir', 'feat_sel', 'random']:
        all = list()
        if x in ('all', 'md', 'mir'):
            training_data, training_targets, valid_data, valid_targets = getData(conf['datasets'], 0, None,
                                                                                 None, type=x)
        elif x == 'random':
            from utils import features
            import random
            conf['features'] = random.sample(np.hstack(features.values()), random.randint(1, 115))
            training_data, training_targets, valid_data, valid_targets = getData(conf['datasets'], 0, conf['features'],
                                                                                 balanced=conf['balanced'], type=x)
        else:
            training_data, training_targets, valid_data, valid_targets = getData(conf['datasets'], 0, conf['features'],
                                                                                 balanced=conf['balanced'], type=x)

        # if there is not enough data available
        conf['datasets'] = training_data.shape[0]
        if conf['units'] is None:
            conf['units'] = [int(math.ceil((training_data.shape[1] + 7) / 2))]
        conf['n_input'] = training_data.shape[1]
        config = conf
        units = [int(math.ceil((training_data.shape[1] + 7) / 2))]
        for i in range(1, 101):
            net = getNet(units, conf['learning_rate'], conf['epochs'], conf['learning_rule'],
                         conf['batch_size'], conf['weight_decay'], conf['dropout_rate'],
                         conf['loss_type'], n_stable=conf['n_stable'], debug=debug, verbose=verbose,
                         callbacks=callbacks,
                         # valid_set=(valid_data, valid_targets)
                         valid_size=conf['ratio']
                         )
            pipeline = learning_utils.getPipeline(training_data, net)
            pipeline.fit(training_data, training_targets)
            all.append(valid_errors)
        all_.append(np.array(all).mean(axis=0))
    learning_utils.plot_lines(data=all_, labels=["all", "md", "mir", "feat_sel", "random"],
                              xlabel="number of epochs",
                              ylabel=config['loss_type'],
                              title="mean training and validation error", suptitle=None,
                              path="learning/nn/plots/comb/test.png")
예제 #2
0
                    i0 = options.md_features
                elif options.type == 'feat_sel':
                    if options.pickle_file:
                        features = None
                        # get feature list
                        features = joblib.load(options.pickle_file)
                        i0 = len(features)
                    else:
                        print "Please specify  the location of the pickle file (-p) containing the list of features"
                        sys.exit(2)
                elif options.type == 'rand':
                    from utils import features
                    import random

                    features = random.sample(
                        np.hstack(features.values()),
                        random.randint(1, options.total_features))
                    i0 = len(features)
            else:
                i0 = total_features
            if options.units is None and unit_range is None:
                units = [int(math.ceil((i0 + 7) / 2))]

            if options.plot_path:
                if options.plot_path == 'gen':
                    options.plot_path = os.path.join(
                        os.getcwd(), 'learning', 'nn', 'plots', 'units',
                        "{}_{}_{}_{}_{}_{}_{}_{}_{}.png".format(
                            options.type, options.units, options.n_iter,
                            options.learning_rate, options.batch_size,
                            options.weight_decay, options.dropout_rate,
예제 #3
0
파일: main.py 프로젝트: JonasMie/SmartChart
                elif options.type == 'md':
                    i0 = options.md_features
                elif options.type == 'feat_sel':
                    if options.pickle_file:
                        features = None
                        # get feature list
                        features = joblib.load(options.pickle_file)
                        i0 = len(features)
                    else:
                        print "Please specify  the location of the pickle file (-p) containing the list of features"
                        sys.exit(2)
                elif options.type == 'rand':
                    from utils import features
                    import random

                    features = random.sample(np.hstack(features.values()), random.randint(1, options.total_features))
                    i0 = len(features)
            else:
                i0 = total_features
            if options.units is None and unit_range is None:
                units = [int(math.ceil((i0 + 7) / 2))]

            if options.plot_path:
                if options.plot_path == 'gen':
                    options.plot_path = os.path.join(os.getcwd(), 'learning', 'nn', 'plots',
                                                     'units',
                                                     "{}_{}_{}_{}_{}_{}_{}_{}_{}.png".format(options.type,
                                                                                             options.units,
                                                                                             options.n_iter,
                                                                                             options.learning_rate,
                                                                                             options.batch_size,