Example #1
0
def test_pmdarima_diff_inv_fails_with_invalid_data(data):

    analyzer = PmdarimaAnalyzer(df=data.df,
                                group_key_columns=data.key_columns,
                                y_col="y",
                                datetime_col="ds")
    diff = analyzer.generate_diff(lag=1, differences=1)

    with pytest.raises(
            DivinerException,
            match="group_diff_data does not contain the key `diff`"):
        diff_mod = {}
        for key, value in diff.items():
            diff_mod[key] = {"series_start": value.get("series_start")}
        analyzer.generate_diff_inversion(group_diff_data=diff_mod,
                                         lag=1,
                                         differences=1,
                                         recenter=True)

    with pytest.warns(
            UserWarning,
            match="Recentering is not possible due to `series_start` missing"):
        diff_mod = {}
        for key, value in diff.items():
            diff_mod[key] = {"diff": value.get("diff")}
        analyzer.generate_diff_inversion(group_diff_data=diff_mod,
                                         lag=1,
                                         differences=1,
                                         recenter=True)
Example #2
0
def test_pmdarima_reconstruct_series_from_diff_inv(data):

    analyzer = PmdarimaAnalyzer(df=data.df,
                                group_key_columns=data.key_columns,
                                y_col="y",
                                datetime_col="ds")
    diff = analyzer.generate_diff(lag=2, differences=1)

    group_dfs = analyzer._group_df

    inverted = analyzer.generate_diff_inversion(diff,
                                                lag=2,
                                                differences=1,
                                                recenter=True)

    for group, data in group_dfs:

        assert_allclose(data["y"], inverted.get(group), rtol=0.1)
    _print_dict(nsdiffs, "Seasonal Differencing")

    # Get the autocorrelation function for each group
    group_acf = analyzer.calculate_acf(unbiased=True,
                                       nlags=120,
                                       qstat=True,
                                       fft=True,
                                       alpha=0.05,
                                       adjusted=True)

    _print_dict(group_acf, "Autocorrelation function")

    # Get the partial autocorrelation function for each group
    group_pacf = analyzer.calculate_pacf(nlags=120, method="yw", alpha=0.05)

    _print_dict(group_pacf, "Partial Autocorrelation function")

    # Perform a diff operation on each group
    group_diff = analyzer.generate_diff(lag=7, differences=1)

    _print_dict(group_diff, "Differencing")

    # Invert the diff operation on each group
    group_diff_inv = analyzer.generate_diff_inversion(group_diff,
                                                      lag=7,
                                                      differences=1,
                                                      recenter=True)

    _print_dict(group_diff_inv, "Differencing Inversion")