Skip to content

Instantly share code, notes, and snippets.

@tomonori-masui
Last active July 3, 2021 18:30
Show Gist options
  • Save tomonori-masui/1d99b4487343e3386fe12a03c9053718 to your computer and use it in GitHub Desktop.
Save tomonori-masui/1d99b4487343e3386fe12a03c9053718 to your computer and use it in GitHub Desktop.
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
y_pred = forecaster.fit(wpi_train).predict(fh=fh_ins)
plot_series(
wpi_train, y_pred, yt, labels=["y_train", "fitted linear trend", "residuals"]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment