arima icon indicating copy to clipboard operation
arima copied to clipboard

Unexpected prediction output

Open ghost opened this issue 2 years ago • 3 comments

Environment

Lib version: [email protected] Node version: v14.18.2 OS: Linux and macOS

Description

Hi @zemlyansky, we have been happily using your library without issue for some time to forecast some monthly cost data until the beginning of this month, when the predictions have suddenly become wildly inaccurate.

Below is a snippet of js which demonstrates our problem:

const Arima = require('Arima');

const inputA = [
  105.82911266800008, 191.51075963815438, 124.22193611229298, 88.42792338363537,
  85.84729763073994, 88.41525425858667, 72.47634627063404, 68.10950727140339,
  50.184748575943566, 41.052736303601996, 49.81397574690716, 64.4913229728772
];

const inputB = [ // FYI this is the same as inputA, except the first element is removed and a new element has been appended
  191.51075963815438, 124.22193611229298, 88.42792338363537, 85.84729763073994,
  88.41525425858667, 72.47634627063404, 68.10950727140339, 50.184748575943566,
  41.052736303601996, 49.81397574690716, 64.4913229728772, 24.585994644050356
];

for (const input of [inputA, inputB]) {
  const autoArima = new Arima({ auto: true, verbose: false }).fit(input);

  // Predict next 3 values
  const [pred, errors] = autoArima.predict(3);
  console.log('pred', pred, 'errors', errors);
}

If you run this snippet, you should get the following output:

0.05 
pred [ 79.41748022969402, 83.61169866651056, 83.61169866651056 ] errors [ 962.4714568849391, 1393.6548836716488, 1393.6548836716488 ]
0.05 
pred [ -2906.1716859202693, -1885.065226527455, -1340.891848101933 ] errors [ 3.8195924253e-313, 88.41525425858667, 3.8195924261e-313 ]

As you can see, the predictions for inputA look sensible, but the ones for inputB do not.

If it assists, when you set verbose to true, you get the following output:

0.05 
p: 2 d: 0 q: 2 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 1.79769e+308 
p: 0 d: 0 q: 0 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 127.525 
p: 1 d: 0 q: 0 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 126.271 
p: 0 d: 0 q: 1 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 126.178 
p: 0 d: 0 q: 0 P: 0 D: 0 Q: 0 Drift/Mean: 0 ic: 145.608 
p: 1 d: 0 q: 1 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 1.79769e+308 
p: 0 d: 0 q: 2 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 130.095 
p: 1 d: 0 q: 2 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 1.79769e+308 

 AutoARIMA summary: 


 Exit Status 
Return Code : 1 
Exit Message : Probable Success

  ARIMA Seasonal Order : ( 0, 0, 1) * (0, 0, 0) 

Coefficients        Value               Standard Error       

MA1              -0.669343           0.251052             

MEAN             83.6117             14.5387              
TREND            0                    

SIGMA^2          1154.95              

ESTIMATION METHOD : CSS-MLE

OPTIMIZATION METHOD : L-BFGS

AIC criterion : 123.083 

BIC criterion : 124.537 

AICC criterion : 126.083 

Log Likelihood : -58.5413 

Auto ARIMA Parameters 

Approximation: TRUE 
pred [ 79.41748022969402, 83.61169866651056, 83.61169866651056 ] errors [ 962.4714568849391, 1393.6548836716488, 1393.6548836716488 ]
Stepwise: TRUE0.05 
p: 2 d: 1 q: 2 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 121.451 
p: 0 d: 1 q: 0 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 99.1227 
p: 1 d: 1 q: 0 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 102.541 
p: 0 d: 1 q: 1 P: 0 D: 0 Q: 0 Drift/Mean: 1 ic: 100.922 
p: 0 d: 1 q: 0 P: 0 D: 0 Q: 0 Drift/Mean: 0 ic: 100.024 

 AutoARIMA summary: 


 Exit Status 
Return Code : 1 
Exit Message : Probable Success

  ARIMA Seasonal Order : ( 0, 1, 0) * (0, 0, 0) 

Coefficients        Value               Standard Error       


MEAN             0                    
TREND            0                    
EXOG             -15.175             6.95421              

SIGMA^2          585.16               

ESTIMATION METHOD : CSS-MLE

OPTIMIZATION METHOD : L-BFGS

AIC criterion : 104.259 

BIC criterion : 105.055 

AICC criterion : 105.759 

Log Likelihood : -50.1295 

Auto ARIMA Parameters 

Approximation: TRUE 
pred [ -2906.1716859202693, -1885.065226527455, -1340.891848101933 ] errors [ 3.8195924253e-313, 88.41525425858667, 3.8195924261e-313 ]

Please could you assist me in understanding this dramatic change in prediction? Is it a bug?

Many thanks in advance for your time.

Miles

ghost avatar Mar 03 '22 19:03 ghost

As a minor aside, do you know why we are seeing 0.05 in the output as well?

ghost avatar Mar 03 '22 19:03 ghost

Same issue

IbrahimShamma99 avatar Feb 10 '23 17:02 IbrahimShamma99