示例#1
0
def test2_predict_is_intervals():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.ARIMAX(formula="y ~ x1 + x2",
                      data=data,
                      ar=2,
                      ma=2,
                      family=pf.Cauchy())
    x = model.fit()
    predictions = model.predict_is(h=10, 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))
示例#2
0
def test_predict_intervals_mh():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.ARIMAX(formula="y ~ x1",
                      data=data,
                      ar=2,
                      ma=2,
                      family=pf.Cauchy())
    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))
def test2_predict_is_intervals_mh():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.GASX(formula="y ~ x1 + x2",
                    data=data,
                    ar=1,
                    sc=1,
                    family=pf.Cauchy())
    x = model.fit('M-H', nsims=400)
    predictions = model.predict_is(h=10, 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 test2_predict_intervals_bbvi():
    """
    Tests prediction intervals are ordered correctly
    """
    model = pf.GASX(formula="y ~ x1 + x2",
                    data=data,
                    ar=1,
                    sc=1,
                    family=pf.Cauchy())
    x = model.fit('BBVI', iterations=100)
    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))
x2 = np.random.normal(0, 1, 300)
data2 = pd.DataFrame([countdata, x1, x2]).T
data2.columns = ['y', 'x1', 'x2']

y_oos = np.random.normal(0, 1, 30)
x1_oos = np.random.normal(0, 1, 30)
x2_oos = np.random.normal(0, 1, 30)
countdata_oos = np.random.poisson(3, 30)

data_oos = pd.DataFrame([y_oos, x1_oos, x2_oos]).T
data_oos.columns = ['y', 'x1', 'x2']

data2_oos = pd.DataFrame([countdata_oos, x1_oos, x2_oos]).T
data2_oos.columns = ['y', 'x1', 'x2']

model_1 = pf.GASX(formula="y ~ x1", data=data, ar=0, sc=0, family=pf.Cauchy())
x_1 = model_1.fit()

model_2 = pf.GASX(formula="y ~ x1", data=data, ar=1, sc=1, family=pf.Cauchy())
x_2 = model_2.fit()

model_3 = pf.GASX(formula="y ~ x1",
                  data=data,
                  ar=1,
                  sc=1,
                  integ=1,
                  family=pf.Cauchy())
x_3 = model_3.fit()

model_4 = pf.GASX(formula="y ~ x1", data=data, ar=2, sc=2, family=pf.Cauchy())
x_4 = model_4.fit()