Beispiel #1
0
def test_singlets_holtwinters(seasonal, h, datatype):
    global airpassengers
    airpassengers = np.asarray(airpassengers, dtype=datatype)
    train = airpassengers[:-h]
    test = airpassengers[-h:]

    if seasonal == "multiplicative":
        pytest.xfail("Statsmodels nan errors with gcc 9.3 (Issue #3384)")

    sm_hw = sm_ES(train,
                  initialization_method='heuristic',
                  seasonal=seasonal,
                  seasonal_periods=12)
    sm_hw = sm_hw.fit()

    # train = cudf.Series(train)

    cu_hw = cuml_ES(train, seasonal=seasonal,
                    seasonal_periods=12)
    cu_hw.fit()

    cu_pred = cu_hw.forecast(h)
    sm_pred = sm_hw.forecast(h)
    cu_r2 = r2_score(cu_pred.to_numpy(), test)
    sm_r2 = r2_score(sm_pred, test)

    assert (cu_r2 >= sm_r2) or (abs(cu_r2 - sm_r2) < 2e-1)
Beispiel #2
0
def test_multits_holtwinters(seasonal, h, datatype):
    global airpassengers, co2
    airpassengers = np.asarray(airpassengers, dtype=datatype)
    co2 = np.asarray(co2, dtype=datatype)

    if seasonal == "multiplicative":
        pytest.xfail("Statsmodels nan errors with gcc 9.3 (Issue #3384)")

    air_train = airpassengers[:-h]
    air_test = airpassengers[-h:]
    co2_train = co2[:-h]
    co2_test = co2[-h:]
    data = np.asarray([air_train, co2_train], dtype=datatype)
    cu_hw = cuml_ES(data, seasonal=seasonal,
                    seasonal_periods=12, ts_num=2)

    sm_air_hw = sm_ES(air_train,
                      initialization_method='heuristic',
                      seasonal=seasonal,
                      seasonal_periods=12)
    sm_co2_hw = sm_ES(co2_train,
                      initialization_method='heuristic',
                      seasonal=seasonal,
                      seasonal_periods=12)
    cu_hw.fit()
    sm_air_hw = sm_air_hw.fit()
    sm_co2_hw = sm_co2_hw.fit()

    cu_air_pred = cu_hw.forecast(h, 0)
    cu_co2_pred = cu_hw.forecast(h, 1)
    sm_air_pred = sm_air_hw.forecast(h)
    sm_co2_pred = sm_co2_hw.forecast(h)

    cu_air_r2 = r2_score(cu_air_pred.to_numpy(), air_test)
    cu_co2_r2 = r2_score(cu_co2_pred.to_numpy(), co2_test)
    sm_air_r2 = r2_score(sm_air_pred, air_test)
    sm_co2_r2 = r2_score(sm_co2_pred, co2_test)

    assert (cu_air_r2 >= sm_air_r2) or (abs(cu_air_r2 - sm_air_r2) < 4)
    assert (cu_co2_r2 >= sm_co2_r2) or (abs(cu_co2_r2 - sm_co2_r2) < 4)

    full_cu_pred = cu_hw.forecast(h)
    air_cu_r2 = r2_score(full_cu_pred[0].to_numpy(), air_test)
    co2_cu_r2 = r2_score(full_cu_pred[1].to_numpy(), co2_test)
    assert (air_cu_r2 >= sm_air_r2) or (abs(air_cu_r2 - sm_air_r2) < 4)
    assert (co2_cu_r2 >= sm_co2_r2) or (abs(co2_cu_r2 - sm_co2_r2) < 4)
Beispiel #3
0
def test_multits_holtwinters(seasonal, h, datatype, input_type):
    global airpassengers, co2
    airpassengers = np.asarray(airpassengers, dtype=datatype)
    co2 = np.asarray(co2, dtype=datatype)

    air_train = airpassengers[:-h]
    air_test = airpassengers[-h:]
    co2_train = co2[:-h]
    co2_test = co2[-h:]
    data = np.asarray([air_train, co2_train], dtype=datatype)

    if input_type == 'cudf':
        data = cudf.DataFrame({i: data[i] for i in range(data.shape[0])})

    cu_hw = cuml_ES(data, seasonal=seasonal,
                    seasonal_periods=12, ts_num=2)

    sm_air_hw = sm_ES(air_train,
                      seasonal=seasonal,
                      seasonal_periods=12)
    sm_co2_hw = sm_ES(co2_train,
                      seasonal=seasonal,
                      seasonal_periods=12)
    cu_hw.fit()
    sm_air_hw = sm_air_hw.fit()
    sm_co2_hw = sm_co2_hw.fit()

    cu_air_pred = cu_hw.forecast(h, 0)
    cu_co2_pred = cu_hw.forecast(h, 1)
    sm_air_pred = sm_air_hw.forecast(h)
    sm_co2_pred = sm_co2_hw.forecast(h)

    cu_air_r2 = r2_score(cu_air_pred, air_test)
    cu_co2_r2 = r2_score(cu_co2_pred, co2_test)
    sm_air_r2 = r2_score(sm_air_pred, air_test)
    sm_co2_r2 = r2_score(sm_co2_pred, co2_test)

    assert (cu_air_r2 >= sm_air_r2) or (abs(cu_air_r2 - sm_air_r2) < 2e-1)
    assert (cu_co2_r2 >= sm_co2_r2) or (abs(cu_co2_r2 - sm_co2_r2) < 2e-1)

    full_cu_pred = cu_hw.forecast(h)
    air_cu_r2 = r2_score(full_cu_pred[0], air_test)
    co2_cu_r2 = r2_score(full_cu_pred[1], co2_test)
    assert (air_cu_r2 >= sm_air_r2) or (abs(air_cu_r2 - sm_air_r2) < 2e-1)
    assert (co2_cu_r2 >= sm_co2_r2) or (abs(co2_cu_r2 - sm_co2_r2) < 2e-1)
Beispiel #4
0
def test_multits_holtwinters(seasonal, h, datatype):
    global airpassengers, co2
    airpassengers = np.asarray(airpassengers, dtype=datatype)
    co2 = np.asarray(co2, dtype=datatype)

    air_train = airpassengers[:-h]
    air_test = airpassengers[-h:]
    co2_train = co2[:-h]
    co2_test = co2[-h:]
    data = np.asarray([air_train, co2_train], dtype=datatype)
    cu_hw = cuml_ES(data, seasonal=seasonal,
                    seasonal_periods=12, ts_num=2)

    sm_air_hw = sm_ES(air_train,
                      seasonal=seasonal,
                      seasonal_periods=12)
    sm_co2_hw = sm_ES(co2_train,
                      seasonal=seasonal,
                      seasonal_periods=12)
    cu_hw.fit()
    sm_air_hw = sm_air_hw.fit()
    sm_co2_hw = sm_co2_hw.fit()

    cu_air_pred = cu_hw.forecast(h, 0)
    cu_co2_pred = cu_hw.forecast(h, 1)
    sm_air_pred = sm_air_hw.forecast(h)
    sm_co2_pred = sm_co2_hw.forecast(h)

    cu_air_r2 = r2_score(cu_air_pred.to_array(), air_test)
    cu_co2_r2 = r2_score(cu_co2_pred.to_array(), co2_test)
    sm_air_r2 = r2_score(sm_air_pred, air_test)
    sm_co2_r2 = r2_score(sm_co2_pred, co2_test)

    assert (cu_air_r2 >= sm_air_r2) or (abs(cu_air_r2 - sm_air_r2) < 4)
    assert (cu_co2_r2 >= sm_co2_r2) or (abs(cu_co2_r2 - sm_co2_r2) < 4)

    full_cu_pred = cu_hw.forecast(h)
    air_cu_r2 = r2_score(full_cu_pred[0], air_test)
    co2_cu_r2 = r2_score(full_cu_pred[1], co2_test)
    assert (air_cu_r2 >= sm_air_r2) or (abs(air_cu_r2 - sm_air_r2) < 4)
    assert (co2_cu_r2 >= sm_co2_r2) or (abs(co2_cu_r2 - sm_co2_r2) < 4)
Beispiel #5
0
def test_singlets_holtwinters(seasonal, h, datatype):
    global airpassengers
    airpassengers = np.asarray(airpassengers, dtype=datatype)
    train = airpassengers[:-h]
    test = airpassengers[-h:]

    sm_hw = sm_ES(train, seasonal=seasonal, seasonal_periods=12)
    sm_hw = sm_hw.fit()

    # train = cudf.Series(train)

    cu_hw = cuml_ES(train, seasonal=seasonal, seasonal_periods=12)
    cu_hw.fit()

    cu_pred = cu_hw.forecast(h)
    sm_pred = sm_hw.forecast(h)
    cu_r2 = r2_score(cu_pred, test)
    sm_r2 = r2_score(sm_pred, test)

    assert (cu_r2 >= sm_r2) or (abs(cu_r2 - sm_r2) < 2e-1)