Beispiel #1
0
def clone():
    tmp = load_object("seed-9473.save")

    net = Network()

    net.add(FCLayer(30, 30))
    net.add(ActivationLayer(tanh, tanh_prime))
    net.add(FCLayer(30, 30))
    net.add(ActivationLayer(tanh, tanh_prime))
    net.add(FCLayer(30, 30))
    net.add(ActivationLayer(tanh, tanh_prime))
    net.add(FCLayer(30, 2))
    net.add(ActivationLayer(softmax, softmax_prime))

    net.layers[0] = tmp.layers[0]
    net.layers[1] = tmp.layers[1]
    net.layers[2] = tmp.layers[2]
    net.layers[3] = tmp.layers[3]
    net.layers[4] = tmp.layers[4]
    net.layers[5] = tmp.layers[5]
    net.layers[6] = tmp.layers[6]

    save_object(net, f'seed-clone-9473-soft.save')
Beispiel #2
0
def train(args, df_x, df_y):
    """
    :param args: dict from argparse
    :param df_x: DataFrame containing xs
    :param df_y: DataFrame containing ys
    :return: Network's instance
    """

    df_x_train, df_x_test, df_y_train, df_y_test = train_test_split(
        df_x, df_y, test_size=0.2, random_state=0)
    net = Network()

    # Loads a seed if load
    if args.load:
        if os.path.exists(os.path.join(os.getcwd(), args.load)):
            net = load_object(args.load)
        else:
            sys.exit(display_errors_dict('wrong_load'))
    else:
        net.add(FCLayer(30, 30))
        net.add(ActivationLayer(tanh, tanh_prime))
        net.add(FCLayer(30, 30))
        net.add(ActivationLayer(tanh, tanh_prime))
        net.add(FCLayer(30, 30))
        net.add(ActivationLayer(tanh, tanh_prime))
        net.add(FCLayer(30, 2))
        net.add(ActivationLayer(softmax, softmax_prime))

    # Saves seed
    if args.save and not args.load:
        save_object(net, f'saved-seed.save')

    # Trains model
    net.use(mse, mse_prime)
    net.fit(df_x_train,
            df_y_train,
            df_x_test,
            df_y_test,
            epoch=args.epoch,
            learning_rate=args.learning,
            error_rate=0.01)
    plot_loss(net)

    # Evaluates with the 20% DataFrame
    rse_acc = evaluate_and_predict(net, df_x_test, df_y_test)

    # Renames seed with accuracy score
    if args.save and not args.load:
        move('saved-seed.save', f'seed-{int(rse_acc * 10000)}.save')

    # Saves network objet
    save_object(net, 'network.save')

    return net