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
test_len = int(len(ts_nl) * 0.3) | |
nl_train, nl_test = ts_nl.iloc[:-test_len], ts_nl.iloc[-test_len:] | |
forecaster = AutoARIMA(suppress_warnings=True) | |
forecaster.fit(nl_train) | |
forecaster.summary() |
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
fh = np.arange(test_len) + 1 | |
forecast = forecaster.predict(fh=fh) | |
forecast_int = forecaster.predict_interval(fh=fh, coverage=coverage)['Coverage'][coverage] | |
nl_arima_mae, nl_arima_mape = plot_forecast(nl_train, nl_test, forecast, forecast_int) |
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
param_grid = {"window_length": [5, 10, 15, 20, 25, 30]} | |
forecaster = create_forecaster() | |
nl_lgb_mae, nl_lgb_mape = grid_serch_forecaster(nl_train, nl_test, forecaster, param_grid) |
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
import requests | |
from io import BytesIO | |
wpi1 = requests.get("https://www.stata-press.com/data/r12/wpi1.dta").content | |
data = pd.read_stata(BytesIO(wpi1)) | |
ts_wpi = data.set_index("t").wpi | |
tsplot(ts_wpi) |
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
ts_wpi_diff = (ts_wpi - ts_wpi.shift(1)).dropna() | |
tsplot(ts_wpi_diff) |
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
ts_wpi_2diff = (ts_wpi_diff - ts_wpi_diff.shift(1)).dropna() | |
tsplot(ts_wpi_2diff) |
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
ts_wpi.index = ts_wpi.index.to_period("Q") | |
test_len = int(len(ts_wpi) * 0.25) | |
wpi_train, wpi_test = ts_wpi.iloc[:-test_len], ts_wpi.iloc[-test_len:] | |
forecaster = AutoARIMA(suppress_warnings=True) | |
forecaster.fit(wpi_train) | |
forecaster.summary() |
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
fh = np.arange(test_len) + 1 | |
forecast = forecaster.predict(fh=fh) | |
forecast_int = forecaster.predict_interval(fh=fh, coverage=coverage)['Coverage'][coverage] | |
wpi_arima_mae, wpi_arima_mape = plot_forecast( | |
wpi_train, wpi_test, forecast, forecast_int | |
) |
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
param_grid = {"window_length": [5, 10, 15, 20, 25, 30]} | |
forecaster = create_forecaster() | |
wpi_lgb_mae, wpi_lgb_mape = grid_serch_forecaster( | |
wpi_train, wpi_test, forecaster, param_grid | |
) |
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 sktime.forecasting.trend import PolynomialTrendForecaster | |
from sktime.transformations.series.detrend import Detrender | |
# linear detrending | |
forecaster = PolynomialTrendForecaster(degree=1) | |
transformer = Detrender(forecaster=forecaster) | |
yt = transformer.fit_transform(wpi_train) | |
forecaster = PolynomialTrendForecaster(degree=1) | |
fh_ins = -np.arange(len(wpi_train)) # in-sample forecasting horizon |