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, 2020 in Python by Sharonda
• 150 points
608 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, 2020 by Niroj
• 82,900 points

selected Apr 10, 2020 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
• 58,140 points
3,159 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
• 58,140 points
8,401 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
260 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,360 points
464 views
0 votes
1 answer

Different types of seasonality in time series modelling

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

answered Aug 9, 2018 in Data Analytics by DataKing99
• 8,240 points
1,273 views
+1 vote
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,620 points
919 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 4, 2018 in Data Analytics by Ali
• 11,330 points
859 views
0 votes
1 answer

Error:django-debug-toolbar breaking on admin while getting sql stats

Hello @kartik, You just need to be able ...READ MORE

answered Jun 12, 2020 in Python by Niroj
• 82,900 points
374 views
+1 vote
1 answer

Error:Getting Site Matching Query Does Not Exist Error after creating django admin

Hello @kartik, The Site object for your Django project is ...READ MORE

answered Jun 22, 2020 in Python by Niroj
• 82,900 points
7,210 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP