GeekyInt
GeekyInt

Reputation: 393

How to predict the time series data in python using ML

I'm building a time series forecasting model.

My dataset is like this:

job,date,maxsal,minsal
Engineer,2001-01,1137,578  
Engineer,2001-02,1187,519
Engineer,2001-03,1131,546 
Engineer,2001-04,1049,604
Engineer,2001-05,1129,579 
Engineer,2001-06,1133,563

Code is:

model = ARIMA(series, order=(1,1,0))
model_fit = model.fit(disp=0)
print(model_fit.summary())  
# plot residual errors
residuals = DataFrame(model_fit.resid)
residuals.plot()
pyplot.show()
residuals.plot(kind='kde')
pyplot.show()
print(residuals.describe())

This will raise the following error:

model_fit = model.fit(disp=0)
  File "/usr/lib/python2.7/dist-packages/statsmodels/tsa/arima_model.py", line 1104, in fit
    callback, **kwargs)
  File "/usr/lib/python2.7/dist-packages/statsmodels/tsa/arima_model.py", line 919, in fit
    start_params = self._fit_start_params((k_ar, k_ma, k), method)
  File "/usr/lib/python2.7/dist-packages/statsmodels/tsa/arima_model.py", line 556, in _fit_start_params
    start_params = self._fit_start_params_hr(order)
  File "/usr/lib/python2.7/dist-packages/statsmodels/tsa/arima_model.py", line 493, in _fit_start_params_hr
    endog -= np.dot(exog, ols_params).squeeze()
TypeError: Cannot cast ufunc subtract output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

I'm trying to predict what is the minsal and maxsal if I give the year as input. I need to plot it in a graph.

Here I Uploaded file

Could anyone please help me?

Upvotes: 1

Views: 197

Answers (1)

Ritesh Bhat
Ritesh Bhat

Reputation: 976

You need to convert your minsal and maxsal columns to float64 type.

You can do this simply by using numpy

import numpy as np

series['maxsal']= series['maxsal'].astype(np.float64)
series['minsal']= series['minsal'].astype(np.float64)

Add these two lines before calling ARIMA

model = ARIMA(series, order=(1,1,0))

Even I faced this issue but in my case, there was only one column to convert. Hope it works for you too.

In some cases, you can directly do like this too.

series = series.astype(np.float64)

Upvotes: 1

Related Questions