Ejemplo n.º 1
0
def test_new_serialization():
    arima = ARIMA(order=(0, 0, 0), suppress_warnings=True).fit(y)

    # Serialize it, show there is no tmp_loc_
    pkl_file = "file.pkl"
    new_loc = "ts_wrapper.pkl"
    try:
        joblib.dump(arima, pkl_file)

        # Assert it does NOT use the old-style pickling
        assert not _uses_legacy_pickling(arima)
        loaded = joblib.load(pkl_file)
        assert not _uses_legacy_pickling(loaded)
        preds = loaded.predict()
        os.unlink(pkl_file)

        # Now save out the arima_res_ piece separately, and show we can load
        # it from the legacy method
        arima.summary()
        arima.arima_res_.save(fname=new_loc)
        arima.tmp_pkl_ = new_loc

        assert _uses_legacy_pickling(arima)

        # Save/load it and show it works
        joblib.dump(arima, pkl_file)
        loaded2 = joblib.load(pkl_file)
        assert_array_almost_equal(loaded2.predict(), preds)

        # De-cache
        arima._clear_cached_state()
        assert not os.path.exists(new_loc)

        # Show we get an OSError now
        with pytest.raises(OSError) as ose:
            joblib.load(pkl_file)
        assert "Does it still" in str(ose), ose

    finally:
        _unlink_if_exists(pkl_file)
        _unlink_if_exists(new_loc)
Ejemplo n.º 2
0
            stepwise=True,
            trace=1,
            m=args.period,
            information_criterion="aicc",
            seasonal=args.seasonal,
            error_action="ignore",
            suppress_warnings=True,
        )
    elif args.fit:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            arima = ARIMA(order=args.order,
                          seasonal_order=args.seasonal_order)
            arima.fit(train)

    print(arima.summary())

    residuals = arima.resid()
    print("train lengths: data={} resid={}".format(
        train_len, residuals.shape[0]))
    len_delta = train_len - residuals.shape[0]

    # Diagnostics plot
    arima.plot_diagnostics(lags=50)
    box_ljung(residuals, nlags=20).format()
    plt.gcf().suptitle('Diagnostics Plot')
    plt.figure()
    plt.plot(df.value.index[len_delta:train_len],
             np.abs(residuals), label="abs(residuals)")
    plt.plot(df.value, label="data", alpha=0.5)
    # fig, axes = plt.subplots(3, 1, sharex=True)