Reputation: 2007
Passing the value of the parameter start_p
as 4
in the function auto_arima()
should make the parameter search start from 4 i.e.
(4,x,x)(x,x,x,x) but it starts from (0,x,x)(x,x,x,x) completely avoiding the argument 4
.
import pandas as pd
from pmdarima import auto_arima
train_df = pd.read_csv('https://raw.githubusercontent.com/vyaduvanshi/helper-files/master/train_SO.csv')
auto_arima(train_df.new_cases, start_p=4, d=0, start_q=0, max_p=5, max_d=0, max_q=5,
start_P=0, D=0, start_Q=0, max_P=5, max_D=0, max_Q=5, seasonal=True, m=7, maxiter=200, trace=True,
information_criterion='aic', with_intercept=False, stepwise=False, max_order=None)
Here is what it looks like after I run the code-
ARIMA(0,0,0)(0,0,0)[7] : AIC=13942.223, Time=0.01 sec
ARIMA(0,0,0)(0,0,1)[7] : AIC=13625.127, Time=0.06 sec
ARIMA(0,0,0)(0,0,2)[7] : AIC=13572.472, Time=0.11 sec
ARIMA(0,0,0)(0,0,3)[7] : AIC=13573.420, Time=0.22 sec
ARIMA(0,0,0)(0,0,4)[7] : AIC=13591.829, Time=0.40 sec
ARIMA(0,0,0)(0,0,5)[7] : AIC=13612.307, Time=1.04 sec
ARIMA(0,0,0)(1,0,0)[7] : AIC=inf, Time=0.08 sec
...
...
...
Upvotes: 1
Views: 349
Reputation: 11
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 parameters 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.
Upvotes: 1