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_al_2diff = (ts_al_diff - ts_al_diff.shift(1)).dropna() | |
| tsplot(ts_al_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_al_diff = (ts_al - ts_al.shift(12)).dropna() | |
| tsplot(ts_al_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
| from sktime.datasets import load_airline | |
| ts_al = load_airline() | |
| tsplot(ts_al) |
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.compose import TransformedTargetForecaster | |
| def create_forecaster_w_detrender(degree=1): | |
| # creating forecaster with LightGBM | |
| regressor = lgb.LGBMRegressor() | |
| forecaster = TransformedTargetForecaster( | |
| [ | |
| ("detrend", Detrender(forecaster=PolynomialTrendForecaster(degree=degree))), | |
| ( |
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 |
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
| 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
| 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
| 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_diff = (ts_wpi - ts_wpi.shift(1)).dropna() | |
| tsplot(ts_wpi_diff) |