# seasonality tests from pmdarima.arima.seasonality import CHTest, decompose, OCSBTest from pmdarima.arima.utils import nsdiffs from pmdarima.compat.pytest import pytest_error_str from pmdarima.datasets import \ load_airpassengers, load_ausbeer, load_austres, load_wineind import numpy as np from numpy.testing import assert_almost_equal, assert_array_equal from sklearn.utils.validation import check_random_state import pytest from unittest import mock airpassengers = load_airpassengers() austres = load_austres() ausbeer = load_ausbeer() wineind = load_wineind() # change the length to be longer so we can actually test the large case aus_list = austres.tolist() # type: list austres_long = np.asarray(aus_list * 10) # type: np.ndarray @pytest.mark.parametrize('x,type_,m,filter_', [ pytest.param(ausbeer, 'additive', 4, None), pytest.param(airpassengers, 'multiplicative', 12, None), pytest.param(wineind, 'additive', 12, None), pytest.param(np.array([1., 2., 3., 4., 5., 6.]), 'additive', 3, None) ])
#1,2,3; 2,3,4 .... ma3 = data.rolling(window=3, center=True).mean() ma3.head() pd.concat([data, ma3], axis=1) ma3.plot(figsize=(10,7)) fig, ax = plt.subplots(figsize=(10,7)) ax.plot(data) ax.plot(ma3) plt.show(); #different combinations of windows #%%% Exponential Smoothening import pmdarima.datasets as pm data2= pm.load_airpassengers(True) data2 from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt fit2 = SimpleExpSmoothing(np.asarray(data)).fit(smoothing_level=0.6,optimized=False) data.tail(6) fit2.forecast(5) np.vstack([data.tail(10), fit2.forecast(10)]) #%%% fit3 = ExponentialSmoothing(np.asarray(data) ,seasonal_periods=7 , trend='add', seasonal='add',).fit() fit3.forecast(5)
head_index = 17 * 4 + 2 tail_index = 17 * 4 - 4 first_index = head_index - tail_index last_index = head_index ausbeer = datasets.load_ausbeer() timeserie_beer = ausbeer[first_index:last_index] decomposed = arima.decompose(timeserie_beer, 'additive', m=4) # Plot the decomposed signal of ausbeer as a subplot axes = utils.decomposed_plot(decomposed, figure_kwargs=figure_kwargs, show=False) axes[0].set_title("Ausbeer Seasonal Decomposition") # # MULTIPLICATIVE EXAMPLE: airpassengers # # Decompose the airpassengers dataset into trend, seasonal and random parts. decomposed = arima.decompose(datasets.load_airpassengers(), 'multiplicative', m=12) # Plot the decomposed signal of airpassengers as a subplot axes = utils.decomposed_plot(decomposed, figure_kwargs=figure_kwargs, show=False) axes[0].set_title("Airpassengers Seasonal Decomposition")