1

I have dataset with dates and random values. The following code is generating the dataset.

def random_dates(start, end, n=10):
        start_u = start.value//10**9
        end_u = end.value//10**9
        return pd.DatetimeIndex((10**9*np.random.randint(start_u, end_u, n)))

    start = pd.to_datetime('2017-01-01')
    end = pd.to_datetime('2018-01-12')

    days = random_dates(start, end)

    np.random.seed(seed=1111)
    data = np.random.randint(1, high=100, size=len(days))
    df = pd.DataFrame({'Date': days, 'values': data})
    df = df.set_index('Date')
    print(df)

The original Dataset I am trying to implement ARIMA timeseries model on the dataset to predict for November, 2018 to December, 2018. From the dataset image it can be seen that I put zeros for the dates where I need to predict the values.

I code below is to do prediction. However, I am getting error at line:2 start of get_prediction is not able to get assigned to the date value of dataframe that I want. TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'

start = pd.to_datetime("2018-01-10")
pred = results.get_prediction(start, dynamic=False)
pred_ci = pred.conf_int()
ax = tc.plot(label='observed')
pred.predicted_mean.plot(ax=ax, label='One-step ahead Forecast', alpha=.7, figsize=(14, 7))
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('TC')
plt.legend()
plt.show()

I tried to change the date-index to string but it is giving the same error. Kindly tell me where I went wrong. Thanks

1 Answer 1

0

I think this is the result of a bug in Statsmodels that was only recently fixed (https://github.com/statsmodels/statsmodels/pull/5250).

In the meantime, you might try the following (assuming your data is in the variable df)

start = df.index.get_loc(pd.to_datetime("2018-01-10"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.