Last active
October 20, 2019 23:59
-
-
Save brockmanmatt/d20b8118884699763f2215237182140c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from statsmodels.tsa.statespace.sarimax import SARIMAX | |
| def gen_SARIMA_result(p,d,q, df, issue, test_length): #takes pdq, data, issue to use | |
| s_model = SARIMAX(endog = df[issue][:-test_length], | |
| exog = df[[x for x in df.columns if x != issue]][:-test_length], | |
| order=(p,d,q), seasonal_order=(1,0,1,7)).fit() | |
| f_ru = df[[issue]].copy()[1:] #haven't bothered to change this, but it's the results | |
| f_ru.columns = ["actual"] #renames the actual values actual | |
| f_ru["predicted"] = s_model.predict(end=time_series.index.max(), endog = df[[issue]][-test_length:],exog = df[[x for x in selected_series.columns if x != issue]][-test_length:], | |
| dynamic= False) #predicts future values (1 step) | |
| f_ru["error"] = np.abs((f_ru["actual"] - f_ru["predicted"]) / f_ru["actual"]) #labels each with the % error | |
| return f_ru, s_model.aic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment