예제 #1
0
def test_interp():
    # univariate time series
    N = 100
    t = np.arange(N) + np.random.rand(N)
    X = [np.column_stack([t, np.random.rand(N)])]
    y = [np.random.rand(N)]

    interp = transform.Interp(2)
    interp.fit(X)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 2
    assert len(yc[0]) == N / 2
    assert np.ndim(Xc[0]) == 1

    y = [np.random.randint(0, 5, N)]
    interp = transform.Interp(5, kind='cubic', categorical_target=True)
    interp.fit(X, y)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 5
    assert len(yc[0]) == N / 5
    assert np.ndim(Xc[0]) == 1
    assert np.all(np.isin(yc, np.arange(6)))

    # multivariate time series
    N = 100
    D = 5
    t = np.arange(N) + np.random.rand(N)
    X = [np.column_stack([t, np.random.rand(N, D)])]
    y = [np.random.rand(N)]

    interp = transform.Interp(2)
    interp.fit(X)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 2
    assert len(yc[0]) == N / 2
    assert Xc[0].shape[1] == D

    y = [np.random.randint(0, 5, N)]
    interp = transform.Interp(5, kind='cubic', categorical_target=True)
    interp.fit(X, y)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 5
    assert len(yc[0]) == N / 5
    assert Xc[0].shape[1] == D
    assert np.all(np.isin(yc, np.arange(6)))
예제 #2
0
def test_interp():
    N = 100
    t = np.arange(N) + np.random.rand(N)
    X = [np.column_stack([t, np.random.rand(N)])]
    y = [np.random.rand(N)]

    interp = transform.Interp(2)
    interp.fit(X)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 2
    assert len(yc[0]) == N / 2

    y = [np.random.randint(0, 5, N)]
    interp = transform.Interp(5, kind='cubic', categorical_target=True)
    interp.fit(X, y)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 5
    assert len(yc[0]) == N / 5
    assert np.all(np.isin(yc, np.arange(6)))
예제 #3
0
def test_interp():
    # univariate time series
    N = 100
    t = np.arange(N) + np.random.rand(N)
    X = [np.column_stack([t, np.random.rand(N)])]
    y = [np.random.rand(N)]

    interp = transform.Interp(2)
    interp.fit(X)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 2
    assert len(yc[0]) == N / 2
    assert np.ndim(Xc[0]) == 1

    y = [np.random.randint(0, 5, N)]
    interp = transform.Interp(5, kind='cubic', categorical_target=True)
    interp.fit(X, y)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 5
    assert len(yc[0]) == N / 5
    assert np.ndim(Xc[0]) == 1
    assert np.all(np.isin(yc, np.arange(6)))

    # multivariate time series
    N = 100
    D = 5
    t = np.arange(N) + np.random.rand(N)
    X = [np.column_stack([t, np.random.rand(N, D)])]
    y = [np.random.rand(N)]

    interp = transform.Interp(2)
    interp.fit(X)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 2
    assert len(yc[0]) == N / 2
    assert Xc[0].shape[1] == D

    y = [np.random.randint(0, 5, N)]
    interp = transform.Interp(5, kind='cubic', categorical_target=True)
    interp.fit(X, y)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 5
    assert len(yc[0]) == N / 5
    assert Xc[0].shape[1] == D
    assert np.all(np.isin(yc, np.arange(6)))

    # sorting case
    N = 100
    t = np.arange(N)
    t[0:3] = 0
    X = [np.column_stack([t, np.random.rand(N)])]
    y = [np.random.rand(N)]

    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")
        interp = transform.Interp(sample_period=2, assume_sorted=False)
        interp.fit(X)
        Xc, yc, swt = interp.transform(X, y)
        assert len(w) == 2
        assert issubclass(w[-1].category, UserWarning)
        assert "duplicate" in str(w[-1].message)
        assert len(Xc[0]) == N / 2
        assert len(yc[0]) == N / 2
        assert np.ndim(Xc[0]) == 1
        assert np.count_nonzero(np.isnan(Xc)) == 0
예제 #4
0
def test_interp():
    # univariate time series
    N = 100
    t = np.arange(N) + np.random.rand(N)
    X = [np.column_stack([t, np.random.rand(N)])]
    y = [np.random.rand(N)]

    interp = transform.Interp(2)
    interp.fit(X)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 2
    assert len(yc[0]) == N / 2
    assert np.ndim(Xc[0]) == 1

    y = [np.random.randint(0, 5, N)]
    interp = transform.Interp(5, kind='cubic', categorical_target=True)
    interp.fit(X, y)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 5
    assert len(yc[0]) == N / 5
    assert np.ndim(Xc[0]) == 1
    assert np.all(np.isin(yc, np.arange(6)))

    # multivariate time series
    N = 100
    D = 5
    t = np.arange(N) + np.random.rand(N)
    X = [np.column_stack([t, np.random.rand(N, D)])]
    y = [np.random.rand(N)]

    interp = transform.Interp(2)
    interp.fit(X)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 2
    assert len(yc[0]) == N / 2
    assert Xc[0].shape[1] == D

    y = [np.random.randint(0, 5, N)]
    interp = transform.Interp(5, kind='cubic', categorical_target=True)
    interp.fit(X, y)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 5
    assert len(yc[0]) == N / 5
    assert Xc[0].shape[1] == D
    assert np.all(np.isin(yc, np.arange(6)))

    # sorthing case
    N = 100
    t = np.arange(N)
    t[0:3] = 0
    X = [np.column_stack([t, np.random.rand(N)])]
    y = [np.random.rand(N)]

    interp = transform.Interp(sample_period=2, assume_sorted=False)
    interp.fit(X)
    Xc, yc, swt = interp.transform(X, y)

    assert len(Xc[0]) == N / 2
    assert len(yc[0]) == N / 2
    assert np.ndim(Xc[0]) == 1
    assert np.count_nonzero(np.isnan(Xc)) == 0