def test_concatenate(nps_app_inst):
    import nums.numpy as nps

    assert nps_app_inst is not None

    ba1: BlockArray = nps.arange(5)
    ba2: BlockArray = nps.arange(6)
    ba = nps.concatenate((ba1, ba2))
    np_arr = np.concatenate((np.arange(5), np.arange(6)))
    assert np.allclose(ba.get(), np_arr)
예제 #2
0
def sample(app: ArrayApplication, sample_size):
    X_train = nps.concatenate([
        nps.random.randn(sample_size // 2, 2),
        nps.random.randn(sample_size // 2, 2) + 2.0
    ],
                              axis=0)
    y_train = nps.concatenate([
        nps.zeros(shape=(sample_size // 2, ), dtype=nps.int),
        nps.ones(shape=(sample_size // 2, ), dtype=nps.int)
    ],
                              axis=0)
    # We augment X with 1s for intercept term.
    X_train = app.concatenate([
        X_train,
        app.ones(shape=(X_train.shape[0], 1),
                 block_shape=(X_train.block_shape[0], 1),
                 dtype=X_train.dtype)
    ],
                              axis=1,
                              axis_block_size=X_train.block_shape[1] + 1)
    return X_train, y_train
예제 #3
0
import nums
import nums.numpy as nps
from nums.models.glms import LogisticRegression

nums.init()

# Make dataset.

X1 = nps.random.randn(500, 1) + 5.0
y1 = nps.zeros(shape=(500, ), dtype=bool)

X2 = nps.random.randn(500, 1) + 10.0
y2 = nps.ones(shape=(500, ), dtype=bool)

X = nps.concatenate([X1, X2], axis=0)
y = nps.concatenate([y1, y2], axis=0)

# Train Logistic Regression Model.

model = LogisticRegression(solver="newton", tol=1e-8, max_iter=1)

model.fit(X, y)
y_pred = model.predict(X)

print("accuracy", (nps.sum(y == y_pred) / X.shape[0]).get())