Skip to content

Instantly share code, notes, and snippets.

@brockmanmatt
Created October 11, 2019 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brockmanmatt/89cfc8be582222567a124895fe7b414b to your computer and use it in GitHub Desktop.
Save brockmanmatt/89cfc8be582222567a124895fe7b414b to your computer and use it in GitHub Desktop.
fig, axs = plt.subplots(4, 5, sharex=True)
fig.set_size_inches(16,12)
x = y = 0
for issue in time_series:
train_l = 55
s_model = SARIMAX(endog = time_series[[issue]][:train_l][1:],
exog = time_series[[x for x in time_series.columns if x != issue]][:train_l].shift().add_suffix("_l1")[1:],
order=(2,0,1), seasonal_order=(1,0,1,7)).fit()
f_ru = time_series[[issue]].copy()[1:]
f_ru.columns = ["actual"]
f_ru["predicted"] = s_model.predict(end=datetime.datetime(2019, 10, 6), endog = time_series[[issue]][-5:],exog = time_series[[x for x in time_series.columns if x != issue]].shift()[-5:],
dynamic= False)
testing = f_ru[-5:].copy()
f_ru["actual"].plot(title="{}\nRMSE {}".format(issue, sqrt(mean_squared_error(testing.actual, testing.predicted))), ax=axs[x,y])
f_ru["predicted"][:-5].plot(color="orange", label="predicted: Train", ax=axs[x,y])
f_ru["predicted"][-6:].plot(color="red", label="predicted: Test", ax=axs[x,y])
x+=1
if x > 3:
x =0
y+=1
handles, labels = axs[0,0].get_legend_handles_labels()
fig.legend(handles, labels, loc='center right')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment