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.55k stars 228 forks source link

auto_arima with out_of_sample_size provided returns np.array in prediction when pd.Series was given for estimation #559

Open nkostiuchenko opened 10 months ago

nkostiuchenko commented 10 months ago

Describe the bug

If the auto_arima is estimated with pd.Series it returns pd.Series from prediction (the same works for np.array). But when the auto_arima is estimated providing the out_of_sample_size parameter, it returns np.array from prediction independent of the object type used in estimation.

To Reproduce

#%%
import numpy as np
import pandas as pd

import pmdarima as pm

#%%
data = pm.datasets.load_lynx()

data_np = np.array(data)
data_pd = pd.Series(data)

#%%
model_np = pm.auto_arima(data_np)
model_pd = pm.auto_arima(data_pd)

# %%
print('np prediction', model_np.predict(1).__class__)
print('pd prediction', model_pd.predict(1).__class__)

# Output:
# np prediction <class 'numpy.ndarray'>
# pd prediction <class 'pandas.core.series.Series'>

# %%
modelx_np = pm.auto_arima(data_np, out_of_sample_size=1)
modelx_pd = pm.auto_arima(data_pd, out_of_sample_size=1)

# %%
print('np prediction with out_of_sample_size', modelx_np.predict(1).__class__)
print('pd prediction with out_of_sample_size', modelx_pd.predict(1).__class__)

# Output:
# np prediction with out_of_sample_size <class 'numpy.ndarray'>
# pd prediction with out_of_sample_size <class 'numpy.ndarray'>

Versions

System:
    python: 3.11.4 (main, Aug 21 2023, 21:32:39) [GCC 11.4.0]
executable: /home/unixuser/projects/pmdarima/.venv/bin/python
   machine: Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.35

Python dependencies:
 setuptools: 65.5.0
        pip: 23.2.1
    sklearn: 1.3.0
statsmodels: 0.14.0
      numpy: 1.25.2
      scipy: 1.11.2
     Cython: 3.0.2
     pandas: 2.1.0
     joblib: 1.3.2
   pmdarima: 0.0.0 # commit 1bb0ef5246c4e34712ef3e7843cf51a64b62bf0a
Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python 3.11.4 (main, Aug 21 2023, 21:32:39) [GCC 11.4.0]
pmdarima 0.0.0
NumPy 1.25.2
SciPy 1.11.2
Scikit-Learn 1.3.0
Statsmodels 0.14.0

Expected Behavior

It seems like the return type of prediction should not change due to the out_of_sample_size parameter.

Actual Behavior

The return type of prediction depends on the out_of_sample_size parameter of auto_arima.

Additional Context

No response