コード例 #1
0
def test_issue_341():
    y = [
        0, 132, 163, 238, 29, 0, 150, 320, 249, 224, 197, 31, 0, 154, 143, 132,
        135, 158, 21, 0, 126, 100, 137, 105, 104, 8, 0, 165, 191, 234, 253,
        155, 25, 0, 228, 234, 265, 205, 191, 19, 0, 188, 156, 172, 173, 166,
        28, 0, 209, 160, 159, 129, 124, 18, 0, 155
    ]

    with pytest.raises(ValueError) as ve:
        auto.auto_arima(y,
                        start_p=1,
                        start_q=1,
                        test='adf',
                        max_p=3,
                        max_q=3,
                        m=52,
                        start_P=0,
                        seasonal=True,
                        d=None,
                        D=1,
                        trace=True,
                        error_action='ignore',
                        suppress_warnings=True,
                        stepwise=True)

    # assert that we catch the np LinAlg error and reraise with a more
    # meaningful message
    assert "Encountered exception in stationarity test" in pytest_error_str(ve)
コード例 #2
0
def test_max_dur():
    # set arbitrarily low to guarantee will always pass after one iter
    with StepwiseContext(max_dur=.5), \
            pytest.warns(UserWarning) as uw:

        auto_arima(lynx, stepwise=True)
        # assert that max_dur was reached
        assert any(str(w.message).startswith('early termination') for w in uw)
コード例 #3
0
def test_auto_arima_with_stepwise_context():
    samp = lynx[:8]
    with StepwiseContext(max_steps=3, max_dur=30):
        with pytest.warns(UserWarning) as uw:
            auto_arima(samp,
                       suppress_warnings=False,
                       stepwise=True,
                       error_action='ignore')

            # assert that max_steps were taken
            assert any(
                str(w.message).startswith('stepwise search has reached the '
                                          'maximum number of tries')
                for w in uw)
コード例 #4
0
def test_subsequent_contexts():
    # Force a very fast fit
    with StepwiseContext(max_dur=.5), \
            pytest.warns(UserWarning):
        auto_arima(lynx, stepwise=True)

    # Out of scope, should be EMPTY
    assert ContextStore.get_or_empty(ContextType.STEPWISE).get_type() \
        is ContextType.EMPTY

    # Now show that we DON'T hit early termination by time here
    with StepwiseContext(max_steps=100), \
            pytest.warns(UserWarning) as uw:

        ctx = ContextStore.get_or_empty(ContextType.STEPWISE)
        assert ctx.get_type() is ContextType.STEPWISE
        assert ctx.max_dur is None

        auto_arima(lynx, stepwise=True)
        # assert that max_dur was NOT reached
        assert not any(
            str(w.message).startswith('early termination') for w in uw)
コード例 #5
0
#print(result)
result.plot()
plt.savefig('SeasonalDecompose.png')
#print(weeklySales.values)
#print(monthlySales.index)

#ap.plotacf(weeklySales,'WeeklySales',show=False,save=True)
#ap.plotacf(monthlySales,'MonthlylySales',show=False,save=True)

stepwise_model = auto_arima(dailySales,
                            start_p=1,
                            start_q=1,
                            max_p=3,
                            max_q=3,
                            m=7,
                            start_P=0,
                            seasonal=True,
                            d=1,
                            D=1,
                            trace=False,
                            error_action='ignore',
                            suppress_warnings=True,
                            stepwise=True)
#print(stepwise_model.aic())
#print(stepwise_model.order)
#print(stepwise_model.seasonal_order)

model = sm.tsa.statespace.SARIMAX(dailySales,
                                  order=stepwise_model.order,
                                  seasonal_order=stepwise_model.seasonal_order,
                                  enforce_stationarity=False,
                                  enforce_invertibility=False)