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

Minimum orders in auto_arima #550

Open
dilwong opened this issue Jun 4, 2023 · 2 comments
Open

Minimum orders in auto_arima #550

dilwong opened this issue Jun 4, 2023 · 2 comments

Comments

@dilwong
Copy link

dilwong commented Jun 4, 2023

In pmdarima.arima.auto_arima, max_p, max_d, and max_q can be specified to indicate the maximum orders of the autoregressive ($p$), first-differencing ($d$), and moving average ($q$) terms. Would there be any value in being able to specify minimum values of $p$, $d$, and $q$ to search over? Maybe this could help speed up the search (by reducing the search space) or give users more flexibility in constraining their models (i.e. if the user had additional domain-knowledge insight into what kind of model was appropriate).

@Relor91
Copy link

Relor91 commented Jul 2, 2023

I have the same issue, it is driving me mad. I am trying to figure it out in the code, will let you know if I manage to fix it

@Relor91
Copy link

Relor91 commented Jul 2, 2023

I found how to deal with it, but beware, this is not an official solution by the people who made the original API, I made it to make my work easier. Also I am not sure if it will damage the overall Stepwise search or anything else, nevertheless if you don't use Stepwise, for now it does seem to work:
Go to the auto.py file by clicking on auto_arima, scroll down to "search = solvers._RandomFitWrapper", you will need to add the below to this function:
start_p=start_p,
start_q=start_q,
start_P=start_P,
start_Q=start_Q
Save it, now go to the _auto_solvers.py and search for the function "class _RandomFitWrapper(_SolverMixin):"
Substitute this function with the below:
class _RandomFitWrapper(_SolverMixin):
"""Searches for the best model using a random search"""

def __init__(self, y, X, fit_partial, d, D, m, max_order,
             start_p, max_p, start_q, max_q, start_P, max_P, start_Q, max_Q, # added start_p, start_q, start_P, start_Q
             random, random_state,
             n_fits, n_jobs, seasonal, trace, with_intercept,
             sarimax_kwargs):

    if seasonal:
        gen = (
            ((p, d, q), (P, D, Q, m))
            for p in range(start_p, max_p + 1)  # changed from 0 to start_p
            for q in range(start_q, max_q + 1)  # changed from 0 to start_q
            for P in range(start_P, max_P + 1)  # changed from 0 to start_P
            for Q in range(start_Q, max_Q + 1)  # changed from 0 to start_Q
            #if p + q + P + Q <= max_order
        )
    else:
        gen = (
            ((p, d, q), (0, 0, 0, 0))
            for p in range(start_p, max_p + 1)  # changed from 0 to start_p
            for q in range(start_q, max_q + 1)  # changed from 0 to start_q
            #if p + q <= max_order
        )

    if random:
        random_state = check_random_state(random_state)
        gen = random_state.permutation(np.array(list(gen), dtype='object'))[:n_fits]

    self.gen = gen
    self.n_jobs = n_jobs
    self.trace = trace

    self.fit_partial = functools.partial(
        fit_partial,
        y=y,
        X=X,
        with_intercept=with_intercept,
        **sarimax_kwargs,
    )

Bosh, save and restart your kernel, now the autoarima will respect the start parameters. I also just tried the Stepwise, and confirm that this amateur fix doesn't work when using Stepwise.

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

No branches or pull requests

2 participants