ARIMA Forecast: Cannot cast ufunc subtract output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

Ankit Tripathi picture Ankit Tripathi · Jun 1, 2018 · Viewed 7.5k times · Source

I am using ARIMA to fit values and save it as a pickle file. Post that, the pickle file is used to get out of sample predictions. However, while getting sample predictions I am getting the following error: Cannot cast ufunc subtract output from dtype('float64') to dtype('int64') with casting rule 'same_kind'.

def forecast_fit(df):            
  series=df
  X = series.values
  train=X
  model = ARIMA(X, order=(1,0,1))
  model_fit = model.fit(disp=0)
  model_fit.save('model.pkl')
forecast_fit(df)
#Out of sample forecasts
loaded = ARIMAResults.load('model.pkl)
forecast = loaded.forecast(steps=17)[0]        #error_occurs_here
df=pd.DataFrame(forecast, columns=[i+'_hat'])  

The df contains the following data: https://docs.google.com/spreadsheets/d/14W77ra-nQYqvDN8wSPhhiN11lBnob6ZW0UVevQ5orKk/edit?usp=sharing

I am attaching the data because the error occurs with this very sample, rest of the variables(I am repeating the exercise for many other variables) don't produce the error.

Answer

Ankit Tripathi picture Ankit Tripathi · Jun 6, 2018

It appears statsmodels ARIMA throws error because it doesn't explicitly converts int to float. If I try to convert data to float, statsmodels will work well.

X = X.astype('float32')

This is already a reported bug on Github.