def test_predict_nans():
    """
    Tests that the predictions are not NaNs
    """
    model = ARIMAX(formula="y ~ x1", data=data, ar=2, ma=2, family=Laplace())
    x = model.fit()
    x.summary()
    assert(len(model.predict(h=5, oos_data=data_oos).values[np.isnan(model.predict(h=5, 
        oos_data=data_oos).values)]) == 0)
def test_predict_length():
    """
    Tests that the length of the predict dataframe is equal to no of steps h
    """
    model = ARIMAX(formula="y ~ x1", data=data, ar=2, ma=2)
    x = model.fit()
    x.summary()
    assert (model.predict(h=5, oos_data=data_oos).shape[0] == 5)
def test_2_predict_nonconstant():
    """
    We should not really have predictions that are constant (should be some difference)...
    This captures bugs with the predict function not iterating forward
    """
    model = ARIMAX(formula="y ~ x1 + x2", data=data, ar=2, ma=2)
    x = model.fit()
    predictions = model.predict(h=10, oos_data=data_oos, intervals=False)
    assert (not np.all(predictions.values == predictions.values[0]))
def test_predict_nonconstant():
    """
    We should not really have predictions that are constant (should be some difference)...
    This captures bugs with the predict function not iterating forward
    """
    model = ARIMAX(formula="y ~ x1", data=data, ar=1, ma=1, family=Poisson())
    x = model.fit('BBVI', iterations=200, quiet_progress=True)
    predictions = model.predict(h=10, oos_data=data_oos, intervals=False)
    assert (not np.all(predictions.values == predictions.values[0]))
def test_2_predict_intervals_mh():
    """
    Tests prediction intervals are ordered correctly
    """
    model = ARIMAX(formula="y ~ x1 + x2", data=data, ar=2, ma=2, family=Laplace())
    x = model.fit('M-H', nsims=200, quiet_progress=True)
    predictions = model.predict(h=10, oos_data=data_oos, intervals=True)

    assert(np.all(predictions['99% Prediction Interval'].values > predictions['95% Prediction Interval'].values))
    assert(np.all(predictions['95% Prediction Interval'].values > predictions[model.data_name].values))
    assert(np.all(predictions[model.data_name].values > predictions['5% Prediction Interval'].values))
    assert(np.all(predictions['5% Prediction Interval'].values > predictions['1% Prediction Interval'].values))
Ejemplo n.º 6
0
def test_predict_intervals_bbvi():
    """
    Tests prediction intervals are ordered correctly
    """
    model = ARIMAX(formula="y ~ x1", data=data, ar=2, ma=2, family=t())
    x = model.fit('BBVI', iterations=100, quiet_progress=True)
    predictions = model.predict(h=10, oos_data=data_oos, intervals=True)

    assert(np.all(predictions['99% Prediction Interval'].values > predictions['95% Prediction Interval'].values))
    assert(np.all(predictions['95% Prediction Interval'].values > predictions[model.data_name].values))
    assert(np.all(predictions[model.data_name].values > predictions['5% Prediction Interval'].values))
    assert(np.all(predictions['5% Prediction Interval'].values > predictions['1% Prediction Interval'].values))
def test_predict_intervals():
    """
    Tests prediction intervals are ordered correctly
    """
    model = ARIMAX(formula="y ~ x1", data=data, ar=2, ma=2, family=Poisson())
    x = model.fit()
    predictions = model.predict(h=10, oos_data=data_oos, intervals=True)

    assert (np.all(predictions['99% Prediction Interval'].values >=
                   predictions['95% Prediction Interval'].values))
    assert (np.all(predictions['95% Prediction Interval'].values >=
                   predictions['5% Prediction Interval'].values))
    assert (np.all(predictions['5% Prediction Interval'].values >=
                   predictions['1% Prediction Interval'].values))
def a_test2_predict_intervals_mh():
    """
    Tests prediction intervals are ordered correctly
    """
    model = ARIMAX(formula="y ~ x1 + x2",
                   data=data,
                   ar=2,
                   ma=2,
                   family=Exponential())
    x = model.fit('M-H', nsims=400)
    predictions = model.predict(h=10, oos_data=data_oos, intervals=True)

    assert (np.all(predictions['99% Prediction Interval'].values >=
                   predictions['95% Prediction Interval'].values))
    assert (np.all(predictions['95% Prediction Interval'].values >=
                   predictions['5% Prediction Interval'].values))
    assert (np.all(predictions['5% Prediction Interval'].values >=
                   predictions['1% Prediction Interval'].values))