from sktime.datasets import load_airline
from sktime.forecasting.model_selection import temporal_train_test_split
y = load_airline() # 144 for 12 years
y_train, y_test = temporal_train_test_split(y, test_size=36) # hold out last 3 years
from sklearn.neighbors import KNeighborsRegressor
from sktime.forecasting.compose import make_reduction
from sktime.performance_metrics.forecasting import mean_absolute_percentage_error
import numpy as np
regressor = KNeighborsRegressor(n_neighbors=1)
forecaster = make_reduction(regressor, window_length=15, strategy="recursive")
forecaster.fit(y_train)
RecursiveTabularRegressionForecaster(estimator=KNeighborsRegressor(n_neighbors=1), window_length=15)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
RecursiveTabularRegressionForecaster(estimator=KNeighborsRegressor(n_neighbors=1), window_length=15)
KNeighborsRegressor(n_neighbors=1)
KNeighborsRegressor(n_neighbors=1)
fh = np.arange(1, 37)
y_pred = forecaster.predict(fh)
from sktime.utils.plotting import plot_series
plot_series(y_train, y_test, y_pred, labels=["y_train", "y_test", "y_pred"])
mean_absolute_percentage_error(y_test, y_pred, symmetric=False)
0.12887507224382988