Building Time Series Model - Getting error involving datetime

0 votes

CODE SNIPPETS:

...

#get predictions starting from 2016-01-01 and calculate confidence intervals
        pred = output.get_prediction(start=pd.to_datetime('2017-09-14'), dynamic=False)
        pred_conf = pred.conf_int()

ERROR:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'
Apr 8 in Python by Sharonda
• 150 points
73 views

Hey, @Sharonda,

Could you please how did you try to run your code? And along with can you please also post your models.py?

1 answer to this question.

0 votes
Best answer

Hey sharonda,

Use a python datetime or string 

results.get_prediction(start='2020-04-08', axis=0)
# or
import datetime as dt
results.get_prediction(start=dt.datetime(2020, 4, 8), axis=0)

Try this once or post your model.py file.

Thank You!!

answered Apr 8 by Niroj
• 22,110 points

selected Apr 9 by Sharonda

Thank you, Niroj the following statement cleared the error:

---

results.get_prediction(start='2020-04-08', axis=0)

Hello I am experiencing a similar error and tried the same thing but did not work. Can you please guide me on this?

#code

pred = results.get_prediction(start=pd.to_datetime('2019-09-25'), dynamic=False, axis = 0)
pred_ci = pred.conf_int()
ax = y[:].plot(label='observed')
pred.predicted_mean.plot(ax=ax, label='One-step ahead Forecast', alpha=.7, figsize=(14, 4))
ax.fill_between(pred_ci.index,
                pred_ci.iloc[:, 0],
                pred_ci.iloc[:, 1], color='k', alpha=.2)
ax.set_xlabel('Date')
ax.set_ylabel('Close')
plt.legend()
plt.show()

ERROR 

TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'

Hello Sanket Dayama,

You have two options:

  1. You can call results.predict using integers for start and end (e.g. results.predict(start=results.nobs, end=results.nobs + 10)) and then attach whatever dates you like to the resulting forecasts.

  2. You can reindex your data to have a date series with daily frequency. For example:

train1_reindex = train1.reindex(pd.DatetimeIndex(start=train1.date[0], end=train1.date[-1], freq='D'))

This will mean your new time series will have NaNs in it, but that's not a problem for SARIMAX. In fact, it should give you better results, since simply removing missing observations is not the right way to deal with missing observations in models like ARIMA where today's value depends on yesterday's value.

Hope this helps!!

Related Questions In Python

0 votes
1 answer

How does time series analysis with statsmodels work?

I'd really like to see a data ...READ MORE

answered Sep 4, 2018 in Python by Priyaj
• 57,530 points
2,014 views
0 votes
1 answer

Getting this error Error sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type

Found out that the problem was that ...READ MORE

answered Oct 1, 2018 in Python by Priyaj
• 57,530 points
3,182 views
0 votes
1 answer

Why am I getting a error when I am printing two different data types in python?

different data type is being used. that ...READ MORE

answered Mar 6, 2019 in Python by Mohammad
• 3,230 points
82 views
0 votes
1 answer

Python error "'Series' object is not callable "

Try this: df['ln_returns'] = np.log(df['Close_mid']/df['Close_mid']) df['Close_mid'](1)) doesn't seem to ...READ MORE

answered Jul 22, 2019 in Python by Greg
5,598 views
0 votes
1 answer

R lag irregular time series data

You could try using: library(dplyr) library(zoo) na.locf(ts$value[sapply(ts$time, function(x) min(which(ts$time - ...READ MORE

answered May 11, 2018 in Data Analytics by Sahiti
• 6,290 points
219 views
0 votes
1 answer

Different types of seasonality in time series modelling

Seasonality in time series occurs when the ...READ MORE

answered Aug 8, 2018 in Data Analytics by DataKing99
• 8,150 points
563 views
0 votes
1 answer

Building a Time series prediction model on web login timestamp

I had done something similar and ran ...READ MORE

answered Dec 7, 2018 in Data Analytics by Upasana
• 8,590 points
521 views
0 votes
2 answers

What is difference between Distributed search head and Search head cluster?

 A distributed environment describes the separation of ...READ MORE

answered Dec 3, 2018 in Data Analytics by Ali
• 10,670 points
326 views
0 votes
1 answer

Error: “ 'dict' object has no attribute 'iteritems' ”?

Hii, In Python2, dictionary.iteritems() is more efficient than ...READ MORE

answered Apr 13 in Python by Niroj
• 22,110 points
202 views
0 votes
1 answer

Import Error: No module named numpy?

Hello, I had numpy installed on the same ...READ MORE

answered Apr 14 in Python by Niroj
• 22,110 points
330 views