Note
Click here to download the full example code
Simple Forecast¶
You can create and evaluate a forecast with just a few lines of code.
Provide your timeseries as a pandas dataframe with timestamp and value.
For example, to forecast daily sessions data, your dataframe could look like this:
import pandas as pd
df = pd.DataFrame({
"date": ["2020-01-08-00", "2020-01-09-00", "2020-01-10-00"],
"sessions": [10231.0, 12309.0, 12104.0]
})
The time column can be any format recognized by pandas.to_datetime
.
In this example, we’ll load a dataset representing log(daily page views)
on the Wikipedia page for Peyton Manning.
It contains values from 2007-12-10 to 2016-01-20. More dataset info
here.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | from collections import defaultdict
import warnings
warnings.filterwarnings("ignore")
import pandas as pd
import plotly
from greykite.common.data_loader import DataLoader
from greykite.framework.templates.autogen.forecast_config import ForecastConfig
from greykite.framework.templates.autogen.forecast_config import MetadataParam
from greykite.framework.templates.forecaster import Forecaster
from greykite.framework.templates.model_templates import ModelTemplateEnum
from greykite.framework.utils.result_summary import summarize_grid_search_results
# Loads dataset into pandas DataFrame
dl = DataLoader()
df = dl.load_peyton_manning()
# specify dataset information
metadata = MetadataParam(
time_col="ts", # name of the time column ("date" in example above)
value_col="y", # name of the value column ("sessions" in example above)
freq="D" # "H" for hourly, "D" for daily, "W" for weekly, etc.
# Any format accepted by `pandas.date_range`
)
|
Create a forecast¶
You can choose from many available models (see Choose a Model).
In this example, we choose the “AUTO” model template, which uses the Silverkite algorithm with automatic parameter configuration given the input data frequency, forecast horizon and evaluation configs. We recommend starting with the “AUTO” template for most use cases.
64 65 66 67 68 69 70 71 72 73 | forecaster = Forecaster() # Creates forecasts and stores the result
result = forecaster.run_forecast_config( # result is also stored as `forecaster.forecast_result`.
df=df,
config=ForecastConfig(
model_template=ModelTemplateEnum.AUTO.name,
forecast_horizon=365, # forecasts 365 steps ahead
coverage=0.95, # 95% prediction intervals
metadata_param=metadata
)
)
|
Out:
Fitting 3 folds for each of 1 candidates, totalling 3 fits
Check results¶
The output of run_forecast_config
is a dictionary that contains
the future forecast, historical forecast performance, and
the original timeseries.
Timeseries¶
Let’s plot the original timeseries.
run_forecast_config
returns this as ts
.
(The interactive plot is generated by plotly
: click to zoom!)
89 90 91 | ts = result.timeseries
fig = ts.plot()
plotly.io.show(fig)
|
Cross-validation¶
By default, run_forecast_config
provides historical evaluation,
so you can see how the forecast performs on past data.
This is stored in grid_search
(cross-validation splits)
and backtest
(holdout test set).
Let’s check the cross-validation results.
By default, all metrics in ElementwiseEvaluationMetricEnum
are computed on each CV train/test split.
The configuration of CV evaluation metrics can be found at
Evaluation Metric.
Below, we show the Mean Absolute Percentage Error (MAPE)
across splits (see summarize_grid_search_results
to control what to show and for details on the output columns).
109 110 111 112 113 114 115 116 117 118 119 | grid_search = result.grid_search
cv_results = summarize_grid_search_results(
grid_search=grid_search,
decimals=2,
# The below saves space in the printed output. Remove to show all available metrics and columns.
cv_report_metrics=None,
column_order=["rank", "mean_test", "split_test", "mean_train", "split_train", "mean_fit_time", "mean_score_time", "params"])
# Transposes to save space in the printed output
cv_results["params"] = cv_results["params"].astype(str)
cv_results.set_index("params", drop=True, inplace=True)
cv_results.transpose()
|
Backtest¶
Let’s plot the historical forecast on the holdout test set. You can zoom in to see how it performed in any given period.
126 127 128 | backtest = result.backtest
fig = backtest.plot()
plotly.io.show(fig)
|
You can also check historical evaluation metrics (on the historical training/test set).
132 133 134 135 136 137 | backtest_eval = defaultdict(list)
for metric, value in backtest.train_evaluation.items():
backtest_eval[metric].append(value)
backtest_eval[metric].append(backtest.test_evaluation[metric])
metrics = pd.DataFrame(backtest_eval, index=["train", "test"]).T
metrics
|
Forecast¶
The forecast
attribute contains the forecasted result.
Just as for backtest
, you can plot the result or
see the evaluation metrics.
Let’s plot the forecast (trained on all data):
147 148 149 | forecast = result.forecast
fig = forecast.plot()
plotly.io.show(fig)
|
The forecasted values are available in df
.
153 | forecast.df.head().round(2)
|
Model Diagnostics¶
The component plot shows how your dataset’s trend, seasonality, and event / holiday patterns are handled in the model:
160 161 | fig = forecast.plot_components()
plotly.io.show(fig) # fig.show() if you are using "PROPHET" template
|
Model summary allows inspection of individual model terms. Check parameter estimates and their significance for insights on how the model works and what can be further improved.
167 168 | summary = result.model[-1].summary() # -1 retrieves the estimator from the pipeline
print(summary)
|
Out:
================================ Model Summary =================================
Number of observations: 2964, Number of features: 280
Method: Ordinary least squares
Number of nonzero features: 280
Residuals:
Min 1Q Median 3Q Max
-2.281 -0.2714 -0.04397 0.189 3.488
Pred_col Estimate Std. Err t value Pr(>|t|) sig. code 95%CI
Intercept 0.7319 0.02149 34.05 <2e-16 *** (0.6897, 0.774)
events_C...New Year 0.09733 0.1695 0.5741 0.566 (-0.2351, 0.4298)
events_C...w Year-1 -0.106 0.185 -0.5728 0.567 (-0.4688, 0.2569)
events_C...w Year-2 0.07634 0.1485 0.5141 0.607 (-0.2148, 0.3675)
events_C...w Year+1 0.06614 0.185 0.3576 0.721 (-0.2966, 0.4289)
events_C...w Year+2 0.1728 0.1483 1.165 0.244 (-0.1181, 0.4636)
events_Christmas Day -0.534 0.1749 -3.052 0.002 ** (-0.877, -0.191)
events_C...as Day-1 -0.2845 0.1744 -1.632 0.103 (-0.6264, 0.05736)
events_C...as Day-2 -0.07261 0.1728 -0.4203 0.674 (-0.4114, 0.2662)
events_C...as Day+1 -0.3222 0.1752 -1.839 0.066 . (-0.6657, 0.02137)
events_C...as Day+2 0.1834 0.1745 1.051 0.293 (-0.1588, 0.5257)
events_E...Ireland] -0.3061 0.1739 -1.76 0.079 . (-0.647, 0.03492)
events_E...eland]-1 -0.1366 0.08696 -1.571 0.116 (-0.3071, 0.03393)
events_E...eland]-2 -0.06412 0.08796 -0.729 0.466 (-0.2366, 0.1083)
events_E...eland]+1 -0.1255 0.1738 -0.7222 0.470 (-0.4662, 0.2152)
events_E...eland]+2 -0.01897 0.1722 -0.1102 0.912 (-0.3566, 0.3187)
events_Good Friday -0.1965 0.1746 -1.126 0.260 (-0.5388, 0.1458)
events_Good Friday-1 -0.1179 0.1725 -0.6832 0.495 (-0.4562, 0.2204)
events_Good Friday-2 -0.03078 0.1728 -0.1782 0.859 (-0.3696, 0.308)
events_Good Friday+1 -0.06412 0.08796 -0.729 0.466 (-0.2366, 0.1083)
events_Good Friday+2 -0.1366 0.08696 -1.571 0.116 (-0.3071, 0.03393)
events_I...ence Day 0.07124 0.1246 0.5718 0.567 (-0.173, 0.3155)
events_I...ce Day-1 0.02882 0.1245 0.2316 0.817 (-0.2153, 0.2729)
events_I...ce Day-2 -0.04493 0.1245 -0.361 0.718 (-0.289, 0.1991)
events_I...ce Day+1 -0.02854 0.1246 -0.229 0.819 (-0.2729, 0.2158)
events_I...ce Day+2 -0.04005 0.1244 -0.3219 0.748 (-0.284, 0.2039)
events_Labor Day -0.3448 0.1236 -2.789 0.005 ** (-0.5872, -0.1024)
events_Labor Day-1 -0.1292 0.1237 -1.045 0.296 (-0.3717, 0.1133)
events_Labor Day-2 -0.05051 0.1236 -0.4086 0.683 (-0.2929, 0.1919)
events_Labor Day+1 -0.2525 0.1236 -2.042 0.041 * (-0.4949, -0.01009)
events_Labor Day+2 -0.2622 0.1235 -2.123 0.034 * (-0.5045, -0.02)
events_Memorial Day -0.361 0.1749 -2.064 0.039 * (-0.7039, -0.01809)
events_M...al Day-1 -0.189 0.1748 -1.081 0.280 (-0.5319, 0.1538)
events_M...al Day-2 0.05543 0.1746 0.3174 0.751 (-0.287, 0.3978)
events_M...al Day+1 0.02993 0.1749 0.1711 0.864 (-0.3131, 0.3729)
events_M...al Day+2 0.3327 0.1749 1.902 0.057 . (-0.01028, 0.6757)
events_New Years Day -0.1038 0.1741 -0.5959 0.551 (-0.4452, 0.2377)
events_N...rs Day-1 0.1337 0.1749 0.7646 0.445 (-0.2092, 0.4767)
events_N...rs Day-2 0.3789 0.1741 2.176 0.030 * (0.03752, 0.7203)
events_N...rs Day+1 0.3026 0.1723 1.756 0.079 . (-0.03534, 0.6405)
events_N...rs Day+2 0.3653 0.1712 2.133 0.033 * (0.02954, 0.7011)
events_Other 0.003788 0.03055 0.124 0.901 (-0.05611, 0.06369)
events_Other-1 0.005232 0.03019 0.1733 0.862 (-0.05397, 0.06443)
events_Other-2 0.02152 0.02982 0.7219 0.470 (-0.03694, 0.07999)
events_Other+1 0.004162 0.03054 0.1363 0.892 (-0.05571, 0.06404)
events_Other+2 -0.007009 0.02984 -0.2349 0.814 (-0.06552, 0.0515)
events_Thanksgiving -0.1684 0.1762 -0.9561 0.339 (-0.5139, 0.177)
events_T...giving-1 -0.3583 0.1761 -2.035 0.042 * (-0.7035, -0.01306)
events_T...giving-2 -0.2163 0.1761 -1.229 0.219 (-0.5616, 0.1289)
events_T...giving+1 -0.06876 0.176 -0.3908 0.696 (-0.4138, 0.2763)
events_T...giving+2 -0.1409 0.1757 -0.8019 0.423 (-0.4853, 0.2036)
events_Veterans Day -0.1375 0.1802 -0.7631 0.445 (-0.4909, 0.2159)
events_V...ns Day-1 -0.1892 0.1797 -1.053 0.292 (-0.5415, 0.163)
events_V...ns Day-2 -0.1695 0.1791 -0.9464 0.344 (-0.5207, 0.1817)
events_V...ns Day+1 -0.1225 0.1804 -0.6789 0.497 (-0.4761, 0.2312)
events_V...ns Day+2 -0.1904 0.1803 -1.056 0.291 (-0.544, 0.1631)
str_dow_2-Tue -0.06023 0.1392 -0.4328 0.665 (-0.3331, 0.2127)
str_dow_3-Wed -0.01674 0.1423 -0.1176 0.906 (-0.2958, 0.2623)
str_dow_4-Thu -0.2368 0.1448 -1.635 0.102 (-0.5207, 0.04718)
str_dow_5-Fri -0.125 0.1487 -0.8408 0.401 (-0.4166, 0.1665)
str_dow_6-Sat -0.2565 0.1509 -1.7 0.089 . (-0.5523, 0.03941)
str_dow_7-Sun 0.7552 0.1629 4.636 3.71e-06 *** (0.4358, 1.075)
ct1 26.65 8.076 3.3 9.80e-04 *** (10.81, 42.49)
is_weekend:ct1 -2.428 8.0 -0.3035 0.762 (-18.11, 13.26)
str_dow_2-Tue:ct1 10.07 15.61 0.6451 0.519 (-20.53, 40.67)
str_dow_3-Wed:ct1 10.48 12.15 0.863 0.388 (-13.34, 34.3)
str_dow_4-Thu:ct1 25.73 13.4 1.919 0.055 . (-0.5541, 52.01)
str_dow_5-Fri:ct1 15.85 13.55 1.17 0.242 (-10.72, 42.41)
str_dow_6-Sat:ct1 15.63 12.9 1.212 0.226 (-9.659, 40.93)
str_dow_7-Sun:ct1 -18.06 14.77 -1.223 0.222 (-47.02, 10.9)
cp0_2008_02_04_00 -32.88 8.75 -3.757 1.75e-04 *** (-50.03, -15.72)
is_weeke...02_04_00 3.787 8.603 0.4402 0.660 (-13.08, 20.66)
str_dow_...02_04_00 -9.491 16.91 -0.5612 0.575 (-42.66, 23.67)
str_dow_...02_04_00 -11.64 13.14 -0.886 0.376 (-37.4, 14.12)
str_dow_...02_04_00 -25.01 14.47 -1.729 0.084 . (-53.37, 3.354)
str_dow_...02_04_00 -14.89 14.61 -1.019 0.308 (-43.54, 13.76)
str_dow_...02_04_00 -14.93 13.86 -1.077 0.281 (-42.11, 12.25)
str_dow_...02_04_00 18.71 15.86 1.18 0.238 (-12.39, 49.82)
cp1_2008_09_15_00 -27.54 12.05 -2.285 0.022 * (-51.17, -3.904)
is_weeke...09_15_00 -13.3 11.02 -1.207 0.227 (-34.9, 8.3)
str_dow_...09_15_00 0.6347 23.2 0.02736 0.978 (-44.86, 46.13)
str_dow_...09_15_00 -13.0 17.73 -0.7334 0.463 (-47.77, 21.76)
str_dow_...09_15_00 -29.56 19.26 -1.535 0.125 (-67.34, 8.212)
str_dow_...09_15_00 -28.67 19.12 -1.499 0.134 (-66.17, 8.828)
str_dow_...09_15_00 -25.19 17.66 -1.427 0.154 (-59.81, 9.433)
str_dow_...09_15_00 11.88 20.16 0.5891 0.556 (-27.66, 51.42)
cp2_2008_10_13_00 39.01 13.91 2.804 0.005 ** (11.73, 66.29)
is_weeke...10_13_00 15.3 12.67 1.207 0.228 (-9.554, 40.15)
str_dow_...10_13_00 -5.822 26.72 -0.2179 0.828 (-58.21, 46.57)
str_dow_...10_13_00 18.4 20.4 0.9019 0.367 (-21.6, 58.41)
str_dow_...10_13_00 36.38 22.17 1.641 0.101 (-7.101, 79.86)
str_dow_...10_13_00 36.67 22.0 1.667 0.096 . (-6.463, 79.81)
str_dow_...10_13_00 29.5 20.3 1.453 0.146 (-10.31, 69.31)
str_dow_...10_13_00 -14.19 23.19 -0.612 0.541 (-59.67, 31.28)
cp3_2009_01_12_00 0.7728 4.072 0.1898 0.849 (-7.211, 8.757)
is_weeke...01_12_00 -2.217 3.65 -0.6074 0.544 (-9.374, 4.94)
str_dow_...01_12_00 6.299 7.696 0.8186 0.413 (-8.79, 21.39)
str_dow_...01_12_00 -2.401 5.859 -0.4097 0.682 (-13.89, 9.088)
str_dow_...01_12_00 -6.191 6.37 -0.9718 0.331 (-18.68, 6.3)
str_dow_...01_12_00 -8.485 6.329 -1.341 0.180 (-20.9, 3.925)
str_dow_...01_12_00 -3.412 5.841 -0.5842 0.559 (-14.87, 8.041)
str_dow_...01_12_00 1.194 6.669 0.1791 0.858 (-11.88, 14.27)
cp4_2009_09_14_00 -6.074 3.237 -1.877 0.061 . (-12.42, 0.2723)
is_weeke...09_14_00 1.092 2.894 0.3773 0.706 (-4.583, 6.766)
str_dow_...09_14_00 -6.745 6.047 -1.115 0.265 (-18.6, 5.112)
str_dow_...09_14_00 -5.829 4.628 -1.26 0.208 (-14.9, 3.246)
str_dow_...09_14_00 -5.848 5.035 -1.162 0.246 (-15.72, 4.024)
str_dow_...09_14_00 -1.054 5.004 -0.2106 0.833 (-10.87, 8.758)
str_dow_...09_14_00 -3.825 4.617 -0.8285 0.407 (-12.88, 5.228)
str_dow_...09_14_00 4.915 5.267 0.9332 0.351 (-5.412, 15.24)
cp5_2009_12_28_00 9.13 10.42 0.8758 0.381 (-11.31, 29.57)
is_weeke...12_28_00 2.522 9.373 0.2691 0.788 (-15.86, 20.9)
str_dow_...12_28_00 19.67 19.6 1.003 0.316 (-18.77, 58.1)
str_dow_...12_28_00 19.73 15.1 1.307 0.191 (-9.874, 49.33)
str_dow_...12_28_00 29.92 16.39 1.825 0.068 . (-2.228, 62.07)
str_dow_...12_28_00 15.19 16.3 0.9316 0.352 (-16.78, 47.15)
str_dow_...12_28_00 16.98 15.0 1.131 0.258 (-12.44, 46.4)
str_dow_...12_28_00 -14.45 17.08 -0.846 0.398 (-47.93, 19.04)
cp6_2010_01_25_00 -10.58 8.524 -1.242 0.214 (-27.3, 6.131)
is_weeke...01_25_00 -3.673 7.689 -0.4777 0.633 (-18.75, 11.4)
str_dow_...01_25_00 -15.66 16.1 -0.9722 0.331 (-47.23, 15.92)
str_dow_...01_25_00 -15.6 12.38 -1.26 0.208 (-39.88, 8.678)
str_dow_...01_25_00 -25.0 13.45 -1.86 0.063 . (-51.37, 1.362)
str_dow_...01_25_00 -14.67 13.37 -1.097 0.273 (-40.9, 11.55)
str_dow_...01_25_00 -14.65 12.31 -1.19 0.234 (-38.78, 9.485)
str_dow_...01_25_00 10.97 14.01 0.7829 0.434 (-16.5, 38.44)
cp7_2011_01_31_00 5.134 1.228 4.182 2.98e-05 *** (2.727, 7.541)
is_weeke...01_31_00 2.207 1.128 1.956 0.051 . (-0.005418, 4.42)
str_dow_...01_31_00 0.3355 2.381 0.1409 0.888 (-4.333, 5.004)
str_dow_...01_31_00 2.499 1.806 1.384 0.167 (-1.042, 6.04)
str_dow_...01_31_00 4.297 1.962 2.19 0.029 * (0.4497, 8.143)
str_dow_...01_31_00 3.481 1.955 1.78 0.075 . (-0.3531, 7.315)
str_dow_...01_31_00 3.042 1.81 1.68 0.093 . (-0.5075, 6.591)
str_dow_...01_31_00 -0.8328 2.067 -0.4028 0.687 (-4.887, 3.221)
cp8_2011_07_18_00 -8.517 2.895 -2.942 0.003 ** (-14.19, -2.84)
is_weeke...07_18_00 -2.912 2.623 -1.11 0.267 (-8.055, 2.23)
str_dow_...07_18_00 0.8226 5.542 0.1484 0.882 (-10.04, 11.69)
str_dow_...07_18_00 -6.862 4.214 -1.628 0.104 (-15.13, 1.401)
str_dow_...07_18_00 -10.52 4.566 -2.303 0.021 * (-19.47, -1.565)
str_dow_...07_18_00 -10.34 4.542 -2.277 0.023 * (-19.25, -1.438)
str_dow_...07_18_00 -5.775 4.207 -1.373 0.170 (-14.02, 2.475)
str_dow_...07_18_00 2.859 4.806 0.5949 0.552 (-6.564, 12.28)
cp9_2011_10_17_00 17.98 10.95 1.642 0.101 (-3.486, 39.44)
is_weeke...10_17_00 0.985 10.13 0.09722 0.923 (-18.88, 20.85)
str_dow_...10_17_00 -10.96 21.2 -0.5171 0.605 (-52.53, 30.61)
str_dow_...10_17_00 14.47 16.42 0.8815 0.378 (-17.72, 46.67)
str_dow_...10_17_00 11.74 17.87 0.6572 0.511 (-23.3, 46.78)
str_dow_...10_17_00 25.72 17.78 1.447 0.148 (-9.145, 60.59)
str_dow_...10_17_00 0.1971 16.38 0.01204 0.990 (-31.91, 32.31)
str_dow_...10_17_00 0.788 18.53 0.04252 0.966 (-35.55, 37.13)
cp10_2011_11_14_00 -35.9 17.82 -2.015 0.044 * (-70.85, -0.9589)
is_weeke...11_14_00 -3.007 16.63 -0.1808 0.857 (-35.61, 29.59)
str_dow_...11_14_00 15.44 34.63 0.4459 0.656 (-52.47, 83.35)
str_dow_...11_14_00 -13.23 26.95 -0.4909 0.624 (-66.08, 39.62)
str_dow_...11_14_00 -1.855 29.38 -0.06313 0.950 (-59.46, 55.75)
str_dow_...11_14_00 -45.5 29.29 -1.553 0.120 (-102.9, 11.94)
str_dow_...11_14_00 -3.15 26.91 -0.1171 0.907 (-55.92, 49.62)
str_dow_...11_14_00 0.1417 30.37 0.004667 0.996 (-59.41, 59.69)
cp11_2011_12_12_00 48.6 11.86 4.096 4.33e-05 *** (25.33, 71.86)
is_weeke...12_12_00 7.795 11.0 0.7085 0.479 (-13.78, 29.37)
str_dow_...12_12_00 -5.229 23.0 -0.2274 0.820 (-50.33, 39.87)
str_dow_...12_12_00 11.36 17.7 0.6417 0.521 (-23.35, 46.06)
str_dow_...12_12_00 2.627 19.29 0.1362 0.892 (-35.2, 40.45)
str_dow_...12_12_00 41.48 19.32 2.147 0.032 * (3.605, 79.36)
str_dow_...12_12_00 15.02 17.76 0.8458 0.398 (-19.81, 49.86)
str_dow_...12_12_00 -7.22 20.12 -0.3588 0.720 (-46.67, 32.23)
cp12_2012_02_13_00 -29.87 2.967 -10.07 <2e-16 *** (-35.69, -24.05)
is_weeke...02_13_00 -3.507 2.711 -1.294 0.196 (-8.823, 1.809)
str_dow_...02_13_00 -1.226 5.718 -0.2144 0.830 (-12.44, 9.987)
str_dow_...02_13_00 -8.278 4.335 -1.909 0.056 . (-16.78, 0.2227)
str_dow_...02_13_00 -5.512 4.715 -1.169 0.243 (-14.76, 3.733)
str_dow_...02_13_00 -14.23 4.727 -3.011 0.003 ** (-23.5, -4.966)
str_dow_...02_13_00 -8.728 4.359 -2.002 0.045 * (-17.28, -0.1807)
str_dow_...02_13_00 5.215 4.97 1.049 0.294 (-4.53, 14.96)
cp13_2013_02_04_00 3.984 0.3473 11.47 <2e-16 *** (3.303, 4.665)
is_weeke...02_04_00 0.06742 0.3273 0.206 0.837 (-0.5743, 0.7092)
str_dow_...02_04_00 0.1168 0.694 0.1683 0.866 (-1.244, 1.478)
str_dow_...02_04_00 1.471 0.5263 2.795 0.005 ** (0.439, 2.503)
str_dow_...02_04_00 1.011 0.5719 1.768 0.077 . (-0.11, 2.133)
str_dow_...02_04_00 0.6043 0.568 1.064 0.287 (-0.5095, 1.718)
str_dow_...02_04_00 0.687 0.524 1.311 0.190 (-0.3405, 1.715)
str_dow_...02_04_00 -0.619 0.6004 -1.031 0.303 (-1.796, 0.5583)
cp14_2014_01_20_00 -1.5 0.1559 -9.625 <2e-16 *** (-1.806, -1.195)
is_weeke...01_20_00 0.1599 0.148 1.08 0.280 (-0.1303, 0.4501)
str_dow_...01_20_00 -0.0756 0.3113 -0.2429 0.808 (-0.686, 0.5348)
str_dow_...01_20_00 -0.3772 0.2363 -1.597 0.110 (-0.8405, 0.08607)
str_dow_...01_20_00 -0.1935 0.2571 -0.7524 0.452 (-0.6977, 0.3107)
str_dow_...01_20_00 -0.02345 0.2554 -0.09181 0.927 (-0.5243, 0.4774)
str_dow_...01_20_00 -0.2131 0.2354 -0.9054 0.365 (-0.6746, 0.2484)
str_dow_...01_20_00 0.3727 0.27 1.38 0.168 (-0.1568, 0.9022)
ct1:sin1_tow_weekly 11.27 7.728 1.458 0.145 (-3.884, 26.42)
ct1:cos1_tow_weekly -42.38 14.42 -2.94 0.003 ** (-70.65, -14.11)
ct1:sin2_tow_weekly 11.61 9.519 1.22 0.223 (-7.051, 30.28)
ct1:cos2_tow_weekly -14.83 12.58 -1.178 0.239 (-39.5, 9.85)
cp0_2008...w_weekly -11.55 8.342 -1.385 0.166 (-27.91, 4.806)
cp0_2008...w_weekly 38.17 15.62 2.444 0.015 * (7.546, 68.8)
cp0_2008...w_weekly -10.42 10.25 -1.016 0.310 (-30.52, 9.684)
cp0_2008...w_weekly 11.57 13.64 0.8485 0.396 (-15.17, 38.32)
cp1_2008...w_weekly 1.742 11.08 0.1573 0.875 (-19.98, 23.46)
cp1_2008...w_weekly 66.12 21.33 3.099 0.002 ** (24.29, 108.0)
cp1_2008...w_weekly -7.607 13.42 -0.5667 0.571 (-33.93, 18.71)
cp1_2008...w_weekly 27.5 18.77 1.465 0.143 (-9.305, 64.3)
cp2_2008...w_weekly -1.882 12.75 -0.1476 0.883 (-26.88, 23.12)
cp2_2008...w_weekly -78.95 24.57 -3.214 0.001 ** (-127.1, -30.78)
cp2_2008...w_weekly 7.135 15.44 0.462 0.644 (-23.14, 37.41)
cp2_2008...w_weekly -28.58 21.61 -1.323 0.186 (-70.95, 13.79)
cp3_2009...w_weekly 3.428 3.673 0.9332 0.351 (-3.775, 10.63)
cp3_2009...w_weekly 17.67 7.092 2.492 0.013 * (3.768, 31.58)
cp3_2009...w_weekly 1.776 4.432 0.4007 0.689 (-6.914, 10.47)
cp3_2009...w_weekly 4.647 6.223 0.7467 0.455 (-7.555, 16.85)
cp4_2009...w_weekly -6.381 2.911 -2.192 0.028 * (-12.09, -0.6732)
cp4_2009...w_weekly 10.62 5.602 1.895 0.058 . (-0.3661, 21.6)
cp4_2009...w_weekly -3.098 3.505 -0.8839 0.377 (-9.971, 3.775)
cp4_2009...w_weekly 9.347 4.914 1.902 0.057 . (-0.2883, 18.98)
cp5_2009...w_weekly 18.71 9.453 1.979 0.048 * (0.1733, 37.24)
cp5_2009...w_weekly -64.56 18.15 -3.557 3.81e-04 *** (-100.2, -28.97)
cp5_2009...w_weekly 10.91 11.39 0.9576 0.338 (-11.43, 33.25)
cp5_2009...w_weekly -43.82 15.88 -2.759 0.006 ** (-74.96, -12.68)
cp6_2010...w_weekly -13.09 7.76 -1.687 0.092 . (-28.31, 2.123)
cp6_2010...w_weekly 54.8 14.91 3.676 2.41e-04 *** (25.57, 84.03)
cp6_2010...w_weekly -8.596 9.347 -0.9197 0.358 (-26.92, 9.732)
cp6_2010...w_weekly 35.87 13.04 2.752 0.006 ** (10.31, 61.44)
cp7_2011...w_weekly 0.7463 1.133 0.6589 0.510 (-1.475, 2.967)
cp7_2011...w_weekly -8.183 2.192 -3.733 1.93e-04 *** (-12.48, -3.885)
cp7_2011...w_weekly 0.7436 1.368 0.5437 0.587 (-1.938, 3.425)
cp7_2011...w_weekly -3.705 1.927 -1.923 0.055 . (-7.484, 0.07322)
cp8_2011...w_weekly -1.039 2.63 -0.3949 0.693 (-6.196, 4.118)
cp8_2011...w_weekly 24.1 5.078 4.745 2.19e-06 *** (14.14, 34.06)
cp8_2011...w_weekly -0.339 3.185 -0.1064 0.915 (-6.585, 5.907)
cp8_2011...w_weekly 10.25 4.475 2.29 0.022 * (1.475, 19.03)
cp9_2011...w_weekly -0.3068 10.23 -0.02998 0.976 (-20.37, 19.76)
cp9_2011...w_weekly -35.04 19.45 -1.801 0.072 . (-73.18, 3.111)
cp9_2011...w_weekly -3.097 12.41 -0.2497 0.803 (-27.42, 21.23)
cp9_2011...w_weekly -5.728 17.08 -0.3354 0.737 (-39.21, 27.76)
cp10_201...w_weekly 11.15 16.82 0.6628 0.508 (-21.83, 44.12)
cp10_201...w_weekly 36.18 31.81 1.137 0.256 (-26.2, 98.56)
cp10_201...w_weekly -7.196 20.38 -0.3531 0.724 (-47.16, 32.77)
cp10_201...w_weekly -2.837 27.87 -0.1018 0.919 (-57.49, 51.82)
cp11_201...w_weekly -9.286 11.09 -0.8371 0.403 (-31.04, 12.47)
cp11_201...w_weekly -32.61 21.11 -1.544 0.123 (-74.01, 8.792)
cp11_201...w_weekly 17.72 13.44 1.318 0.188 (-8.635, 44.07)
cp11_201...w_weekly -1.145 18.52 -0.06185 0.951 (-37.46, 35.16)
cp12_201...w_weekly -0.06491 2.725 -0.02382 0.981 (-5.408, 5.278)
cp12_201...w_weekly 14.47 5.25 2.757 0.006 ** (4.18, 24.77)
cp12_201...w_weekly -6.44 3.295 -1.954 0.051 . (-12.9, 0.0218)
cp12_201...w_weekly 2.955 4.613 0.6407 0.522 (-6.089, 12.0)
cp13_201...w_weekly 1.144 0.3279 3.489 4.92e-04 *** (0.5011, 1.787)
cp13_201...w_weekly -0.4545 0.6355 -0.7151 0.475 (-1.701, 0.7916)
cp13_201...w_weekly 0.3956 0.3994 0.9904 0.322 (-0.3875, 1.179)
cp13_201...w_weekly 0.2912 0.5615 0.5187 0.604 (-0.8097, 1.392)
cp14_201...w_weekly 0.06485 0.1476 0.4392 0.661 (-0.2247, 0.3544)
cp14_201...w_weekly 0.09127 0.2853 0.3199 0.749 (-0.4682, 0.6507)
cp14_201...w_weekly 0.2462 0.1803 1.366 0.172 (-0.1073, 0.5996)
cp14_201...w_weekly -0.0006615 0.2529 -0.002616 0.998 (-0.4965, 0.4952)
sin1_tow_weekly 0.134 0.1498 0.8946 0.371 (-0.1597, 0.4277)
cos1_tow_weekly 1.132 0.1882 6.014 2.04e-09 *** (0.7628, 1.501)
sin2_tow_weekly -0.0503 0.151 -0.3332 0.739 (-0.3464, 0.2458)
cos2_tow_weekly 0.6298 0.1873 3.362 7.85e-04 *** (0.2625, 0.9972)
sin3_tow_weekly 0.03251 0.1483 0.2193 0.826 (-0.2582, 0.3233)
cos3_tow_weekly 0.3237 0.1882 1.72 0.086 . (-0.04536, 0.6928)
sin2_tom_monthly 0.04764 0.02556 1.864 0.062 . (-0.002474, 0.09775)
cos2_tom_monthly -0.05897 0.02637 -2.236 0.025 * (-0.1107, -0.007266)
sin3_toq_quarterly 0.0635 0.02621 2.423 0.015 * (0.01211, 0.1149)
cos3_toq_quarterly 0.01505 0.02624 0.5737 0.566 (-0.03639, 0.0665)
sin1_ct1_yearly -0.3429 0.03076 -11.15 <2e-16 *** (-0.4033, -0.2826)
cos1_ct1_yearly 1.62 0.03253 49.81 <2e-16 *** (1.556, 1.684)
sin2_ct1_yearly 0.06827 0.02805 2.434 0.015 * (0.01327, 0.1233)
cos2_ct1_yearly -0.1547 0.0284 -5.448 5.55e-08 *** (-0.2104, -0.09901)
sin3_ct1_yearly 0.5123 0.02797 18.32 <2e-16 *** (0.4575, 0.5671)
cos3_ct1_yearly -0.06643 0.02712 -2.449 0.014 * (-0.1196, -0.01325)
sin4_ct1_yearly 0.04131 0.0277 1.492 0.136 (-0.01299, 0.09562)
cos4_ct1_yearly -0.2267 0.02539 -8.929 <2e-16 *** (-0.2765, -0.1769)
sin5_ct1_yearly -0.1816 0.02764 -6.571 5.96e-11 *** (-0.2358, -0.1274)
cos5_ct1_yearly -0.03185 0.02514 -1.267 0.205 (-0.08114, 0.01745)
sin6_ct1_yearly -0.2291 0.0272 -8.421 <2e-16 *** (-0.2824, -0.1757)
cos6_ct1_yearly -0.05742 0.02608 -2.201 0.028 * (-0.1086, -0.006277)
sin7_ct1_yearly -0.1061 0.02653 -3.998 6.56e-05 *** (-0.1581, -0.05404)
cos7_ct1_yearly 0.08923 0.02573 3.468 5.32e-04 *** (0.03878, 0.1397)
sin8_ct1_yearly 0.08539 0.02588 3.3 9.80e-04 *** (0.03465, 0.1361)
cos8_ct1_yearly 0.2242 0.02678 8.373 <2e-16 *** (0.1717, 0.2767)
Signif. Code: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Multiple R-squared: 0.7157, Adjusted R-squared: 0.6961
F-statistic: 36.528 on 191 and 2771 DF, p-value: 1.110e-16
Model AIC: 19378.0, model BIC: 20528.0
WARNING: the condition number is large, 3.39e+19. This might indicate that there are strong multicollinearity or other numerical problems.
Apply the model¶
The trained model is available as a fitted sklearn.pipeline.Pipeline
.
174 175 |
Out:
Pipeline(steps=[('input',
PandasFeatureUnion(transformer_list=[('date',
Pipeline(steps=[('select_date',
ColumnSelector(column_names=['ts']))])),
('response',
Pipeline(steps=[('select_val',
ColumnSelector(column_names=['y'])),
('outlier',
ZscoreOutlierTransformer()),
('null',
NullTransformer(impute_algorithm='interpolate',
impute_params={'axis': 0,
'limit_direct...
'start_year': 2007},
uncertainty_dict={'params': {'conditional_cols': ['dow_hr'],
'quantile_estimation_method': 'normal_fit',
'quantiles': [0.025000000000000022,
0.975],
'sample_size_thresh': 5,
'small_sample_size_method': 'std_quantiles',
'small_sample_size_quantile': 0.98},
'uncertainty_method': 'simple_conditional_residuals'},
weekly_seasonality=3,
yearly_seasonality=8))])
You can take this model and forecast on any date range
by passing a new dataframe to predict on. The
make_future_dataframe
convenience function can be used to create this dataframe.
Here, we predict the next 4 periods after the model’s train end date.
Note
The dataframe passed to .predict() must have the same columns
as the df
passed to run_forecast_config
above, including
any regressors needed for prediction. The value_col
column
should be included with values set to np.nan.
189 190 191 192 |
Call .predict() to compute predictions
What’s next?¶
If you’re satisfied with the forecast performance, you’re done!
For a complete example of how to tune this forecast, see Tune your first forecast model.
Besides the component plot, we offer additional tools to help you improve your forecast and understand the result.
See the following guides:
For example, for this dataset, you could add changepoints to handle the change in trend around 2014 and avoid the overprediction issue seen in the backtest plot.
Or you might want to try a different model template. Model templates bundle an algorithm with recommended hyperparameters. The template that works best for you depends on the data characteristics and forecast requirements (e.g. short / long forecast horizon). We recommend trying a few and tuning the ones that look promising. All model templates are available through the same forecasting and tuning interface shown here.
For details about the model templates and how to set model components, see the following guides:
Total running time of the script: ( 0 minutes 31.748 seconds)