Ejemplo n.º 1
0
        transformer_fun=None)
    am_test_batch = batch_data.batch_data(amte,
        normalizer_fun=None,transformer_fun=None)
    
    # Spit out some sample data
    next_batch = am_train_batch.next()
    data, label = next_batch
    np.set_printoptions(threshold=np.nan)
    print "Batch properties:"
    print "Length: {}".format(len(data))
    print "Type: {}".format(type(data))
    print
    print "First record of first batch:"
    print "Type (1 level in): {}".format(type(data[0]))
    print "Type of record (2 levels in): {}".format(type(data[0,0]))
    print data[0,0]
    print "Sentiment label: {}".format(label[0])
    print "In numpy format:"
    oh = data_utils.to_one_hot(data[0,0])
    print np.array_str(np.argmax(oh,axis=0))
    print "Translated back into characters:\n"
    print data_utils.from_one_hot(oh)
    
    # dimension checks
    second_batch_data, second_batch_label = second_batch = am_train_batch.next()
    second_batch = list(second_batch)
    print len(second_batch)
    print "Data object type: ", type(second_batch_data)
    print second_batch_data.shape
    
Ejemplo n.º 2
0
        # Spit out some sample data
        next_batch = amz_train_batch.next()
        data, label = next_batch
        np.set_printoptions(threshold=np.nan)
        print "Batch properties:"
        print "Shape (data): {}".format(data.shape)
        print "Shape (label): {}".format(label.shape)
        print "Type: {}".format(type(data))
        print
        print "First record of first batch:"
        print "Type (1 level in): {}".format(type(data[0]))
        print "Type of record (2 levels in): {}".format(type(data[0,0]))
        print data[0,0]
        print "Sentiment label: {}".format(label[0,0])
        print "Data in numpy format:"
        oh = data_utils.to_one_hot(data[0,0])
        print np.array_str(np.argmax(oh,axis=0))
        print "Translated back into characters:\n"
        print ''.join(data_utils.from_one_hot(oh))

        # demo balanced batching
        amz_balanced_batcher = batch_data(amz_train,balance_labels=True)
        balanced_batch = amz_balanced_batcher.next()
        print 'Balanced batch:'
        balanced_label_counts = {}
        for idx in range(balanced_batch[1].shape[0]):
            label = balanced_batch[1][idx,0]
            balanced_label_counts[label] = balanced_label_counts.get(label, 0) + 1
        print balanced_label_counts

    # Demo iterator utility classes
Ejemplo n.º 3
0
    print(f"acc: {acc}")


if __name__ == '__main__':
    print("Testing network on scikit-learn wine dataset...")

    np.random.seed(1)
    scaler = StandardScaler()

    print("\nLoading data...")
    data = load_wine()

    print("\nPreprocessing data...")
    x = data['data']
    y = data['target']
    y = data_utils.to_one_hot(y)
    x_train, y_train, x_test, y_test, x_valid, y_valid = data_utils.train_test_valid_split(
        x, y, 0.7, 0.2, should_shuffle=True)

    x_train = scaler.fit_transform(x_train)
    x_test = scaler.transform(x_test)
    x_valid = scaler.transform(x_valid)

    dataset = data_utils.Dataset(x_train, y_train)
    data_manager = data_utils.DataManager(dataset, batch_size=8)

    print("\nBuilding network...")
    n_inputs = len(x[0])
    n_hidden = 2
    n_outputs = 3