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

AutoArima 0 mean (no intercept) with constant time series #572

Open BaklazhenkoNikita opened 5 months ago

BaklazhenkoNikita commented 5 months ago

Describe the bug

When provided with a completely constant time series (0,0,0) ARMA is being created with no intercept. Hence, for all the constant time series we predict 0. Slight alteration of time series with epsilon on the other hand leads to (0,0,0) ARMA with mean intercept.

To Reproduce

import pandas as pd
from pmdarima import auto_arima
from IPython.display import display

#Testing the Arima predictions with constant time series (returns 0 predictions)
data = pd.Series([1]*20, index=pd.period_range(start='2024-01-01', periods=20, freq='D'))

auto_arima_model = auto_arima(data, error_action='ignore')

n_periods = 5 
forecast = auto_arima_model.predict(n_periods=n_periods)

display(auto_arima_model.summary())
print("Forecast for constant time series:", forecast)

#Testing the Arima predictions with constant time series and one altered value (returns Mean as predictions)
data_non_constant = pd.Series([1]*19 + [1.1], index=pd.period_range(start='2024-01-01', periods=20, freq='D'))

auto_arima_model_non_constant = auto_arima(data_non_constant, error_action='ignore')

n_periods = 5 
forecast = auto_arima_model_non_constant.predict(n_periods=n_periods)

display(auto_arima_model_non_constant.summary())
print("Forecast for almost constant time series:", forecast)

Versions

Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-glibc2.31
Python 3.9.11 (main, Mar 17 2022, 06:00:02) 
[GCC 10.2.1 20210110]
pmdarima 1.8.4
NumPy 1.24.4
SciPy 1.11.4
Scikit-Learn 1.2.2
Statsmodels 0.14.1

Expected Behavior

Expect to have ARIMA prediction with a constant (with a mean)

Actual Behavior

Predicts future observations with 0

Additional Context

Error happens in line 443-460, if set with_intercept to True, then we predict with a Mean +- epsilon.

ARIMA_0_Constant

image

shreyash-Pandey-Katni commented 4 months ago

Hi Team, Shall I take up this issue?

tgsmith61591 commented 4 months ago

Please feel free @shreyash-Pandey-Katni, and thank you for offering. I've not had the time to look at this

shreyash-Pandey-Katni commented 4 months ago

Thank you, I will start working on it ASAP.