Ejemplo n.º 1
0
def test_convenience(load_df_and_hier_uv):
    hd, hier = load_df_and_hier_uv
    hd = hd.head(200)
    ht = HTSRegressor(model='holt_winters', revision_method='OLS')
    ht = ht.fit(df=hd, nodes=hier)
    preds = ht.predict(steps_ahead=10)

    rev = revise_forecasts(
        'OLS',
        nodes=ht.nodes,
        forecasts=ht.hts_result.forecasts,
        errors=ht.hts_result.errors,
        residuals=ht.hts_result.residuals,
    )

    assert isinstance(rev, pandas.DataFrame)
    assert numpy.allclose(preds.values, rev.values)

    rev_s = revise_forecasts(
        'OLS',
        summing_matrix=ht.sum_mat,
        forecasts=ht.hts_result.forecasts,
        errors=ht.hts_result.errors,
        residuals=ht.hts_result.residuals,
    )
    assert isinstance(rev_s, pandas.DataFrame)
    assert numpy.allclose(rev.values, rev_s.values)

    rev = revise_forecasts('AHP',
                           nodes=ht.nodes,
                           forecasts=ht.hts_result.forecasts)
    assert isinstance(rev, pandas.DataFrame)
Ejemplo n.º 2
0
def test_instantiate_revision(load_df_and_hier_visnights):
    hierarchical_visnights_data, visnights_hier = load_df_and_hier_visnights

    for method in ['OLS', 'FP', 'WLSS', 'WLSV', 'PHA', 'AHP', 'NONE']:
        ht = HTSRegressor(model='holt_winters', revision_method=method)
        ht.fit(df=hierarchical_visnights_data, nodes=visnights_hier)

        rm = RevisionMethod(method,
                            sum_mat=ht.sum_mat,
                            transformer=ht.transform)

        _ = ht.predict(steps_ahead=3)
        revised = rm.revise(forecasts=ht.hts_result.forecasts,
                            mse=ht.hts_result.errors,
                            nodes=ht.nodes)
        assert isinstance(revised, numpy.ndarray)
        assert revised.shape == (11, len(ht.hts_result.forecasts))
Ejemplo n.º 3
0
def test_predict_regressor_visnights(load_df_and_hier_visnights):
    hierarchical_vis_data, vis_hier = load_df_and_hier_visnights
    hvd = hierarchical_vis_data
    for model in ["holt_winters", "auto_arima"]:
        ht = HTSRegressor(model=model, revision_method="OLS")

        ht.fit(df=hvd, nodes=vis_hier)
        preds = ht.predict(steps_ahead=4)

        assert isinstance(preds, pandas.DataFrame)

        # base + steps ahead
        assert len(preds) == len(hvd) + 4
        assert len(ht.hts_result.forecasts["total"]) == len(hvd) + 4
        assert "total" in ht.hts_result.errors
        assert "total" in ht.hts_result.forecasts
        assert "total" in ht.hts_result.residuals

        assert "NSW" in ht.hts_result.errors
        assert "NSW" in ht.hts_result.forecasts
        assert "NSW" in ht.hts_result.residuals
Ejemplo n.º 4
0
def test_predict_regressor_uv(load_df_and_hier_uv):
    hierarchical_sine_data, sine_hier = load_df_and_hier_uv
    hsd = hierarchical_sine_data.head(200)

    for model in ["holt_winters", "auto_arima", "sarimax"]:
        ht = HTSRegressor(model=model, revision_method="OLS")

        ht.fit(df=hsd, nodes=sine_hier)
        preds = ht.predict(steps_ahead=10)

        assert isinstance(preds, pandas.DataFrame)

        # base + steps ahead
        assert len(preds) == len(hsd) + 10
        assert len(ht.hts_result.forecasts["total"]) == len(hsd) + 10
        assert "total" in ht.hts_result.errors
        assert "total" in ht.hts_result.forecasts
        assert "total" in ht.hts_result.residuals

        assert "a" in ht.hts_result.errors
        assert "a" in ht.hts_result.forecasts
        assert "a" in ht.hts_result.residuals