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
measure_mae(reconcilied_preds) |
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
plot_forecast_sums(reconcilied_preds) |
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
reconciliator = MinTReconciliator(method="wls_val") | |
reconciliator.fit(train) | |
reconcilied_preds = reconciliator.transform(pred) |
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 plot_forecast_sums(pred_series): | |
plt.figure(figsize=(10, 5)) | |
pred_series["Total"].plot(label="total", lw=6, alpha=0.3, color="grey") | |
sum([pred_series[r] for r in regions]).plot(label="sum of regions") | |
sum([pred_series[r] for r in reasons]).plot(label="sum of reasons") | |
sum([pred_series[t] for t in regions_reasons_comps]).plot( | |
label="sum of (region, reason) series" | |
) | |
sum([pred_series[t] for t in regions_reasons_city_comps]).plot( |
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
# we pre-generate some of the components' names | |
regions_reasons_comps = list( | |
map(lambda t: "{} - {}".format(t[0], t[1].lower()), product(regions, reasons)) | |
) | |
regions_reasons_city_comps = list( | |
map( | |
lambda t: "{} - {} - {}".format(t[0], t[1].lower(), t[2]), | |
product(regions, reasons, city_labels), | |
) |
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
components_to_show = ["Total", "NSW", "NSW - bus", "NSW - hol", "NSW - bus - city"] | |
plt.figure(figsize=(14, 8)) | |
tourism_series[components_to_show].plot(lw=5) | |
pred[components_to_show].plot(lw=2) |
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
model = LinearRegressionModel(lags=12) | |
model.fit(train) | |
pred = model.predict(n=len(val)) |
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
train, val = tourism_series[:-12], tourism_series[-12:] |
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
tourism_series = tourism_series.with_hierarchy(hierarchy) |
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
for component in ["Hol", "NSW - hol", "NSW - bus - city"]: | |
print(f"{component} -> {hierarchy[component]}") |
NewerOlder