https://github.com/nixtla logo
#general
Title
# general
m

Manuel

08/03/2023, 11:06 AM
With
AutoARIMA
when I set both
stepwise=False
and
max_q=0
I get this error:
Copy code
File /opt/conda/lib/python3.10/site-packages/statsforecast/core.py:581, in _StatsForecast.fit(self, df, sort_df)
    579     self.fitted_ = self.ga.fit(models=self.models)
    580 else:
--> 581     self.fitted_ = self._fit_parallel()
    582 return self

File /opt/conda/lib/python3.10/site-packages/statsforecast/core.py:940, in _StatsForecast._fit_parallel(self)
    938         future = executor.apply_async(ga.fit, (self.models,))
    939         futures.append(future)
--> 940     fm = np.vstack([f.get() for f in futures])
    941 return fm

File /opt/conda/lib/python3.10/site-packages/statsforecast/core.py:940, in <listcomp>(.0)
    938         future = executor.apply_async(ga.fit, (self.models,))
    939         futures.append(future)
--> 940     fm = np.vstack([f.get() for f in futures])
    941 return fm

File /opt/conda/lib/python3.10/multiprocessing/pool.py:774, in ApplyResult.get(self, timeout)
    772     return self._value
    773 else:
--> 774     raise self._value

UnboundLocalError: local variable 'best_fit' referenced before assignment
k

Kevin Kho

08/03/2023, 4:52 PM
Could you open an issue for this?
m

Manuel

08/03/2023, 4:55 PM
@Kevin Kho I've found that a similar issue has already been reported https://github.com/Nixtla/statsforecast/issues/152 However it looks like he just set
stepwise=False
(which in my case works fine until I also set
max_q=0
)
k

Kevin Kho

08/03/2023, 4:56 PM
Ah ok. Thanks!
b

Bartosz Bohaterewicz

08/03/2023, 9:49 PM
What about setting max_q to None?
k

Kevin Kho

08/03/2023, 9:52 PM
I think it will still error because the loop is not passed here
None will mess up the
range()
also
@Manuel, does using the AutoRegressive instead work for you?
m

Manuel

08/03/2023, 10:33 PM
It seems to work, should I expect any error?
k

Kevin Kho

08/03/2023, 10:48 PM
No you shouldn’t. That’s equivalent to q=0 right?
m

Manuel

08/03/2023, 10:55 PM
@Kevin Kho I think the problem is that the fit is not executed when max_p or max_q or max_P or max_Q are set to zero. Maybe we should change the code to:
Copy code
for i in range(max_p + 1):
        for j in range(max_q + 1):
            for I in range(max_P + 1):
                for J in range(max_Q + 1):
                    if i + j + I + J > max_order:
So that the fit is executed at least 1 time even when one of those parameters is set to zero.
k

Kevin Kho

08/03/2023, 10:56 PM
I think that would add extra runs right?
Ah maybe not…
I think @Mariana Menchero can chime in?
m

Manuel

08/03/2023, 10:59 PM
I think it's an error introduced when you ported code from R. This is the auto.arima code:
Copy code
for (i in 0:max.p) {
      for (j in 0:max.q) {
        for (I in 0:max.P) {
          for (J in 0:max.Q) {
:max.p etc. is inclusive, so you have to add 1 to get the same behavior in Python
k

Kevin Kho

08/03/2023, 11:01 PM
I believe you, but I don’t work on the models so I need someone else to chime in 😂 . I am more on the Spark, Dask, Ray side and distributed computing.
m

Manuel

08/03/2023, 11:09 PM
So basically there's also the problem that max_p, max_q etc. values are never tried (because range()'s stop value is not inclusive)
k

Kevin Kho

08/04/2023, 1:03 AM
Yeah
m

Manuel

08/04/2023, 8:11 AM
I created a pull request to fix this
k

Kevin Kho

08/04/2023, 1:51 PM
Thanks! Will take a look in a bit
m

Mariana Menchero

08/04/2023, 7:26 PM
Hi! I'll take a look at this issue. Thanks for bringing this up 🙂