コード例 #1
0
def test_sw_first_window_size(train_size, window_size, horizon, expected):
    '''
    check that the window size is correct in the sliding
    window method - this tests the first fold.
    '''
    train = np.arange(train_size)
    cv = ms.sliding_window(train, window_size=window_size, horizon=horizon)

    train_cv, _ = next(cv)

    assert expected == len(train_cv)
コード例 #2
0
def test_sw_test_length(train_size, horizon, expected):
    '''
    test the length of test is correct in the sliding window
    generator
    '''
    train = np.arange(train_size)
    cv = ms.sliding_window(train, window_size=1, horizon=horizon)

    _, test_cv = next(cv)

    assert expected == len(test_cv)
コード例 #3
0
def test_sw_number_of_folds(train_size, window_size, horizon, step, expected):
    '''
    check that the number of folds returned from sliding window
    is as expected
    '''
    train = np.arange(train_size)
    cv = ms.sliding_window(train,
                           window_size=window_size,
                           horizon=horizon,
                           step=step)
    actual = 0

    # number of folds found
    for _, _ in cv:
        actual += 1

    assert expected == actual
コード例 #4
0
def test_sw_number_of_folds_pd(train_size, window_size, horizon, step,
                               expected):
    '''
    check that the number of folds returned from rolling origin
    is as expected when data source is a PANDAS.DATAFRAME
    '''
    train = pd.DataFrame(np.arange(train_size))
    cv = ms.sliding_window(train,
                           window_size=window_size,
                           horizon=horizon,
                           step=step)
    actual = 0

    # number of folds found
    for _, _ in cv:
        actual += 1

    assert expected == actual