예제 #1
0
def test_io_dfgenerator_w_str_batches():
    X = pandas.DataFrame(numpy.random.randn(500, 13))
    X2 = X.copy()
    w = numpy.abs(numpy.random.randn(500))
    X['w'] = w

    data = DataFrameGenerator(X, 'w')
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    w_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X2.values, X_)
    assert_almost_equal(w, w_)

    data = DataFrameGenerator(X, 'w', batch_size=123)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    w_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X2.values, X_)
    assert_almost_equal(w, w_)

    data = DataFrameGenerator(X, 'w', batch_size=1)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    w_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X2.values, X_)
    assert_almost_equal(w, w_)

    data = DataFrameGenerator(X, 'w', batch_size=506)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    w_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X2.values, X_)
    assert_almost_equal(w, w_)
예제 #2
0
def test_io_dfgenerator_y_str_batches():
    X = pandas.DataFrame(numpy.random.randn(500, 13))
    X2 = X.copy()
    y = numpy.random.randint(5, size=500)
    X['y'] = y

    data = DataFrameGenerator(X, y='y')
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    y_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X2.values, X_)
    assert_almost_equal(y, y_)

    data = DataFrameGenerator(X, y='y', batch_size=123)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    y_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X2.values, X_)
    assert_almost_equal(y, y_)

    data = DataFrameGenerator(X, y='y', batch_size=1)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    y_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X2.values, X_)
    assert_almost_equal(y, y_)

    data = DataFrameGenerator(X, y='y', batch_size=506)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    y_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X2.values, X_)
    assert_almost_equal(y, y_)
예제 #3
0
def test_io_dfgenerator_x_batches():
    X = pandas.DataFrame(numpy.random.randn(500, 13))
    w = numpy.ones(500)

    data = DataFrameGenerator(X)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    w_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X.values, X_)
    assert_almost_equal(w, w_)

    data = DataFrameGenerator(X, batch_size=123)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    w_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X.values, X_)
    assert_almost_equal(w, w_)

    data = DataFrameGenerator(X, batch_size=1)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    w_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X.values, X_)
    assert_almost_equal(w, w_)

    data = DataFrameGenerator(X, batch_size=506)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    w_ = numpy.concatenate([batch[1] for batch in data.batches()])
    assert_almost_equal(X.values, X_)
    assert_almost_equal(w, w_)
예제 #4
0
def test_io_dfgenerator_wy_batches():
    X = pandas.DataFrame(numpy.random.randn(500, 13))
    w = numpy.abs(numpy.random.randn(500))
    y = numpy.random.randint(5, size=500)

    data = DataFrameGenerator(X, w, y)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    y_ = numpy.concatenate([batch[1] for batch in data.batches()])
    w_ = numpy.concatenate([batch[2] for batch in data.batches()])
    assert_almost_equal(X.values, X_)
    assert_almost_equal(y, y_)
    assert_almost_equal(w, w_)

    data = DataFrameGenerator(X, w, y, batch_size=123)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    y_ = numpy.concatenate([batch[1] for batch in data.batches()])
    w_ = numpy.concatenate([batch[2] for batch in data.batches()])
    assert_almost_equal(X.values, X_)
    assert_almost_equal(y, y_)
    assert_almost_equal(w, w_)

    data = DataFrameGenerator(X, w, y, batch_size=1)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    y_ = numpy.concatenate([batch[1] for batch in data.batches()])
    w_ = numpy.concatenate([batch[2] for batch in data.batches()])
    assert_almost_equal(X.values, X_)
    assert_almost_equal(y, y_)
    assert_almost_equal(w, w_)

    data = DataFrameGenerator(X, w, y, batch_size=506)
    X_ = numpy.concatenate([batch[0] for batch in data.batches()])
    y_ = numpy.concatenate([batch[1] for batch in data.batches()])
    w_ = numpy.concatenate([batch[2] for batch in data.batches()])
    assert_almost_equal(X.values, X_)
    assert_almost_equal(y, y_)
    assert_almost_equal(w, w_)