Last active
March 10, 2023 06:38
-
-
Save tomonori-masui/0f6fc07571a24de27d771bd50521ca74 to your computer and use it in GitHub Desktop.
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 make_reduction, TransformedTargetForecaster | |
from sktime.forecasting.model_selection import ExpandingWindowSplitter, ForecastingGridSearchCV | |
from sktime.performance_metrics.forecasting import MeanAbsolutePercentageError | |
import lightgbm as lgb | |
def create_forecaster(): | |
# creating forecaster with LightGBM | |
regressor = lgb.LGBMRegressor() | |
forecaster = make_reduction(regressor, window_length=5, strategy="recursive") | |
return forecaster | |
def grid_serch_forecaster(train, test, forecaster, param_grid): | |
# Grid search on window_length | |
cv = ExpandingWindowSplitter(initial_window=int(len(train) * 0.7)) | |
gscv = ForecastingGridSearchCV( | |
forecaster, strategy="refit", cv=cv, param_grid=param_grid, | |
scoring=MeanAbsolutePercentageError(symmetric=True) | |
) | |
gscv.fit(train) | |
print(f"best params: {gscv.best_params_}") | |
# forecasting | |
fh = np.arange(len(test)) + 1 | |
y_pred = gscv.predict(fh=fh) | |
mae, mape = plot_forecast(train, test, y_pred) | |
return mae, mape | |
param_grid = { | |
"window_length": [5, 10, 15, 20, 25, 30] # parameter set to be grid searched | |
} | |
forecaster = create_forecaster() | |
sun_lgb_mae, sun_lgb_mape = grid_serch_forecaster( | |
sun_train, sun_test, forecaster, param_grid | |
) |
Thanks for your quick response. I have been following your online material but couldn't find anywhere freq being explicitly being fed into input series.
https://towardsdatascience.com/multi-step-time-series-forecasting-with-arima-lightgbm-and-prophet-cc9e3f95dfb0
I was looking at the code nile data set code.
The way I have my input data is where freq should be auto detected, right? df = pd.read_csv('uniques_pv_imps.csv', index_col = [0], parse_dates = True)
On Monday, 20 September, 2021, 08:54:24 pm GMT-4, Tomonori Masui ***@***.***> wrote:
@tomonori-masui commented on this gist.
@hiteshgupta2507 Your input series needs to be indexed with the right frequency. Possible frequencies can be seen in this link.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
I have been following your online material but couldn't find anywhere freq being explicitly being fed into input series.
Only the WPI data have that conversion in that blog post.
I was looking at the code nile data set code.
Nile dataset is not indexed with datetime values. It just has numeric values of years, hence it does not require frequency on its index.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@hiteshgupta2507 Your input series needs to be indexed with the right frequency. Possible frequencies can be seen in this link.