alkaline-ml / pmdarima

A statistical library designed to fill the void in Python's time series analysis capabilities, including the equivalent of R's auto.arima function.
https://www.alkaline-ml.com/pmdarima
MIT License
1.57k stars 231 forks source link

ValueError When replicating the Quickstart example using `wineind` dataset #461

Closed pmoriano closed 2 years ago

pmoriano commented 2 years ago

Hello, Thanks for putting together this amazing package. I am trying to replicate one of the basic examples in the documentation. See below:

import pmdarima as pm
from pmdarima.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt

# Load/split your data
y = pm.datasets.load_wineind()
train, test = train_test_split(y, train_size=150)

# Fit your model
model = pm.auto_arima(train, seasonal=True, m=12)

However, when building the model (last line) I am getting the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/ipykernel_228524/3922284263.py in <module>
      3 
      4 # Fit model
----> 5 model = pm.auto_arima(train, seasonal=True, m=12)
      6 
      7 # forecasts = model.predict(test.shape[0])

~/.conda/envs/basic38/lib/python3.8/site-packages/pmdarima/arima/auto.py in auto_arima(y, X, start_p, d, start_q, max_p, max_d, max_q, start_P, D, start_Q, max_P, max_D, max_Q, max_order, m, seasonal, stationary, information_criterion, alpha, test, seasonal_test, stepwise, n_jobs, start_params, trend, method, maxiter, offset_test_args, seasonal_test_args, suppress_warnings, error_action, trace, random, random_state, n_fits, return_valid_fits, out_of_sample_size, scoring, scoring_args, with_intercept, sarimax_kwargs, **fit_args)
    715         )
    716 
--> 717     sorted_res = search.solve()
    718     return _return_wrapper(sorted_res, return_valid_fits, start, trace)
    719 

~/.conda/envs/basic38/lib/python3.8/site-packages/pmdarima/arima/_auto_solvers.py in solve(self)
    284 
    285         # fit a baseline p, d, q model
--> 286         self._do_fit((p, d, q), (P, D, Q, m))
    287 
    288         # null model with possible constant

~/.conda/envs/basic38/lib/python3.8/site-packages/pmdarima/arima/_auto_solvers.py in _do_fit(self, order, seasonal_order, constant)
    231             self.k += 1
    232 
--> 233             fit, fit_time, new_ic = self._fit_arima(
    234                 order=order,
    235                 seasonal_order=seasonal_order,

~/.conda/envs/basic38/lib/python3.8/site-packages/pmdarima/arima/_auto_solvers.py in _fit_candidate_model(y, X, order, seasonal_order, start_params, trend, method, maxiter, fit_params, suppress_warnings, trace, error_action, out_of_sample_size, scoring, scoring_args, with_intercept, information_criterion, **kwargs)
    528         # check the roots of the new model, and set IC to inf if the
    529         # roots are near non-invertible
--> 530         ic = _root_test(fit, ic, trace)
    531 
    532     # log the model fit

~/.conda/envs/basic38/lib/python3.8/site-packages/pmdarima/arima/_auto_solvers.py in _root_test(model, ic, trace)
     36 
     37     if p + P > 0:
---> 38         max_invroot = max(0, *np.abs(1 / model.arroots()))
     39     if q + Q > 0 and np.isfinite(ic):
     40         max_invroot = max(0, *np.abs(1 / model.maroots()))

~/.conda/envs/basic38/lib/python3.8/site-packages/sklearn/utils/metaestimators.py in __get__(self, obj, owner)
    107             # delegate only on instances, not the classes.
    108             # this is to allow access to the docstrings.
--> 109             if not self.check(obj):
    110                 raise attr_err
    111 

~/.conda/envs/basic38/lib/python3.8/site-packages/sklearn/utils/metaestimators.py in _check(self, obj)
    195             return False
    196         # raise original AttributeError
--> 197         return getattr(delegate, self.attribute_name) or True
    198 
    199 

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I have no clue of what is the issue. I am running this in Linux with miniconda environment. I would appreciate any pointers. I installed pmdarima following instructions in the documentation for conda.

Thanks in advance.

tgsmith61591 commented 2 years ago

I'm guessing you're running pmdarima 1.8.2. Can you upgrade to 1.8.3? Sklearn shipped a version that broke our dependency on them and it was recently fixed in #455

If that does not solve the issue, please feel free to reopen.

aaronreidsmith commented 2 years ago

If you installed via conda, then you may need to downgrade your scikit-learn version, as 1.8.3 is not available on conda yet (follow this PR to see when it will be available).

Try this:

conda install -c conda-forge scikit-learn=0.24.2
pmoriano commented 2 years ago

@tgsmith61591 and @aaronreidsmith. Thanks for your help. Doing what you suggested works.