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

pmdarima negative forecasts #537

Open asgharmustafa opened 1 year ago

asgharmustafa commented 1 year ago

Hi Team, Is it possible for .predict function to generate strictly positive predictions and confidence intervals? If so can you please guide on the change the pmd auto arima and/or predict for this to happen?

nkostiuchenko commented 1 year ago

Hi. This can be done by transforming variable before fitting the model.

Perhaps you want to predict a non-negative variable like the price or quantity. Let the variable be y. Then you need to define new variable lny = ln(y), fit the model on lny, make a prediction lny_pred and apply inverse transformation exp(lny_pred). Or you can use sqrt instead of ln and x ** 2 instead of exp.

But be careful because such transformations tend to bias the estimates of expectation and confidence intervals. If you need to get unbiased estimates, then you need to either calculate a correction for the resulting forecast or conduct a Monte Carlo.

References: