From aa249bda4e337780523df0dbe2e6ca74c47dc7c5 Mon Sep 17 00:00:00 2001 From: tgsmith61591 Date: Fri, 12 Jul 2019 15:52:30 -0500 Subject: [PATCH 1/9] Fixes #140 (hopefully) --- pmdarima/arima/arima.py | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/pmdarima/arima/arima.py b/pmdarima/arima/arima.py index 1bcfd713c..d5bd0127c 100644 --- a/pmdarima/arima/arima.py +++ b/pmdarima/arima/arima.py @@ -14,7 +14,6 @@ from statsmodels.tsa.arima_model import ARIMA as _ARIMA from statsmodels.tsa.base.tsa_model import TimeSeriesModelResults -from statsmodels.tsa.tsatools import unintegrate, unintegrate_levels from statsmodels import api as sm from scipy.stats import gaussian_kde, norm @@ -89,13 +88,6 @@ def _seasonal_prediction_with_confidence(arima_res, start, end, exog, alpha, return f, conf_int -def _unintegrate_differenced_preds(preds, results_wrapper, d): - """If predictions were generated on un-integrate, fix it""" - endog = results_wrapper.model.data.endog[-d:] - preds = unintegrate(preds, unintegrate_levels(endog, d))[d:] - return preds - - def _uses_legacy_pickling(arima): # If the package version is < 1.1.0 it uses legacy pickling behavior, but # a later version of the package may actually try to load a legacy model.. @@ -501,7 +493,7 @@ def _check_exog(self, exogenous): def predict_in_sample(self, exogenous=None, start=None, end=None, dynamic=False, return_conf_int=False, - alpha=0.05): + alpha=0.05, typ='linear'): """Generate in-sample predictions from the fit ARIMA model. Predicts the original training (in-sample) time series values. This can @@ -555,17 +547,17 @@ def predict_in_sample(self, exogenous=None, start=None, d = self.order[1] results_wrapper = self.arima_res_ + # The only func that has 'typ' is for ARIMAs, not ARMAs or SARIMAX + kwargs = {} + if d > 0: + kwargs['typ'] = typ + # If not returning the confidence intervals, we have it really easy if not return_conf_int: - preds = results_wrapper.predict(exog=exogenous, start=start, - end=end, dynamic=dynamic) - - # Might need to un-integrate for ARIMA - if not self._is_seasonal() and d > 0: - preds = _unintegrate_differenced_preds( - preds=preds, - results_wrapper=results_wrapper, - d=d) + preds = results_wrapper.predict( + exog=exogenous, start=start, + end=end, dynamic=dynamic, + **kwargs) return preds @@ -587,15 +579,16 @@ def predict_in_sample(self, exogenous=None, start=None, else: preds = results_wrapper.predict( exog=exogenous, start=start, - end=end, dynamic=dynamic) + end=end, dynamic=dynamic, **kwargs) # We only have to un-integrate if there was any differencing + # TODO: prob don't need to since this occurs in the predict code # (i.e., ARIMA vs. ARMA) - if d > 0: - preds = _unintegrate_differenced_preds( - preds=preds, - results_wrapper=results_wrapper, - d=d) + # if d > 0: + # preds = _unintegrate_differenced_preds( + # preds=preds, + # results_wrapper=results_wrapper, + # d=d) # get prediction errors pred_err = results_wrapper._forecast_error(len(preds)) From e064a6f40830d39985546efdf103eca1d10312eb Mon Sep 17 00:00:00 2001 From: tgsmith61591 Date: Sat, 13 Jul 2019 12:44:18 -0500 Subject: [PATCH 2/9] Bump Numpy requirement to 1.16+ to address #165 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 07175d07f..7c177df7b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ Cython>=0.29 joblib>=0.11 -numpy>=1.15 +numpy>=1.16 pandas>=0.19 scikit-learn>=0.19 scipy>=1.3 From ed10096045deace40d7a61b6c83b085fdcc9cd97 Mon Sep 17 00:00:00 2001 From: tgsmith61591 Date: Sat, 13 Jul 2019 12:49:06 -0500 Subject: [PATCH 3/9] Update docstr and doc --- doc/whats_new.rst | 12 ++++++++++++ pmdarima/arima/arima.py | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 333754600..536c4c0f1 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -13,6 +13,18 @@ v0.8.1) will document the latest features. * Adds a new dataset for stock prediction, along with an associated example (``load_msft``) +* Fixes a bug in ``predict_in_sample``, as addressed in `#140 `_. + +* Numpy 1.16+ is now required + +* Statsmodels 0.10.0+ is now required + + +`v1.2.1 `_ +-------------------------------------------------- + +* Pins scipy at 1.12 to avoid a statsmodels bug. + `v1.2.0 `_ -------------------------------------------------- diff --git a/pmdarima/arima/arima.py b/pmdarima/arima/arima.py index d5bd0127c..f62c791fc 100644 --- a/pmdarima/arima/arima.py +++ b/pmdarima/arima/arima.py @@ -531,6 +531,11 @@ def predict_in_sample(self, exogenous=None, start=None, alpha : float, optional (default=0.05) The confidence intervals for the forecasts are (1 - alpha) % + typ : str, optional (default='linear') + The type of prediction to make. Options are ('linear', 'levels'). + This is only used when the underlying model is ARIMA (not ARMA or + SARIMAX). + Returns ------- preds : array From a6bff45bfc39cece6d27e728d7208d85bf9796ae Mon Sep 17 00:00:00 2001 From: tgsmith61591 Date: Sat, 13 Jul 2019 12:54:48 -0500 Subject: [PATCH 4/9] Modernize PyPy build --- build_tools/circle/build_test_pypy.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/build_tools/circle/build_test_pypy.sh b/build_tools/circle/build_test_pypy.sh index 97805b837..f8ee4a9dc 100755 --- a/build_tools/circle/build_test_pypy.sh +++ b/build_tools/circle/build_test_pypy.sh @@ -16,13 +16,8 @@ source pypy-env/bin/activate python --version which python -# This is a temporary fix for #93: -# XXX: numpy version pinning can be reverted once PyPy -# compatibility is resolved for numpy v1.6.x. For instance, -# when PyPy3 >6.0 is released (see numpy/numpy#12740) -pip install --extra-index https://antocuni.github.io/pypy-wheels/ubuntu numpy=="1.15.*" Cython pytest -pip install "scipy>=1.1.0" -pip install "scikit-learn==0.19.*" +pip install --extra-index https://antocuni.github.io/pypy-wheels/ubuntu numpy Cython pytest scipy scikit-learn + # Pandas has starting throwing issues in Pypy now... pip install "pandas==0.23.*" statsmodels matplotlib pip install --extra-index https://antocuni.github.io/pypy-wheels/ubuntu pytest-mpl pytest-benchmark From 196b241faffd62b40fc85c6d776c8b6b71c37768 Mon Sep 17 00:00:00 2001 From: tgsmith61591 Date: Sat, 13 Jul 2019 12:57:03 -0500 Subject: [PATCH 5/9] :rage: --- build_tools/circle/build_test_pypy.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build_tools/circle/build_test_pypy.sh b/build_tools/circle/build_test_pypy.sh index f8ee4a9dc..7a590fe0c 100755 --- a/build_tools/circle/build_test_pypy.sh +++ b/build_tools/circle/build_test_pypy.sh @@ -16,8 +16,9 @@ source pypy-env/bin/activate python --version which python -pip install --extra-index https://antocuni.github.io/pypy-wheels/ubuntu numpy Cython pytest scipy scikit-learn - +pip install --extra-index https://antocuni.github.io/pypy-wheels/ubuntu numpy Cython pytest +pip install scipy +pip install scikit-learn # Pandas has starting throwing issues in Pypy now... pip install "pandas==0.23.*" statsmodels matplotlib pip install --extra-index https://antocuni.github.io/pypy-wheels/ubuntu pytest-mpl pytest-benchmark From 6b1395f62e068c7ded37ddfc2fc43c3ed6033db1 Mon Sep 17 00:00:00 2001 From: tgsmith61591 Date: Sat, 13 Jul 2019 13:01:57 -0500 Subject: [PATCH 6/9] Use latest pypy image --- .circleci/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a6c2278a6..afa2b6311 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,9 +55,9 @@ commands: jobs: # For testing PyPy rather than CPython - pypy36: + pypy: docker: - - image: pypy:3-6.0.0 + - image: pypy:latest steps: # Download and cache dependencies - restore_cache: @@ -184,7 +184,7 @@ workflows: pmdarima-pipeline: jobs: # All testing jobs - - pypy36: + - pypy: filters: *test-filters - cpython35: filters: *test-filters @@ -198,7 +198,7 @@ workflows: filters: *test-filters - testing-passed: requires: - - pypy36 + - pypy - cpython35 - cpython36 - cpython37 From 544b6d6865c86ab8d5aea1e742859eb0638b3c50 Mon Sep 17 00:00:00 2001 From: tgsmith61591 Date: Sat, 13 Jul 2019 13:35:43 -0500 Subject: [PATCH 7/9] Change PyPy test image again --- .circleci/config.yml | 2 +- doc/whats_new.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index afa2b6311..1ddafe2ca 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,7 +57,7 @@ jobs: # For testing PyPy rather than CPython pypy: docker: - - image: pypy:latest + - image: pypy:3.6-7.1.1 steps: # Download and cache dependencies - restore_cache: diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 536c4c0f1..ee905fac4 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -23,7 +23,7 @@ v0.8.1) will document the latest features. `v1.2.1 `_ -------------------------------------------------- -* Pins scipy at 1.12 to avoid a statsmodels bug. +* Pins scipy at 1.2.0 to avoid a statsmodels bug. `v1.2.0 `_ From 92275a9021a553a575f36b6c09426103a1647119 Mon Sep 17 00:00:00 2001 From: tgsmith61591 Date: Sat, 13 Jul 2019 13:55:17 -0500 Subject: [PATCH 8/9] No longer call before_install for regression testing --- .circleci/config.yml | 2 +- build_tools/circle/build_test_pypy.sh | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ddafe2ca..9e85fb9ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -112,7 +112,7 @@ jobs: working_directory: ~/pmdarima steps: - checkout - - run: ./build_tools/circle/before_install.sh + # - run: ./build_tools/circle/before_install.sh - run: ./build_tools/circle/regression_testing.sh # Simple job that passes when all other tests have passed diff --git a/build_tools/circle/build_test_pypy.sh b/build_tools/circle/build_test_pypy.sh index 7a590fe0c..19e0f9efc 100755 --- a/build_tools/circle/build_test_pypy.sh +++ b/build_tools/circle/build_test_pypy.sh @@ -16,12 +16,15 @@ source pypy-env/bin/activate python --version which python -pip install --extra-index https://antocuni.github.io/pypy-wheels/ubuntu numpy Cython pytest -pip install scipy -pip install scikit-learn +extra_index_url="https://antocuni.github.io/pypy-wheels/ubuntu" + +pip install --extra-index ${extra_index_url} numpy Cython pytest +pip install --extra-index ${extra_index_url} scipy +pip install --extra-index ${extra_index_url} scikit-learn + # Pandas has starting throwing issues in Pypy now... pip install "pandas==0.23.*" statsmodels matplotlib -pip install --extra-index https://antocuni.github.io/pypy-wheels/ubuntu pytest-mpl pytest-benchmark +pip install --extra-index ${extra_index_url} pytest-mpl pytest-benchmark ccache -M 512M export CCACHE_COMPRESS=1 From 8fe1f8425de4c9b9008a740e46202f02aa9e7d03 Mon Sep 17 00:00:00 2001 From: tgsmith61591 Date: Sat, 13 Jul 2019 16:24:16 -0500 Subject: [PATCH 9/9] Remove before_install from doc build --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9e85fb9ec..d69fe904d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -174,7 +174,7 @@ jobs: working_directory: ~/pmdarima steps: - checkout - - run: ./build_tools/circle/before_install.sh + # - run: ./build_tools/circle/before_install.sh - run: make doc-requirements - run: make install - run: ./build_tools/circle/build_push_doc.sh