Skip to content

Instantly share code, notes, and snippets.

Avatar

Lianne & Justin @ Just into Data liannewriting

View GitHub Profile
@liannewriting
liannewriting / prediction_manual_auto_comparison.py
Created Aug 9, 2022
time series prediction arima model python
View prediction_manual_auto_comparison.py
forecast_test_auto = auto_arima.predict(n_periods=len(df_test))
df['forecast_auto'] = [None]*len(df_train) + list(forecast_test_auto)
df.plot()
@liannewriting
liannewriting / evaluation_auto.py
Created Aug 9, 2022
time series prediction arima model python
View evaluation_auto.py
mae = mean_absolute_error(df_test, forecast_test_auto)
mape = mean_absolute_percentage_error(df_test, forecast_test_auto)
rmse = np.sqrt(mean_squared_error(df_test, forecast_test_auto))
print(f'mae - auto: {mae}')
print(f'mape - auto: {mape}')
print(f'rmse - auto: {rmse}')
@liannewriting
liannewriting / evaluation_manual.py
Last active Aug 12, 2022
time series prediction arima model python
View evaluation_manual.py
from sklearn.metrics import mean_absolute_error, mean_absolute_percentage_error, mean_squared_error
mae = mean_absolute_error(df_test, forecast_test)
mape = mean_absolute_percentage_error(df_test, forecast_test)
rmse = np.sqrt(mean_squared_error(df_test, forecast_test))
print(f'mae - manual: {mae}')
print(f'mape - manual: {mape}')
print(f'rmse - manual: {rmse}')
@liannewriting
liannewriting / auto_arima_summary.py
Created Aug 9, 2022
time series prediction arima model python
View auto_arima_summary.py
auto_arima.summary()
@liannewriting
liannewriting / pmdarima_auto_arima.py
Created Aug 9, 2022
time series prediction arima model python
View pmdarima_auto_arima.py
import pmdarima as pm
auto_arima = pm.auto_arima(df_train, stepwise=False, approximation=False, seasonal=False)
auto_arima
@liannewriting
liannewriting / model_manual_forecast.py
Created Aug 9, 2022
time series prediction arima model python
View model_manual_forecast.py
forecast_test = model_fit.forecast(len(df_test))
df['forecast_manual'] = [None]*len(df_train) + list(forecast_test)
df.plot()
@liannewriting
liannewriting / acf_pacf_residuals.py
Created Aug 9, 2022
time series prediction arima model python
View acf_pacf_residuals.py
acf_res = plot_acf(residuals)
pacf_res = plot_pacf(residuals)
@liannewriting
liannewriting / residual_plots.py
Created Aug 9, 2022
time series prediction arima model python
View residual_plots.py
import matplotlib.pyplot as plt
residuals = model_fit.resid[1:]
fig, ax = plt.subplots(1,2)
residuals.plot(title='Residuals', ax=ax[0])
residuals.plot(title='Density', kind='kde', ax=ax[1])
plt.show()
@liannewriting
liannewriting / arima_model_manual.py
Created Aug 9, 2022
time series prediction arima model python
View arima_model_manual.py
from statsmodels.tsa.arima.model import ARIMA
model = ARIMA(df_train, order=(2,1,0))
model_fit = model.fit()
print(model_fit.summary())
@liannewriting
liannewriting / adf_test_difference.py
Created Aug 9, 2022
time series prediction arima model python
View adf_test_difference.py
adf_test = adfuller(df_train_diff)
print(f'p-value: {adf_test[1]}')