Last active
February 13, 2023 14:13
-
-
Save Mr-Geekman/d8ab3ba3f4c0c410a2d534f7771ab046 to your computer and use it in GitHub Desktop.
This file contains 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
def get_metrics_by_horizon(ts: TSDataset, horizon: int, total_points: int): | |
if total_points % horizon != 0: | |
raise ValueError("Horizon should divide total number of points!") | |
n_folds = total_points // horizon | |
transforms = [ | |
LagTransform( | |
in_column="target", | |
lags=list(range(horizon, MAX_LAG)), | |
out_column="lag_target", | |
), | |
SegmentEncoderTransform(), | |
] | |
model = CatBoostMultiSegmentModel() | |
pipeline = Pipeline(model=model, transforms=transforms, horizon=horizon) | |
start_time = time.perf_counter() | |
metrics_df, forecast_df, fold_info_df = pipeline.backtest( | |
ts=ts, metrics=[SMAPE()], n_folds=n_folds | |
) | |
elapsed_time = time.perf_counter() - start_time | |
smape_value = metrics_df.mean().to_dict()["SMAPE"] | |
return {"SMAPE": smape_value, "time": elapsed_time} | |
horizon_values = [24, 12, 6, 4, 3, 2, 1] | |
horizon_results = [] | |
for horizon in horizon_values: | |
cur_res = get_metrics_by_horizon( | |
ts=ts, horizon=horizon, total_points=HORIZON * N_FOLDS | |
) | |
horizon_results.append({"horizon": horizon, **cur_res}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment