Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: predict() got an unexpected keyword argument 'typ' raised during cross-validation #29

Closed
ahardjasa opened this issue Aug 11, 2018 · 2 comments

Comments

@ahardjasa
Copy link

Description

TypeError: predict() got an unexpected keyword argument 'typ' raised when seasonal=False, CV is performed (i.e. out_of_sample_size is passed) and a d of 0 is selected by auto_arima.
I think this is because an ARMA model doesn't take a typ argument, but here typ='linear' is being passed.

Steps/Code to Reproduce

from pyramid.arima import auto_arima
import pandas
auto_arima(pandas.Series([3.0, 4.0, 1.0, 2.0, 1.0, 2.0, 0.0, 1.0, 
0.0, 0.0, 2.0, 0.0, 1.0, 1.0, 2.0, 2.0]), 
out_of_sample_size=3, seasonal=False)

Versions

Linux-4.15.0-29-generic-x86_64-with-debian-buster-sid
Python 3.5.5 (default, Jul 24 2018, 13:20:46)
[GCC 7.3.0]
Pyramid 0.6.5
NumPy 1.15.0
SciPy 1.1.0
Scikit-Learn 0.19.2
Statsmodels 0.9.0

@tgsmith61591
Copy link
Member

tgsmith61591 commented Aug 11, 2018

Thanks for filing! And good sleuthing. I'll take a look into this and the fix will be part of 0.7.0

@tgsmith61591
Copy link
Member

tgsmith61591 commented Aug 13, 2018

This was technically handled in #28 since the new code doesn't use typ='linear' anymore:

        if cv_samples is not None:
            # get the predictions (use self.predict, which calls forecast
            # from statsmodels internally)
            pred = self.predict(n_periods=cv, exogenous=cv_exog)
            self.oob_ = scoring(cv_samples, pred, **self.scoring_args)

            # If we compute out of sample scores, we have to now update the
            # observed time points so future forecasts originate from the end
            # of our y vec
            self.add_new_observations(cv_samples, cv_exog)
        else:
            self.oob_ = np.nan

But to be sure, I've included some new unit tests for cases where d=0 and out_of_sample > 0. See, for instance, pyramid/arima/tests/test_arima.test_oob_for_issue_29:

from pyramid.arima import ARIMA
import numpy as np

# Test Issue #29 (d=0, cv=True) -----------------------------------------------
def test_oob_for_issue_29():
    y = np.array([3.0, 4.0, 1.0, 2.0, 1.0, 2.0, 0.0, 1.0,
                  0.0, 0.0, 2.0, 0.0, 1.0, 1.0, 2.0, 2.0])

    xreg = np.random.RandomState(1).rand(y.shape[0], 3)

    # Try for cv on/off, various D levels, and various Xregs
    for d in (0, 1):
        for cv in (0, 3):
            for exog in (xreg, None):

                # surround with try/except so we can log the failing combo
                try:
                    model = ARIMA(order=(1, d, 1),
                                  out_of_sample_size=cv).fit(y, exogenous=exog)

                    # If exogenous is defined, we need to pass n_periods of
                    # exogenous rows to the predict function. Otherwise we'll
                    # just leave it at None
                    if exog is not None:
                        xr = exog[:3, :]
                    else:
                        xr = None

                    _, _ = model.predict(n_periods=3, return_conf_int=True,
                                         exogenous=xr)

                except Exception:
                    print("Failing combo: d=%i, cv=%i, exog=%r"
                          % (d, cv, exog))
                    raise

The changes that make this functional are going to be released with v0.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants