Auto reg

PHOTO EMBED

Thu Jul 22 2021 17:12:37 GMT+0000 (Coordinated Universal Time)

Saved by @Corrydye #python

#Importing AutoReg function to apply AR model
from statsmodels.tsa.ar_model import AutoReg

plt.figure(figsize=(16,8))
model_AR = AutoReg(df_shift, lags=7) #Using number of lags as 7
results_AR = model_AR.fit()
plt.plot(df_shift)
predict = results_AR.predict(start=0,end=len(df_shift)-1)
predict = predict.fillna(0) #Converting NaN values to 0
plt.plot(predict, color='red')
plt.title('AR Model - RMSE: %.4f'% mean_squared_error(predict,df_shift['Close'], squared=False))  #Calculating rmse
plt.show()
content_copyCOPY