Example #1
0
def test_nsdiffs_corner_cases():
    # max_D must be a positive int
    with pytest.raises(ValueError):
        nsdiffs(austres, m=2, max_D=0)

    # assert 0 for constant
    assert nsdiffs([1, 1, 1, 1], m=2) == 0

    # show fails for m <= 1
    for m in (0, 1):
        with pytest.raises(ValueError):
            nsdiffs(austres, m=m)
Example #2
0
def test_nsdiffs_corner_cases():
    # max_D must be a positive int
    assert_raises(ValueError, nsdiffs, austres, m=2, max_D=0)

    # assert 0 for constant
    assert nsdiffs([1, 1, 1, 1], m=2) == 0

    # show fails for m <= 1
    assert_raises(ValueError, nsdiffs, austres, m=1)
    assert_raises(ValueError, nsdiffs, austres, m=0)
    def autoarima(self, data, pre_len=7):
        D_f = nsdiffs(data, m=3, max_D=5, test='ch')
        d_f = ndiffs(data, alpha=0.05, test='kpss', max_d=5)
        if len(data) <= 30:
            seasonal = False
        else:
            seasonal = True
        try:
            stepwise_fit = auto_arima(
                data,
                start_p=0,
                start_q=0,
                max_p=3,
                max_q=3,
                m=12,
                start_P=0,
                seasonal=seasonal,
                d=d_f,
                D=D_f,
                trace=False,
                error_action=
                'ignore',  # don't want to know if an order does not work
                suppress_warnings=True,  # don't want convergence warnings
                stepwise=True)  # set to stepwise
        except:
            stepwise_fit = auto_arima(
                data,
                start_p=0,
                start_q=0,
                max_p=3,
                max_q=0,
                m=12,
                start_P=0,
                seasonal=False,
                d=0,
                D=0,
                trace=False,
                error_action=
                'ignore',  # don't want to know if an order does not work
                suppress_warnings=True,  # don't want convergence warnings
                stepwise=True)  # set to stepwise
        output = stepwise_fit.predict(n_periods=pre_len).tolist()

        self._get_model({
            'model_name': 'autoarima',
            'model': stepwise_fit,
            'pred': output,
            'org_data': data,
            'pre_len': pre_len
        })

        return output
Example #4
0
def test_nsdiffs_on_wine():
    assert nsdiffs(wineind, m=52) == 2
    #exit()
    print('==-Order of (d,D) ===')
    r = []
    terr = [v for v in h_snl['STND_TRRTRY_NM'].unique()]
    for ter in terr:
        terrData = h_snl[h_snl.STND_TRRTRY_NM == ter]
        optionList = list(set(terrData.KEY))
        for i in optionList:
            print('In progress' + '\n' + ter + '-----' + str(i))
            r1 = pd.DataFrame()
            histData = h_snl[(h_snl.STND_TRRTRY_NM == ter) & (h_snl.KEY == i)]
            if len(histData) >= 52:
                sales = histData['RTL_QTY']
                try:
                    d = int(ndiffs(sales, test='adf'))
                    D = int(nsdiffs(sales, m=52, max_D=5))
                    r.append(ter + "_" + str(i) + "_" + str(d) + "_" + str(D))
                    print('== Difference algo works ==')
                except:
                    d = 1
                    D = 0
                    r.append(ter + "_" + str(i) + "_" + str(d) + "_" + str(D))
                    print('== Difference algo fails  ==')

            else:
                histData['d'] = 1
                histData['D'] = 0
                r.append(ter + "_" + str(i) + "_" + str(d) + "_" + str(D))
                print('== Less history ==')

    orderdf = pd.DataFrame()