Example for weekly data

This is a basic example for weekly data using Silverkite. Note that here we are fitting a few simple models and the goal is not to optimize the results as much as possible.

10 import warnings
11 from collections import defaultdict
12
13 import plotly
14 import pandas as pd
15
16 from greykite.common.constants import TIME_COL
17 from greykite.common.constants import VALUE_COL
18 from greykite.framework.benchmark.data_loader_ts import DataLoader
19 from greykite.framework.input.univariate_time_series import UnivariateTimeSeries
20 from greykite.framework.templates.autogen.forecast_config import EvaluationPeriodParam
21 from greykite.framework.templates.autogen.forecast_config import ForecastConfig
22 from greykite.framework.templates.autogen.forecast_config import MetadataParam
23 from greykite.framework.templates.autogen.forecast_config import ModelComponentsParam
24 from greykite.framework.templates.forecaster import Forecaster
25 from greykite.framework.utils.result_summary import summarize_grid_search_results
26
27 warnings.filterwarnings("ignore")

Loads weekly dataset into UnivariateTimeSeries.

31 dl = DataLoader()
32 agg_func = {"count": "sum"}
33 df = dl.load_bikesharing(agg_freq="weekly", agg_func=agg_func)
34 # In this dataset the first week and last week's data are incomplete, therefore we drop it
35 df.drop(df.head(1).index,inplace=True)
36 df.drop(df.tail(1).index,inplace=True)
37 df.reset_index(drop=True)
38 ts = UnivariateTimeSeries()
39 ts.load_data(
40     df=df,
41     time_col="ts",
42     value_col="count",
43     freq="W-MON")
44 print(ts.df.head())

Out:

                   ts     y
2010-09-27 2010-09-27  2801
2010-10-04 2010-10-04  3238
2010-10-11 2010-10-11  6241
2010-10-18 2010-10-18  7756
2010-10-25 2010-10-25  9556

Exploratory Data Analysis (EDA)

After reading in a time series, we could first do some exploratory data analysis. The UnivariateTimeSeries class is used to store a timeseries and perform EDA.

A quick description of the data can be obtained as follows.

55 print(ts.describe_time_col())
56 print(ts.describe_value_col())

Out:

{'data_points': 466, 'mean_increment_secs': 604800.0, 'min_timestamp': Timestamp('2010-09-27 00:00:00'), 'max_timestamp': Timestamp('2019-08-26 00:00:00')}
count       466.000000
mean      53466.961373
std       24728.824016
min        2801.000000
25%       32819.750000
50%       51921.500000
75%       76160.750000
max      102350.000000
Name: y, dtype: float64

Let’s plot the original timeseries. (The interactive plot is generated by plotly: click to zoom!)

61 fig = ts.plot()
62 plotly.io.show(fig)

Exploratory plots can be plotted to reveal the time series’s properties. Monthly overlay plot can be used to inspect the annual patterns. This plot overlays various years on top of each other.

68 fig = ts.plot_quantiles_and_overlays(
69     groupby_time_feature="month",
70     show_mean=True,
71     show_quantiles=False,
72     show_overlays=True,
73     center_values=True,
74     overlay_label_time_feature="year",  # splits overlays by year
75     overlay_style={"line": {"width": 1}, "opacity": 0.5},
76     xlabel="Month",
77     ylabel=ts.original_value_col,
78     title="Yearly seasonality by year (centered)",
79 )
80 plotly.io.show(fig)

Weekly overlay plot.

84 fig = ts.plot_quantiles_and_overlays(
85     groupby_time_feature="woy",
86     show_mean=True,
87     show_quantiles=False,
88     show_overlays=True,
89     center_values=True,
90     overlay_label_time_feature="year",  # splits overlays by year
91     overlay_style={"line": {"width": 1}, "opacity": 0.5},
92     xlabel="Week of year",
93     ylabel=ts.original_value_col,
94     title="Yearly seasonality by year (centered)",
95 )
96 plotly.io.show(fig)

Fit Greykite Models

After some exploratory data analysis, let’s specify the model parameters and fit a Greykite model.

Specify common metadata.

105 forecast_horizon = 4  # Forecast 4 weeks
106 time_col = TIME_COL  # "ts"
107 value_col = VALUE_COL  # "y"
108 metadata = MetadataParam(
109     time_col=time_col,
110     value_col=value_col,
111     freq="W-MON",  # Optional, the model will infer the data frequency
112 )

Specify common evaluation parameters. Set minimum input data for training.

117 cv_min_train_periods = 52 * 2
118 # Let CV use most recent splits for cross-validation.
119 cv_use_most_recent_splits = True
120 # Determine the maximum number of validations.
121 cv_max_splits = 6
122 evaluation_period = EvaluationPeriodParam(
123     test_horizon=forecast_horizon,
124     cv_horizon=forecast_horizon,
125     periods_between_train_test=0,
126     cv_min_train_periods=cv_min_train_periods,
127     cv_expanding_window=True,
128     cv_use_most_recent_splits=cv_use_most_recent_splits,
129     cv_periods_between_splits=None,
130     cv_periods_between_train_test=0,
131     cv_max_splits=cv_max_splits,
132 )

Let’s also define a helper function that generates the model results summary and plots.

136 def get_model_results_summary(result):
137     """Generates model results summary.
138
139     Parameters
140     ----------
141     result : `ForecastResult`
142         See :class:`~greykite.framework.pipeline.pipeline.ForecastResult` for documentation.
143
144     Returns
145     -------
146     Prints out model coefficients, cross-validation results, overall train/test evalautions.
147     """
148     # Get the useful fields from the forecast result
149     model = result.model[-1]
150     backtest = result.backtest
151     grid_search = result.grid_search
152
153     # Check model coefficients / variables
154     # Get model summary with p-values
155     print(model.summary())
156
157     # Get cross-validation results
158     cv_results = summarize_grid_search_results(
159         grid_search=grid_search,
160         decimals=2,
161         cv_report_metrics=None,
162         column_order=[
163             "rank", "mean_test", "split_test", "mean_train", "split_train",
164             "mean_fit_time", "mean_score_time", "params"])
165     # Transposes to save space in the printed output
166     print("================================= CV Results ==================================")
167     print(cv_results.transpose())
168
169     # Check historical evaluation metrics (on the historical training/test set).
170     backtest_eval = defaultdict(list)
171     for metric, value in backtest.train_evaluation.items():
172         backtest_eval[metric].append(value)
173         backtest_eval[metric].append(backtest.test_evaluation[metric])
174     metrics = pd.DataFrame(backtest_eval, index=["train", "test"]).T
175     print("=========================== Train/Test Evaluation =============================")
176     print(metrics)

Fit a simple model without autoregression. The the most important model parameters are specified through ModelComponentsParam. The extra_pred_cols is used to specify growth and annual seasonality Growth is modelled with both “ct_sqrt”, “ct1” for extra flexibility as we have longterm data and ridge regularization will avoid over-fitting the trend. The yearly seasonality is modelled using Fourier series. In the ModelComponentsParam, we can specify the order of that - the higher the order is, the more flexible pattern the model could capture. Usually one can try integers between 10 and 50.

188 autoregression = None
189 extra_pred_cols = ["ct1", "ct_sqrt", "ct1:C(month, levels=list(range(1, 13)))"]
190
191 # Specify the model parameters
192 model_components = ModelComponentsParam(
193     autoregression=autoregression,
194     seasonality={
195         "yearly_seasonality": 25,
196         "quarterly_seasonality": 0,
197         "monthly_seasonality": 0,
198         "weekly_seasonality": 0,
199         "daily_seasonality": 0
200     },
201     changepoints={
202         'changepoints_dict': {
203             "method": "auto",
204             "resample_freq": "7D",
205             "regularization_strength": 0.5,
206             "potential_changepoint_distance": "14D",
207             "no_changepoint_distance_from_end": "60D",
208             "yearly_seasonality_order": 25,
209             "yearly_seasonality_change_freq": None,
210         },
211         "seasonality_changepoints_dict": None
212     },
213     events={
214         "holiday_lookup_countries": []
215     },
216     growth={
217         "growth_term": None
218     },
219     custom={
220         'feature_sets_enabled': False,
221         'fit_algorithm_dict': dict(fit_algorithm='ridge'),
222         'extra_pred_cols': extra_pred_cols,
223     }
224 )
225
226 forecast_config = ForecastConfig(
227     metadata_param=metadata,
228     forecast_horizon=forecast_horizon,
229     coverage=0.95,
230     evaluation_period_param=evaluation_period,
231     model_components_param=model_components
232 )
233
234 # Run the forecast model
235 forecaster = Forecaster()
236 result = forecaster.run_forecast_config(
237     df=ts.df,
238     config=forecast_config
239 )

Out:

Fitting 6 folds for each of 1 candidates, totalling 6 fits

Let’s check the model results summary and plots.

243 get_model_results_summary(result)

Out:

============================ Forecast Model Summary ============================

Number of observations: 466,   Number of features: 68
Method: Ridge regression
Number of nonzero features: 68
Regularization parameter: 0.02807

Residuals:
         Min           1Q       Median           3Q          Max
  -2.758e+04      -3953.0        169.9       4685.0    2.165e+04

           Pred_col   Estimate  Std. Err Pr(>)_boot sig. code                    95%CI
          Intercept  1.086e+04    5404.0      0.046         *      (1652.0, 2.344e+04)
                ct1  1.932e+04 1.165e+04      0.102               (-3443.0, 4.161e+04)
ct1:C(mo... 13)))_2      917.1    6467.0      0.894            (-1.196e+04, 1.442e+04)
ct1:C(mo... 13)))_3     9628.0    6290.0      0.126               (-1844.0, 2.160e+04)
ct1:C(mo... 13)))_4  3.472e+04    5539.0     <2e-16       ***   (2.356e+04, 4.487e+04)
ct1:C(mo... 13)))_5  2.762e+04    5880.0     <2e-16       ***   (1.585e+04, 3.925e+04)
ct1:C(mo... 13)))_6  3.755e+04    5210.0     <2e-16       ***   (2.534e+04, 4.759e+04)
ct1:C(mo... 13)))_7  4.068e+04    5507.0     <2e-16       ***   (3.028e+04, 5.098e+04)
ct1:C(mo... 13)))_8  4.096e+04    5383.0     <2e-16       ***   (3.042e+04, 5.121e+04)
ct1:C(mo... 13)))_9  3.261e+04    5876.0     <2e-16       ***   (2.165e+04, 4.418e+04)
ct1:C(mo...13)))_10  3.322e+04    5290.0     <2e-16       ***   (2.235e+04, 4.351e+04)
ct1:C(mo...13)))_11  1.036e+04    5660.0      0.074         .      (-661.7, 2.150e+04)
ct1:C(mo...13)))_12     4878.0    5476.0      0.372               (-6619.0, 1.499e+04)
            ct_sqrt  5.656e+04    9718.0     <2e-16       ***   (3.494e+04, 7.215e+04)
    sin1_ct1_yearly -1.977e+04    1589.0     <2e-16       *** (-2.293e+04, -1.687e+04)
    cos1_ct1_yearly     6433.0    1757.0     <2e-16       ***      (3351.0, 1.017e+04)
    sin2_ct1_yearly     5236.0    1580.0     <2e-16       ***         (2353.0, 8398.0)
    cos2_ct1_yearly     4841.0    1618.0      0.002        **         (1816.0, 7975.0)
    sin3_ct1_yearly     1800.0    1583.0      0.280                  (-1194.0, 4808.0)
    cos3_ct1_yearly     -272.9    1576.0      0.870                  (-3531.0, 2668.0)
    sin4_ct1_yearly     -337.2    1480.0      0.806                  (-3329.0, 2502.0)
    cos4_ct1_yearly    -1376.0    1467.0      0.344                  (-4096.0, 1832.0)
    sin5_ct1_yearly    -2044.0    1473.0      0.150                   (-5038.0, 922.5)
    cos5_ct1_yearly     -786.7    1353.0      0.548                  (-3690.0, 1787.0)
    sin6_ct1_yearly     -126.7    1521.0      0.944                  (-2965.0, 2845.0)
    cos6_ct1_yearly     1482.0    1146.0      0.196                   (-640.0, 3567.0)
    sin7_ct1_yearly     -363.0    1314.0      0.760                  (-2797.0, 2148.0)
    cos7_ct1_yearly     -270.2    1177.0      0.798                  (-2542.0, 2135.0)
    sin8_ct1_yearly    -1562.0    1250.0      0.212                   (-4127.0, 876.2)
    cos8_ct1_yearly      724.6    1146.0      0.550                  (-1536.0, 2943.0)
    sin9_ct1_yearly    -1829.0    1134.0      0.110                   (-3941.0, 329.1)
    cos9_ct1_yearly     2049.0    1154.0      0.074         .         (-66.95, 4482.0)
   sin10_ct1_yearly      630.4    1062.0      0.546                  (-1446.0, 2756.0)
   cos10_ct1_yearly     1728.0    1080.0      0.112                   (-307.6, 3785.0)
   sin11_ct1_yearly     2838.0    1022.0      0.012         *          (809.5, 4799.0)
   cos11_ct1_yearly     -686.5    1060.0      0.520                  (-2890.0, 1180.0)
   sin12_ct1_yearly    -2057.0    1027.0      0.050         .         (-3982.0, 60.42)
   cos12_ct1_yearly    -2302.0    1089.0      0.028         *        (-4307.0, -108.6)
   sin13_ct1_yearly     -407.8     992.1      0.682                  (-2361.0, 1512.0)
   cos13_ct1_yearly      316.2    1011.0      0.732                  (-1946.0, 2145.0)
   sin14_ct1_yearly    -1372.0    1031.0      0.172                   (-3275.0, 525.7)
   cos14_ct1_yearly     1162.0    1050.0      0.266                   (-879.0, 3173.0)
   sin15_ct1_yearly      112.2    1091.0      0.904                  (-2122.0, 2258.0)
   cos15_ct1_yearly     1259.0    1037.0      0.214                   (-804.3, 3228.0)
   sin16_ct1_yearly    -2384.0    1071.0      0.032         *        (-4437.0, -218.0)
   cos16_ct1_yearly     -644.5    1117.0      0.576                  (-2829.0, 1698.0)
   sin17_ct1_yearly      680.7    1011.0      0.486                  (-1200.0, 2586.0)
   cos17_ct1_yearly      850.7    1095.0      0.448                  (-1344.0, 2902.0)
   sin18_ct1_yearly     -549.1    1031.0      0.592                  (-2599.0, 1448.0)
   cos18_ct1_yearly      220.5    1067.0      0.832                  (-1807.0, 2334.0)
   sin19_ct1_yearly     -579.2    1016.0      0.564                  (-2653.0, 1317.0)
   cos19_ct1_yearly     -773.8    1078.0      0.462                  (-2834.0, 1408.0)
   sin20_ct1_yearly     1083.0    1064.0      0.304                  (-1059.0, 3078.0)
   cos20_ct1_yearly      311.6    1036.0      0.758                  (-1508.0, 2296.0)
   sin21_ct1_yearly    -1025.0    1035.0      0.368                   (-2965.0, 899.5)
   cos21_ct1_yearly     -483.3    1069.0      0.672                  (-2661.0, 1443.0)
   sin22_ct1_yearly     1110.0     952.6      0.252                   (-859.9, 2879.0)
   cos22_ct1_yearly      340.0    1134.0      0.752                  (-1845.0, 2734.0)
   sin23_ct1_yearly      506.2     938.8      0.594                  (-1362.0, 2344.0)
   cos23_ct1_yearly    -3098.0    1114.0      0.002        **        (-5347.0, -970.5)
   sin24_ct1_yearly    -1075.0    1074.0      0.298                   (-3128.0, 910.0)
   cos24_ct1_yearly     -367.7    1120.0      0.750                  (-2452.0, 1905.0)
   sin25_ct1_yearly    -2124.0    1049.0      0.040         *        (-4216.0, -100.1)
   cos25_ct1_yearly     -34.79    1056.0      0.974                  (-1996.0, 1935.0)
  cp0_2012_01_30_00     2645.0 1.245e+04      0.864            (-2.137e+04, 2.618e+04)
  cp1_2013_01_14_00 -2.420e+04 1.087e+04      0.030         *    (-4.633e+04, -3150.0)
  cp2_2015_02_23_00    -1574.0    5547.0      0.774               (-1.282e+04, 8974.0)
  cp3_2017_10_02_00 -1.979e+04    2996.0     <2e-16       *** (-2.534e+04, -1.355e+04)
Signif. Code: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Multiple R-squared: 0.9181,   Adjusted R-squared: 0.9047
F-statistic: 67.998 on 65 and 399 DF,   p-value: 1.110e-16
Model AIC: 11257.0,   model BIC: 11533.0

WARNING: the condition number is large, 2.06e+05. This might indicate that there are strong multicollinearity or other numerical problems.
WARNING: the F-ratio and its p-value on regularized methods might be misleading, they are provided only for reference purposes.

================================= CV Results ==================================
                                                                              0
rank_test_MAPE                                                                1
mean_test_MAPE                                                            10.73
split_test_MAPE                        (12.11, 15.22, 4.69, 10.99, 9.81, 11.59)
mean_train_MAPE                                                           15.96
split_train_MAPE                      (15.89, 16.1, 16.05, 15.95, 15.91, 15.88)
mean_fit_time                                                              4.92
mean_score_time                                                            0.35
param_estimator__auto_holiday_params                                       None
params                                                                       []
=========================== Train/Test Evaluation =============================
                                                              train            test
CORR                                                       0.957887        0.886164
R2                                                         0.917539       -2.019265
MSE                                                 50186299.582873  51875105.70039
RMSE                                                    7084.228934     7202.437483
MAE                                                     5394.331719     6425.432865
MedAE                                                   4193.480899     6045.073112
MAPE                                                      15.853829        8.134249
MedAPE                                                     8.593354        7.539209
sMAPE                                                       7.41262        3.864425
Q80                                                     2697.165859     1285.086573
Q95                                                     2697.165859      321.271643
Q99                                                     2697.165859       64.254329
OutsideTolerance1p                                         0.943723             1.0
OutsideTolerance2p                                         0.883117             1.0
OutsideTolerance3p                                          0.80303             1.0
OutsideTolerance4p                                         0.755411            0.75
OutsideTolerance5p                                         0.705628             0.5
Outside Tolerance (fraction)                                   None            None
R2_null_model_score                                            None            None
Prediction Band Width (%)                                 91.188809        41.58916
Prediction Band Coverage (fraction)                        0.965368             1.0
Coverage: Lower Band                                       0.465368             1.0
Coverage: Upper Band                                            0.5             0.0
Coverage Diff: Actual_Coverage - Intended_Coverage         0.015368            0.05
MIS                                                    37747.359084    33697.724421

Fit/backtest plot:

247 fig = result.backtest.plot()
248 plotly.io.show(fig)

Forecast plot:

252 fig = result.forecast.plot()
253 plotly.io.show(fig)

The components plot:

257 fig = result.forecast.plot_components()
258 plotly.io.show(fig)

Fit a simple model with autoregression. This is done by specifying the autoregression parameter in ModelComponentsParam. Note that the auto-regressive structure can be customized further depending on your data.

264 autoregression = {
265     "autoreg_dict": {
266         "lag_dict": {"orders": [1]},  # Only use lag-1
267         "agg_lag_dict": None
268     }
269 }
270 extra_pred_cols = ["ct1", "ct_sqrt", "ct1:C(month, levels=list(range(1, 13)))"]
271
272 # Specify the model parameters
273 model_components = ModelComponentsParam(
274     autoregression=autoregression,
275     seasonality={
276         "yearly_seasonality": 25,
277         "quarterly_seasonality": 0,
278         "monthly_seasonality": 0,
279         "weekly_seasonality": 0,
280         "daily_seasonality": 0
281     },
282     changepoints={
283         'changepoints_dict': {
284             "method": "auto",
285             "resample_freq": "7D",
286             "regularization_strength": 0.5,
287             "potential_changepoint_distance": "14D",
288             "no_changepoint_distance_from_end": "60D",
289             "yearly_seasonality_order": 25,
290             "yearly_seasonality_change_freq": None,
291         },
292         "seasonality_changepoints_dict": None
293     },
294     events={
295         "holiday_lookup_countries": []
296     },
297     growth={
298         "growth_term": None
299     },
300     custom={
301         'feature_sets_enabled': False,
302         'fit_algorithm_dict': dict(fit_algorithm='ridge'),
303         'extra_pred_cols': extra_pred_cols,
304     }
305 )
306
307 forecast_config = ForecastConfig(
308     metadata_param=metadata,
309     forecast_horizon=forecast_horizon,
310     coverage=0.95,
311     evaluation_period_param=evaluation_period,
312     model_components_param=model_components
313 )
314
315 # Run the forecast model
316 forecaster = Forecaster()
317 result = forecaster.run_forecast_config(
318     df=ts.df,
319     config=forecast_config
320 )

Out:

Fitting 6 folds for each of 1 candidates, totalling 6 fits

Let’s check the model results summary and plots.

324 get_model_results_summary(result)

Out:

============================ Forecast Model Summary ============================

Number of observations: 466,   Number of features: 69
Method: Ridge regression
Number of nonzero features: 69
Regularization parameter: 0.0621

Residuals:
         Min           1Q       Median           3Q          Max
  -2.954e+04      -3841.0        468.7       4111.0    2.007e+04

           Pred_col   Estimate Std. Err Pr(>)_boot sig. code                    95%CI
          Intercept  1.228e+04   4915.0      0.024         *      (4007.0, 2.305e+04)
                ct1  1.700e+04   4830.0     <2e-16       ***      (7863.0, 2.729e+04)
ct1:C(mo... 13)))_2    -1832.0   5124.0      0.708               (-1.177e+04, 8548.0)
ct1:C(mo... 13)))_3     4877.0   5692.0      0.414               (-6494.0, 1.511e+04)
ct1:C(mo... 13)))_4  2.342e+04   4898.0     <2e-16       ***   (1.380e+04, 3.176e+04)
ct1:C(mo... 13)))_5  1.770e+04   5934.0      0.004        **      (4958.0, 2.884e+04)
ct1:C(mo... 13)))_6  2.350e+04   4827.0     <2e-16       ***   (1.311e+04, 3.269e+04)
ct1:C(mo... 13)))_7  2.675e+04   4721.0     <2e-16       ***   (1.725e+04, 3.568e+04)
ct1:C(mo... 13)))_8  2.596e+04   4897.0     <2e-16       ***   (1.548e+04, 3.455e+04)
ct1:C(mo... 13)))_9  1.952e+04   5617.0     <2e-16       ***      (7750.0, 2.962e+04)
ct1:C(mo...13)))_10  2.056e+04   4615.0     <2e-16       ***   (1.030e+04, 2.906e+04)
ct1:C(mo...13)))_11     2924.0   4694.0      0.534               (-6808.0, 1.153e+04)
ct1:C(mo...13)))_12     1582.0   4849.0      0.782               (-7841.0, 1.003e+04)
            ct_sqrt  3.718e+04   6223.0     <2e-16       ***   (2.473e+04, 4.877e+04)
    sin1_ct1_yearly -1.452e+04   1826.0     <2e-16       *** (-1.831e+04, -1.127e+04)
    cos1_ct1_yearly     4158.0   1549.0      0.008        **         (1247.0, 7240.0)
    sin2_ct1_yearly     3378.0   1498.0      0.022         *          (448.1, 6185.0)
    cos2_ct1_yearly     4393.0   1560.0      0.008        **         (1453.0, 7446.0)
    sin3_ct1_yearly     1934.0   1510.0      0.206                  (-1054.0, 4822.0)
    cos3_ct1_yearly     -201.8   1447.0      0.866                  (-3176.0, 2666.0)
    sin4_ct1_yearly     -914.2   1384.0      0.500                  (-3508.0, 1749.0)
    cos4_ct1_yearly     -796.1   1437.0      0.544                  (-3510.0, 2103.0)
    sin5_ct1_yearly    -1596.0   1363.0      0.240                  (-4171.0, 1073.0)
    cos5_ct1_yearly     -988.7   1233.0      0.432                  (-3281.0, 1358.0)
    sin6_ct1_yearly      113.2   1371.0      0.924                  (-2533.0, 2621.0)
    cos6_ct1_yearly     1641.0   1129.0      0.152                   (-747.1, 3719.0)
    sin7_ct1_yearly     -485.6   1236.0      0.710                  (-2891.0, 1779.0)
    cos7_ct1_yearly     -215.5   1048.0      0.842                  (-2408.0, 1808.0)
    sin8_ct1_yearly    -1111.0   1196.0      0.374                   (-3434.0, 991.4)
    cos8_ct1_yearly      519.5   1050.0      0.636                  (-1469.0, 2579.0)
    sin9_ct1_yearly    -2083.0   1023.0      0.032         *        (-4114.0, -308.3)
    cos9_ct1_yearly     1135.0   1102.0      0.314                   (-987.0, 3278.0)
   sin10_ct1_yearly      178.2   1024.0      0.848                  (-1935.0, 2117.0)
   cos10_ct1_yearly     1482.0    977.7      0.126                   (-416.0, 3335.0)
   sin11_ct1_yearly     2166.0    962.1      0.022         *          (319.4, 3867.0)
   cos11_ct1_yearly     -251.9    994.4      0.792                  (-2171.0, 1852.0)
   sin12_ct1_yearly    -1328.0    975.8      0.176                   (-3302.0, 429.3)
   cos12_ct1_yearly    -2660.0    967.7      0.002        **       (-4691.0, -1002.0)
   sin13_ct1_yearly    -1046.0    985.5      0.282                   (-2990.0, 882.8)
   cos13_ct1_yearly      463.8    969.7      0.660                  (-1475.0, 2421.0)
   sin14_ct1_yearly    -1463.0    966.8      0.128                   (-3515.0, 442.3)
   cos14_ct1_yearly     1141.0   1046.0      0.282                   (-651.4, 3182.0)
   sin15_ct1_yearly     -189.7   1121.0      0.880                  (-2179.0, 2241.0)
   cos15_ct1_yearly     1158.0    994.1      0.226                   (-768.1, 2921.0)
   sin16_ct1_yearly    -2142.0    980.4      0.032         *        (-4078.0, -345.9)
   cos16_ct1_yearly    -1075.0    992.3      0.286                   (-2973.0, 895.8)
   sin17_ct1_yearly      423.9    994.2      0.730                  (-1378.0, 2307.0)
   cos17_ct1_yearly      983.1    943.9      0.306                   (-905.4, 2835.0)
   sin18_ct1_yearly     -245.8   1042.0      0.804                  (-2217.0, 1869.0)
   cos18_ct1_yearly     -192.3    966.4      0.840                  (-1994.0, 1614.0)
   sin19_ct1_yearly     -698.6    964.0      0.474                  (-2739.0, 1225.0)
   cos19_ct1_yearly     -929.2    998.8      0.342                  (-2791.0, 1073.0)
   sin20_ct1_yearly     1321.0    954.3      0.174                   (-396.7, 3294.0)
   cos20_ct1_yearly      428.0   1068.0      0.712                  (-1722.0, 2266.0)
   sin21_ct1_yearly    -1275.0    993.5      0.174                   (-3129.0, 846.7)
   cos21_ct1_yearly     -740.6    995.7      0.460                  (-2657.0, 1065.0)
   sin22_ct1_yearly     1233.0    934.1      0.186                   (-589.4, 3106.0)
   cos22_ct1_yearly      603.5   1113.0      0.596                  (-1485.0, 2794.0)
   sin23_ct1_yearly      570.9    961.2      0.560                  (-1299.0, 2257.0)
   cos23_ct1_yearly    -3478.0   1047.0      0.002        **       (-5483.0, -1588.0)
   sin24_ct1_yearly    -1124.0    994.4      0.264                   (-3101.0, 657.8)
   cos24_ct1_yearly     -484.6   1027.0      0.642                  (-2470.0, 1489.0)
   sin25_ct1_yearly    -2646.0    970.0      0.002        **        (-4571.0, -928.0)
   cos25_ct1_yearly      307.7   1007.0      0.770                  (-1422.0, 2374.0)
  cp0_2012_01_30_00     2383.0   8226.0      0.770            (-1.341e+04, 1.753e+04)
  cp1_2013_01_14_00 -1.616e+04   8493.0      0.056         .     (-3.487e+04, -611.9)
  cp2_2015_02_23_00    -2032.0   5087.0      0.692               (-1.100e+04, 7818.0)
  cp3_2017_10_02_00 -1.392e+04   3028.0     <2e-16       ***    (-1.938e+04, -8003.0)
             y_lag1  2.981e+04   5293.0     <2e-16       ***   (2.012e+04, 4.130e+04)
Signif. Code: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Multiple R-squared: 0.9245,   Adjusted R-squared: 0.912
F-statistic: 73.697 on 66 and 398 DF,   p-value: 1.110e-16
Model AIC: 11220.0,   model BIC: 11498.0

WARNING: the condition number is large, 1.04e+05. This might indicate that there are strong multicollinearity or other numerical problems.
WARNING: the F-ratio and its p-value on regularized methods might be misleading, they are provided only for reference purposes.

================================= CV Results ==================================
                                                                               0
rank_test_MAPE                                                                 1
mean_test_MAPE                                                             10.71
split_test_MAPE                          (15.14, 13.3, 7.09, 10.34, 8.01, 10.39)
mean_train_MAPE                                                            14.46
split_train_MAPE                      (14.61, 14.54, 14.48, 14.43, 14.38, 14.31)
mean_fit_time                                                               4.36
mean_score_time                                                             5.77
param_estimator__auto_holiday_params                                        None
params                                                                        []
=========================== Train/Test Evaluation =============================
                                                             train             test
CORR                                                      0.961255         0.966554
R2                                                        0.924008         -2.16448
MSE                                                 46248880.41402  54370105.477575
RMSE                                                    6800.65294      7373.608715
MAE                                                    5131.614192      7227.447815
MedAE                                                  4077.576962      7494.464787
MAPE                                                     14.266985         8.998055
MedAPE                                                    7.631892         9.368987
sMAPE                                                     6.689048         4.294898
Q80                                                    2565.807096      1445.489563
Q95                                                    2565.807096       361.372391
Q99                                                    2565.807096        72.274478
OutsideTolerance1p                                        0.919913              1.0
OutsideTolerance2p                                        0.863636              1.0
OutsideTolerance3p                                        0.798701              1.0
OutsideTolerance4p                                        0.757576              1.0
OutsideTolerance5p                                        0.675325              1.0
Outside Tolerance (fraction)                                  None             None
R2_null_model_score                                           None             None
Prediction Band Width (%)                                87.710451        26.414926
Prediction Band Coverage (fraction)                       0.965368              1.0
Coverage: Lower Band                                        0.4329              1.0
Coverage: Upper Band                                      0.532468              0.0
Coverage Diff: Actual_Coverage - Intended_Coverage        0.015368             0.05
MIS                                                   36540.712701     21114.559822

Fit/backtest plot:

328 fig = result.backtest.plot()
329 plotly.io.show(fig)

Forecast plot:

333 fig = result.forecast.plot()
334 plotly.io.show(fig)

The components plot:

338 fig = result.forecast.plot_components()
339 plotly.io.show(fig)

Fit a greykite model with autoregression and forecast one-by-one. Forecast one-by-one is only used when autoregression is set to “auto”, and it can be enable by setting forecast_one_by_one=True in Without forecast one-by-one, the lag order in autoregression has to be greater than the forecast horizon in order to avoid simulation (which leads to less accuracy). The advantage of turning on forecast_one_by_one is to improve the forecast accuracy by breaking the forecast horizon to smaller steps, fitting multiple models using immediate lags. Note that the forecast one-by-one option may slow down the training.

350 autoregression = {
351     "autoreg_dict": "auto"
352 }
353 extra_pred_cols = ["ct1", "ct_sqrt", "ct1:C(month, levels=list(range(1, 13)))"]
354 forecast_one_by_one = True
355
356 # Specify the model parameters
357 model_components = ModelComponentsParam(
358     autoregression=autoregression,
359     seasonality={
360         "yearly_seasonality": 25,
361         "quarterly_seasonality": 0,
362         "monthly_seasonality": 0,
363         "weekly_seasonality": 0,
364         "daily_seasonality": 0
365     },
366     changepoints={
367         'changepoints_dict': {
368             "method": "auto",
369             "resample_freq": "7D",
370             "regularization_strength": 0.5,
371             "potential_changepoint_distance": "14D",
372             "no_changepoint_distance_from_end": "60D",
373             "yearly_seasonality_order": 25,
374             "yearly_seasonality_change_freq": None,
375         },
376         "seasonality_changepoints_dict": None
377     },
378     events={
379         "holiday_lookup_countries": []
380     },
381     growth={
382         "growth_term": None
383     },
384     custom={
385         'feature_sets_enabled': False,
386         'fit_algorithm_dict': dict(fit_algorithm='ridge'),
387         'extra_pred_cols': extra_pred_cols,
388     }
389 )
390
391 forecast_config = ForecastConfig(
392     metadata_param=metadata,
393     forecast_horizon=forecast_horizon,
394     coverage=0.95,
395     evaluation_period_param=evaluation_period,
396     model_components_param=model_components,
397     forecast_one_by_one=forecast_one_by_one
398 )
399
400 # Run the forecast model
401 forecaster = Forecaster()
402 result =  forecaster.run_forecast_config(
403     df=ts.df,
404     config=forecast_config
405 )

Out:

Fitting 6 folds for each of 1 candidates, totalling 6 fits

Let’s check the model results summary and plots. Here the forecast_one_by_one option fits 4 models for each step, hence 4 model summaries are printed, and 4 components plots are generated.

410 get_model_results_summary(result)

Out:

[============================ Forecast Model Summary ============================

Number of observations: 466,   Number of features: 71
Method: Ridge regression
Number of nonzero features: 71
Regularization parameter: 0.0621

Residuals:
         Min           1Q       Median           3Q          Max
  -2.890e+04      -3782.0        623.6       3971.0    2.048e+04

           Pred_col   Estimate Std. Err Pr(>)_boot sig. code                   95%CI
          Intercept  1.157e+04   4651.0      0.024         *     (3341.0, 2.208e+04)
                ct1  1.383e+04   5095.0      0.012         *     (3799.0, 2.334e+04)
ct1:C(mo... 13)))_2    -1369.0   5254.0      0.776              (-1.167e+04, 8357.0)
ct1:C(mo... 13)))_3     3498.0   5566.0      0.534              (-6687.0, 1.502e+04)
ct1:C(mo... 13)))_4  2.005e+04   4924.0     <2e-16       ***     (9803.0, 2.917e+04)
ct1:C(mo... 13)))_5  1.243e+04   6029.0      0.034         *     (-24.65, 2.394e+04)
ct1:C(mo... 13)))_6  1.846e+04   5029.0     <2e-16       ***     (7945.0, 2.846e+04)
ct1:C(mo... 13)))_7  2.014e+04   5210.0     <2e-16       ***     (9917.0, 3.032e+04)
ct1:C(mo... 13)))_8  1.952e+04   5071.0     <2e-16       ***  (1.034e+04, 2.983e+04)
ct1:C(mo... 13)))_9  1.316e+04   5350.0      0.014         *     (2964.0, 2.357e+04)
ct1:C(mo...13)))_10  1.442e+04   5220.0      0.008        **     (4713.0, 2.459e+04)
ct1:C(mo...13)))_11    -2251.0   4797.0      0.630              (-1.122e+04, 6839.0)
ct1:C(mo...13)))_12      88.81   5071.0      0.992              (-1.062e+04, 9008.0)
            ct_sqrt  2.724e+04   6365.0     <2e-16       ***  (1.395e+04, 3.872e+04)
    sin1_ct1_yearly -1.184e+04   2125.0     <2e-16       ***   (-1.625e+04, -7816.0)
    cos1_ct1_yearly     2201.0   1555.0      0.156                  (-879.7, 5100.0)
    sin2_ct1_yearly     2414.0   1455.0      0.100                  (-543.2, 5329.0)
    cos2_ct1_yearly     4682.0   1408.0     <2e-16       ***        (2057.0, 7615.0)
    sin3_ct1_yearly     2098.0   1408.0      0.128                  (-888.4, 4778.0)
    cos3_ct1_yearly     -160.8   1431.0      0.920                 (-3279.0, 2463.0)
    sin4_ct1_yearly     -903.4   1378.0      0.512                 (-3625.0, 1661.0)
    cos4_ct1_yearly     -403.2   1415.0      0.778                 (-3252.0, 2289.0)
    sin5_ct1_yearly    -1422.0   1380.0      0.304                 (-4085.0, 1127.0)
    cos5_ct1_yearly    -1450.0   1313.0      0.280                 (-3844.0, 1307.0)
    sin6_ct1_yearly      18.43   1317.0      0.984                 (-2571.0, 2504.0)
    cos6_ct1_yearly     2262.0   1143.0      0.050         .        (-59.03, 4435.0)
    sin7_ct1_yearly     -570.3   1191.0      0.622                 (-3212.0, 1503.0)
    cos7_ct1_yearly     -392.5   1117.0      0.738                 (-2564.0, 1821.0)
    sin8_ct1_yearly    -1046.0   1144.0      0.366                 (-3307.0, 1090.0)
    cos8_ct1_yearly      314.1   1086.0      0.802                 (-1871.0, 2532.0)
    sin9_ct1_yearly    -2537.0    988.1      0.020         *       (-4627.0, -544.2)
    cos9_ct1_yearly     1553.0   1027.0      0.128                  (-479.6, 3552.0)
   sin10_ct1_yearly      384.5   1009.0      0.708                 (-1418.0, 2499.0)
   cos10_ct1_yearly     1482.0   1014.0      0.150                  (-509.8, 3482.0)
   sin11_ct1_yearly     2064.0   1020.0      0.048         *         (17.38, 4025.0)
   cos11_ct1_yearly     -377.9   1067.0      0.694                 (-2440.0, 1763.0)
   sin12_ct1_yearly    -1793.0    995.6      0.072         .        (-3691.0, 165.0)
   cos12_ct1_yearly    -2747.0   1052.0      0.008        **       (-4841.0, -838.2)
   sin13_ct1_yearly     -926.8   1052.0      0.372                 (-3044.0, 1051.0)
   cos13_ct1_yearly     1072.0   1011.0      0.284                  (-740.1, 3323.0)
   sin14_ct1_yearly    -1079.0    977.8      0.266                  (-3156.0, 841.1)
   cos14_ct1_yearly     1292.0    973.0      0.192                  (-660.6, 3291.0)
   sin15_ct1_yearly     -10.76   1054.0      0.988                 (-2145.0, 1988.0)
   cos15_ct1_yearly     1135.0    925.1      0.216                  (-665.9, 2945.0)
   sin16_ct1_yearly    -2247.0   1052.0      0.030         *       (-4399.0, -310.8)
   cos16_ct1_yearly     -882.8    950.8      0.348                 (-2664.0, 1178.0)
   sin17_ct1_yearly      484.5    993.2      0.612                 (-1373.0, 2393.0)
   cos17_ct1_yearly      891.7   1075.0      0.392                 (-1134.0, 3038.0)
   sin18_ct1_yearly     -413.2   1004.0      0.658                 (-2368.0, 1469.0)
   cos18_ct1_yearly     -31.73    999.3      0.972                 (-2176.0, 1846.0)
   sin19_ct1_yearly     -696.1   1024.0      0.470                 (-2759.0, 1260.0)
   cos19_ct1_yearly     -785.3    999.7      0.424                 (-2681.0, 1300.0)
   sin20_ct1_yearly     1262.0    994.0      0.190                  (-495.8, 3362.0)
   cos20_ct1_yearly      359.5    975.3      0.728                 (-1411.0, 2246.0)
   sin21_ct1_yearly    -1148.0   1008.0      0.248                 (-2960.0, 1033.0)
   cos21_ct1_yearly     -670.7   1032.0      0.510                 (-2661.0, 1380.0)
   sin22_ct1_yearly     1086.0    994.8      0.258                 (-1063.0, 2852.0)
   cos22_ct1_yearly      421.2   1043.0      0.690                 (-1613.0, 2400.0)
   sin23_ct1_yearly      409.4    982.8      0.696                 (-1507.0, 2184.0)
   cos23_ct1_yearly    -3170.0   1067.0      0.002        **       (-5033.0, -861.8)
   sin24_ct1_yearly    -1020.0   1010.0      0.304                  (-3120.0, 898.3)
   cos24_ct1_yearly     -452.9   1011.0      0.618                 (-2583.0, 1465.0)
   sin25_ct1_yearly    -2412.0    986.7      0.024         *       (-4345.0, -524.9)
   cos25_ct1_yearly      349.5   1070.0      0.736                 (-1794.0, 2431.0)
  cp0_2012_01_30_00     2834.0   7129.0      0.682           (-1.094e+04, 1.650e+04)
  cp1_2013_01_14_00 -1.253e+04   7642.0      0.088         .    (-2.763e+04, 2621.0)
  cp2_2015_02_23_00    -1701.0   4805.0      0.708              (-1.228e+04, 7189.0)
  cp3_2017_10_02_00 -1.108e+04   2800.0     <2e-16       ***   (-1.639e+04, -5535.0)
             y_lag1  2.380e+04   5576.0     <2e-16       ***  (1.343e+04, 3.530e+04)
             y_lag2  1.217e+04   5679.0      0.030         *      (735.7, 2.241e+04)
             y_lag3  1.001e+04   5352.0      0.066         .     (-993.6, 2.098e+04)
Signif. Code: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Multiple R-squared: 0.9265,   Adjusted R-squared: 0.9139
F-statistic: 73.444 on 67 and 397 DF,   p-value: 1.110e-16
Model AIC: 11212.0,   model BIC: 11498.0

WARNING: the condition number is large, 1.08e+05. This might indicate that there are strong multicollinearity or other numerical problems.
WARNING: the F-ratio and its p-value on regularized methods might be misleading, they are provided only for reference purposes.
, ============================ Forecast Model Summary ============================

Number of observations: 466,   Number of features: 71
Method: Ridge regression
Number of nonzero features: 71
Regularization parameter: 0.0621

Residuals:
         Min           1Q       Median           3Q          Max
  -2.845e+04      -3677.0        385.2       4356.0    1.959e+04

           Pred_col   Estimate Std. Err Pr(>)_boot sig. code                    95%CI
          Intercept  1.081e+04   4600.0      0.028         *      (3784.0, 2.249e+04)
                ct1  1.641e+04   5828.0      0.004        **      (5447.0, 2.811e+04)
ct1:C(mo... 13)))_2     -370.3   6138.0      0.942            (-1.318e+04, 1.178e+04)
ct1:C(mo... 13)))_3     4962.0   6131.0      0.396               (-6087.0, 1.851e+04)
ct1:C(mo... 13)))_4  2.512e+04   5131.0     <2e-16       ***   (1.500e+04, 3.481e+04)
ct1:C(mo... 13)))_5  1.566e+04   5796.0      0.010         *      (3645.0, 2.590e+04)
ct1:C(mo... 13)))_6  2.458e+04   5153.0     <2e-16       ***   (1.360e+04, 3.436e+04)
ct1:C(mo... 13)))_7  2.551e+04   5490.0     <2e-16       ***   (1.322e+04, 3.570e+04)
ct1:C(mo... 13)))_8  2.564e+04   5563.0     <2e-16       ***   (1.472e+04, 3.580e+04)
ct1:C(mo... 13)))_9  1.826e+04   6216.0      0.004        **      (5272.0, 3.037e+04)
ct1:C(mo...13)))_10  1.944e+04   5500.0     <2e-16       ***      (8143.0, 3.020e+04)
ct1:C(mo...13)))_11     -402.0   5249.0      0.938            (-1.036e+04, 1.029e+04)
ct1:C(mo...13)))_12      649.1   5550.0      0.910            (-1.039e+04, 1.099e+04)
            ct_sqrt  3.508e+04   7275.0     <2e-16       ***   (1.981e+04, 4.743e+04)
    sin1_ct1_yearly -1.474e+04   2016.0     <2e-16       *** (-1.853e+04, -1.113e+04)
    cos1_ct1_yearly     3027.0   1723.0      0.076         .         (-373.4, 6246.0)
    sin2_ct1_yearly     3383.0   1486.0      0.030         *          (710.4, 6418.0)
    cos2_ct1_yearly     5267.0   1609.0      0.002        **         (2249.0, 8625.0)
    sin3_ct1_yearly     2135.0   1479.0      0.156                   (-932.8, 4982.0)
    cos3_ct1_yearly     -350.5   1438.0      0.826                  (-3238.0, 2493.0)
    sin4_ct1_yearly     -665.1   1360.0      0.614                  (-3415.0, 2020.0)
    cos4_ct1_yearly     -669.7   1413.0      0.612                  (-3335.0, 2471.0)
    sin5_ct1_yearly    -1646.0   1422.0      0.250                  (-4508.0, 1118.0)
    cos5_ct1_yearly    -1388.0   1368.0      0.312                  (-3973.0, 1545.0)
    sin6_ct1_yearly     -82.52   1318.0      0.958                  (-2706.0, 2433.0)
    cos6_ct1_yearly     2357.0   1146.0      0.048         *          (205.7, 4772.0)
    sin7_ct1_yearly     -591.4   1280.0      0.634                  (-3055.0, 2009.0)
    cos7_ct1_yearly     -571.0   1059.0      0.590                  (-2842.0, 1414.0)
    sin8_ct1_yearly    -1370.0   1175.0      0.242                   (-3796.0, 690.6)
    cos8_ct1_yearly      438.5   1054.0      0.676                  (-1492.0, 2422.0)
    sin9_ct1_yearly    -2511.0   1068.0      0.016         *        (-4490.0, -427.8)
    cos9_ct1_yearly     2370.0   1149.0      0.038         *          (240.0, 4603.0)
   sin10_ct1_yearly      767.9   1017.0      0.450                  (-1182.0, 2667.0)
   cos10_ct1_yearly     1622.0    979.7      0.104                   (-282.5, 3460.0)
   sin11_ct1_yearly     2459.0   1017.0      0.020         *          (605.2, 4416.0)
   cos11_ct1_yearly     -712.9   1040.0      0.450                  (-2948.0, 1496.0)
   sin12_ct1_yearly    -2496.0    982.2      0.018         *        (-4417.0, -622.9)
   cos12_ct1_yearly    -2554.0   1029.0      0.014         *        (-4593.0, -456.8)
   sin13_ct1_yearly     -464.0    951.0      0.604                  (-2224.0, 1440.0)
   cos13_ct1_yearly     1258.0   1042.0      0.230                   (-648.3, 3424.0)
   sin14_ct1_yearly     -833.4    949.1      0.360                  (-2798.0, 1032.0)
   cos14_ct1_yearly     1381.0   1020.0      0.196                   (-702.2, 3212.0)
   sin15_ct1_yearly      256.7   1026.0      0.782                  (-1771.0, 2093.0)
   cos15_ct1_yearly     1171.0   1004.0      0.250                   (-732.6, 3146.0)
   sin16_ct1_yearly    -2512.0    985.9      0.020         *        (-4333.0, -545.7)
   cos16_ct1_yearly     -483.9   1065.0      0.658                  (-2461.0, 1762.0)
   sin17_ct1_yearly      730.2   1045.0      0.490                  (-1250.0, 2721.0)
   cos17_ct1_yearly      778.5   1028.0      0.416                  (-1246.0, 2883.0)
   sin18_ct1_yearly     -699.5   1014.0      0.484                  (-2701.0, 1179.0)
   cos18_ct1_yearly      272.6    971.2      0.794                  (-1549.0, 2150.0)
   sin19_ct1_yearly     -664.3   1063.0      0.520                  (-2809.0, 1229.0)
   cos19_ct1_yearly     -601.2   1029.0      0.598                  (-2583.0, 1369.0)
   sin20_ct1_yearly     1087.0   1003.0      0.270                   (-797.6, 3258.0)
   cos20_ct1_yearly      252.7    961.6      0.804                  (-1543.0, 2176.0)
   sin21_ct1_yearly     -908.7   1028.0      0.362                  (-2927.0, 1126.0)
   cos21_ct1_yearly     -453.1    995.5      0.670                  (-2474.0, 1506.0)
   sin22_ct1_yearly      922.5    938.1      0.316                   (-978.1, 2752.0)
   cos22_ct1_yearly      129.3   1090.0      0.874                  (-1977.0, 2157.0)
   sin23_ct1_yearly      247.3    983.8      0.798                  (-1791.0, 2132.0)
   cos23_ct1_yearly    -2725.0   1045.0      0.012         *        (-4628.0, -606.4)
   sin24_ct1_yearly     -933.8    953.4      0.336                  (-2709.0, 1012.0)
   cos24_ct1_yearly     -348.9   1043.0      0.746                  (-2350.0, 1669.0)
   sin25_ct1_yearly    -1887.0   1061.0      0.066         .        (-4052.0, -23.37)
   cos25_ct1_yearly      142.6   1002.0      0.884                  (-1857.0, 2170.0)
  cp0_2012_01_30_00     2893.0   8029.0      0.708            (-1.162e+04, 1.871e+04)
  cp1_2013_01_14_00 -1.565e+04   8014.0      0.052         .      (-3.100e+04, 50.78)
  cp2_2015_02_23_00    -1969.0   4917.0      0.662               (-1.202e+04, 7630.0)
  cp3_2017_10_02_00 -1.377e+04   2908.0     <2e-16       ***    (-1.931e+04, -7384.0)
             y_lag2  1.841e+04   5371.0     <2e-16       ***      (8588.0, 2.951e+04)
             y_lag3  1.335e+04   5284.0      0.008        **      (3514.0, 2.340e+04)
             y_lag4      384.1   5292.0      0.962               (-9298.0, 1.104e+04)
Signif. Code: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Multiple R-squared: 0.9225,   Adjusted R-squared: 0.9092
F-statistic: 69.268 on 67 and 397 DF,   p-value: 1.110e-16
Model AIC: 11236.0,   model BIC: 11522.0

WARNING: the condition number is large, 1.08e+05. This might indicate that there are strong multicollinearity or other numerical problems.
WARNING: the F-ratio and its p-value on regularized methods might be misleading, they are provided only for reference purposes.
, ============================ Forecast Model Summary ============================

Number of observations: 466,   Number of features: 71
Method: Ridge regression
Number of nonzero features: 71
Regularization parameter: 0.0621

Residuals:
         Min           1Q       Median           3Q          Max
  -2.803e+04      -3780.0        295.0       4331.0    2.130e+04

           Pred_col   Estimate Std. Err Pr(>)_boot sig. code                    95%CI
          Intercept  1.174e+04   4984.0      0.024         *      (2982.0, 2.296e+04)
                ct1  1.729e+04   5615.0     <2e-16       ***      (7796.0, 2.858e+04)
ct1:C(mo... 13)))_2     1405.0   6194.0      0.812            (-1.150e+04, 1.247e+04)
ct1:C(mo... 13)))_3     7198.0   6036.0      0.232               (-5084.0, 1.839e+04)
ct1:C(mo... 13)))_4  2.871e+04   5331.0     <2e-16       ***   (1.768e+04, 3.918e+04)
ct1:C(mo... 13)))_5  1.782e+04   5975.0      0.006        **      (5232.0, 2.869e+04)
ct1:C(mo... 13)))_6  2.810e+04   5098.0     <2e-16       ***   (1.730e+04, 3.814e+04)
ct1:C(mo... 13)))_7  2.890e+04   5249.0     <2e-16       ***   (1.877e+04, 3.895e+04)
ct1:C(mo... 13)))_8  2.861e+04   5334.0     <2e-16       ***   (1.740e+04, 3.822e+04)
ct1:C(mo... 13)))_9  2.073e+04   5726.0      0.002        **      (8806.0, 3.173e+04)
ct1:C(mo...13)))_10  2.231e+04   5404.0      0.002        **   (1.145e+04, 3.161e+04)
ct1:C(mo...13)))_11      132.7   5662.0      0.982            (-1.143e+04, 1.122e+04)
ct1:C(mo...13)))_12     1278.0   5283.0      0.806            (-1.063e+04, 1.024e+04)
            ct_sqrt  3.670e+04   7374.0     <2e-16       ***   (2.206e+04, 4.924e+04)
    sin1_ct1_yearly -1.623e+04   1828.0     <2e-16       *** (-1.975e+04, -1.273e+04)
    cos1_ct1_yearly     2976.0   1749.0      0.082         .         (-507.5, 6304.0)
    sin2_ct1_yearly     3903.0   1506.0      0.014         *          (939.3, 6640.0)
    cos2_ct1_yearly     5873.0   1658.0     <2e-16       ***         (2994.0, 9216.0)
    sin3_ct1_yearly     1995.0   1606.0      0.192                  (-1238.0, 5086.0)
    cos3_ct1_yearly     -385.0   1512.0      0.782                  (-3547.0, 2413.0)
    sin4_ct1_yearly     -256.7   1473.0      0.858                  (-3284.0, 2675.0)
    cos4_ct1_yearly    -1006.0   1421.0      0.480                  (-3905.0, 1555.0)
    sin5_ct1_yearly    -2232.0   1453.0      0.116                   (-5099.0, 460.0)
    cos5_ct1_yearly    -1400.0   1308.0      0.290                  (-3902.0, 1138.0)
    sin6_ct1_yearly     -94.22   1409.0      0.954                  (-2653.0, 2814.0)
    cos6_ct1_yearly     1961.0   1129.0      0.086         .         (-560.9, 3998.0)
    sin7_ct1_yearly     -576.8   1259.0      0.628                  (-3022.0, 1795.0)
    cos7_ct1_yearly     -366.1   1029.0      0.720                  (-2375.0, 1588.0)
    sin8_ct1_yearly    -1574.0   1177.0      0.186                   (-3561.0, 747.6)
    cos8_ct1_yearly      846.0   1076.0      0.396                  (-1323.0, 3011.0)
    sin9_ct1_yearly    -1734.0   1136.0      0.134                   (-3900.0, 445.8)
    cos9_ct1_yearly     2571.0   1206.0      0.028         *          (404.8, 4956.0)
   sin10_ct1_yearly      936.5   1099.0      0.400                  (-1260.0, 2961.0)
   cos10_ct1_yearly     1333.0   1029.0      0.184                   (-805.2, 3277.0)
   sin11_ct1_yearly     2276.0   1060.0      0.038         *           (67.6, 4196.0)
   cos11_ct1_yearly     -887.5   1012.0      0.354                  (-2890.0, 1125.0)
   sin12_ct1_yearly    -2133.0   1014.0      0.036         *        (-4230.0, -353.8)
   cos12_ct1_yearly    -2129.0    995.4      0.038         *        (-4129.0, -113.5)
   sin13_ct1_yearly     -311.7   1044.0      0.774                  (-2383.0, 1679.0)
   cos13_ct1_yearly      806.0   1024.0      0.468                  (-1022.0, 2892.0)
   sin14_ct1_yearly     -983.8    953.3      0.306                   (-2756.0, 963.2)
   cos14_ct1_yearly     1091.0   1114.0      0.336                  (-1094.0, 3288.0)
   sin15_ct1_yearly      138.3   1064.0      0.908                  (-1903.0, 2138.0)
   cos15_ct1_yearly     1151.0    989.0      0.260                   (-667.7, 3143.0)
   sin16_ct1_yearly    -2434.0   1085.0      0.022         *        (-4717.0, -514.0)
   cos16_ct1_yearly     -554.2    996.2      0.584                  (-2382.0, 1407.0)
   sin17_ct1_yearly      657.1   1035.0      0.524                  (-1430.0, 2628.0)
   cos17_ct1_yearly      765.6   1012.0      0.452                  (-1272.0, 2803.0)
   sin18_ct1_yearly     -705.3    981.8      0.474                  (-2550.0, 1305.0)
   cos18_ct1_yearly      471.5   1037.0      0.640                  (-1426.0, 2638.0)
   sin19_ct1_yearly     -460.8   1029.0      0.644                  (-2576.0, 1443.0)
   cos19_ct1_yearly     -671.8   1104.0      0.516                  (-2846.0, 1381.0)
   sin20_ct1_yearly     1066.0   1078.0      0.324                   (-981.9, 3212.0)
   cos20_ct1_yearly      441.2   1040.0      0.658                  (-1465.0, 2548.0)
   sin21_ct1_yearly     -826.5   1012.0      0.388                  (-2889.0, 1156.0)
   cos21_ct1_yearly     -657.0   1031.0      0.524                  (-2717.0, 1361.0)
   sin22_ct1_yearly      867.5    979.8      0.384                  (-1158.0, 2674.0)
   cos22_ct1_yearly      350.7   1128.0      0.766                  (-1820.0, 2476.0)
   sin23_ct1_yearly      802.0   1010.0      0.426                  (-1224.0, 2783.0)
   cos23_ct1_yearly    -3043.0   1017.0      0.004        **       (-4944.0, -1001.0)
   sin24_ct1_yearly    -1033.0   1080.0      0.354                  (-3074.0, 1076.0)
   cos24_ct1_yearly     -523.5   1032.0      0.620                  (-2548.0, 1597.0)
   sin25_ct1_yearly    -2544.0   1016.0      0.012         *        (-4496.0, -561.2)
   cos25_ct1_yearly      49.26   1060.0      0.956                  (-2096.0, 2181.0)
  cp0_2012_01_30_00     2950.0   8463.0      0.736            (-1.544e+04, 2.014e+04)
  cp1_2013_01_14_00 -1.687e+04   8319.0      0.034         *     (-3.204e+04, -576.2)
  cp2_2015_02_23_00    -2182.0   5376.0      0.702               (-1.387e+04, 7403.0)
  cp3_2017_10_02_00 -1.481e+04   2898.0     <2e-16       ***    (-2.015e+04, -8744.0)
             y_lag3  1.671e+04   5537.0     <2e-16       ***      (5887.0, 2.756e+04)
             y_lag4      553.5   5284.0      0.916                 (-10000.0, 9912.0)
             y_lag5  1.004e+04   4860.0      0.038         *      (-72.56, 1.907e+04)
Signif. Code: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Multiple R-squared: 0.9208,   Adjusted R-squared: 0.9072
F-statistic: 67.654 on 67 and 397 DF,   p-value: 1.110e-16
Model AIC: 11246.0,   model BIC: 11532.0

WARNING: the condition number is large, 1.08e+05. This might indicate that there are strong multicollinearity or other numerical problems.
WARNING: the F-ratio and its p-value on regularized methods might be misleading, they are provided only for reference purposes.
, ============================ Forecast Model Summary ============================

Number of observations: 466,   Number of features: 71
Method: Ridge regression
Number of nonzero features: 71
Regularization parameter: 0.02807

Residuals:
         Min           1Q       Median           3Q          Max
  -2.844e+04      -3736.0        448.2       4182.0    2.170e+04

           Pred_col   Estimate  Std. Err Pr(>)_boot sig. code                    95%CI
          Intercept  1.167e+04    5812.0      0.036         *      (2165.0, 2.427e+04)
                ct1  1.785e+04 1.136e+04      0.126               (-3145.0, 4.145e+04)
ct1:C(mo... 13)))_2     2556.0    6260.0      0.674            (-1.066e+04, 1.363e+04)
ct1:C(mo... 13)))_3     9731.0    6288.0      0.130               (-3826.0, 2.137e+04)
ct1:C(mo... 13)))_4  3.373e+04    5462.0     <2e-16       ***   (2.174e+04, 4.325e+04)
ct1:C(mo... 13)))_5  2.337e+04    6325.0     <2e-16       ***   (1.010e+04, 3.502e+04)
ct1:C(mo... 13)))_6  3.428e+04    5209.0     <2e-16       ***   (2.376e+04, 4.345e+04)
ct1:C(mo... 13)))_7  3.618e+04    5563.0     <2e-16       ***   (2.389e+04, 4.756e+04)
ct1:C(mo... 13)))_8  3.622e+04    5351.0     <2e-16       ***   (2.481e+04, 4.609e+04)
ct1:C(mo... 13)))_9  2.771e+04    6198.0     <2e-16       ***   (1.559e+04, 3.911e+04)
ct1:C(mo...13)))_10  2.884e+04    5779.0     <2e-16       ***   (1.693e+04, 3.897e+04)
ct1:C(mo...13)))_11     5801.0    6126.0      0.348               (-6614.0, 1.724e+04)
ct1:C(mo...13)))_12     3647.0    5143.0      0.472               (-7323.0, 1.249e+04)
            ct_sqrt  4.639e+04 1.007e+04     <2e-16       ***   (2.637e+04, 6.435e+04)
    sin1_ct1_yearly -1.796e+04    1988.0     <2e-16       *** (-2.227e+04, -1.453e+04)
    cos1_ct1_yearly     4496.0    1916.0      0.018         *          (788.1, 8525.0)
    sin2_ct1_yearly     4660.0    1600.0      0.002        **         (1655.0, 7873.0)
    cos2_ct1_yearly     5335.0    1598.0     <2e-16       ***         (2445.0, 8476.0)
    sin3_ct1_yearly     1819.0    1538.0      0.230                  (-1286.0, 4860.0)
    cos3_ct1_yearly     -139.4    1582.0      0.932                  (-3409.0, 2643.0)
    sin4_ct1_yearly     -144.7    1544.0      0.948                  (-3184.0, 2761.0)
    cos4_ct1_yearly    -1255.0    1438.0      0.358                  (-4234.0, 1482.0)
    sin5_ct1_yearly    -2204.0    1411.0      0.114                   (-4902.0, 287.5)
    cos5_ct1_yearly    -1147.0    1341.0      0.374                  (-3660.0, 1490.0)
    sin6_ct1_yearly     -262.0    1385.0      0.818                  (-2680.0, 2735.0)
    cos6_ct1_yearly     1650.0    1160.0      0.142                   (-623.3, 3728.0)
    sin7_ct1_yearly     -376.6    1243.0      0.764                  (-3064.0, 1731.0)
    cos7_ct1_yearly     -280.6    1119.0      0.796                  (-2494.0, 2038.0)
    sin8_ct1_yearly    -1639.0    1215.0      0.178                   (-4204.0, 532.2)
    cos8_ct1_yearly      933.8    1090.0      0.374                  (-1058.0, 3235.0)
    sin9_ct1_yearly    -1453.0    1115.0      0.182                   (-3722.0, 686.2)
    cos9_ct1_yearly     2266.0    1125.0      0.042         *          (277.2, 4501.0)
   sin10_ct1_yearly      826.0    1059.0      0.424                  (-1145.0, 2850.0)
   cos10_ct1_yearly     1374.0    1041.0      0.180                   (-602.8, 3418.0)
   sin11_ct1_yearly     2407.0     995.7      0.008        **          (565.7, 4375.0)
   cos11_ct1_yearly     -786.0    1000.0      0.414                  (-2821.0, 1113.0)
   sin12_ct1_yearly    -1690.0    1027.0      0.102                   (-3697.0, 198.3)
   cos12_ct1_yearly    -2128.0    1016.0      0.040         *        (-4110.0, -110.1)
   sin13_ct1_yearly     -512.2    1040.0      0.606                  (-2584.0, 1512.0)
   cos13_ct1_yearly      277.1    1007.0      0.772                  (-1598.0, 2409.0)
   sin14_ct1_yearly    -1453.0    1026.0      0.180                   (-3369.0, 553.9)
   cos14_ct1_yearly     1027.0    1027.0      0.324                   (-851.0, 2978.0)
   sin15_ct1_yearly     -11.37    1106.0      0.990                  (-2177.0, 2042.0)
   cos15_ct1_yearly     1352.0    1029.0      0.170                   (-624.6, 3455.0)
   sin16_ct1_yearly    -2544.0    1068.0      0.020         *        (-4722.0, -455.1)
   cos16_ct1_yearly     -857.2    1146.0      0.426                  (-3051.0, 1415.0)
   sin17_ct1_yearly      743.2    1078.0      0.490                  (-1316.0, 2829.0)
   cos17_ct1_yearly      887.1    1046.0      0.404                  (-1243.0, 2975.0)
   sin18_ct1_yearly     -719.1    1009.0      0.444                  (-2683.0, 1334.0)
   cos18_ct1_yearly      346.5    1019.0      0.742                  (-1665.0, 2323.0)
   sin19_ct1_yearly     -632.6    1052.0      0.568                  (-2679.0, 1318.0)
   cos19_ct1_yearly     -719.2    1038.0      0.496                  (-2759.0, 1278.0)
   sin20_ct1_yearly     1077.0    1061.0      0.290                   (-857.7, 3210.0)
   cos20_ct1_yearly      254.7    1034.0      0.840                  (-1549.0, 2420.0)
   sin21_ct1_yearly     -907.9     982.4      0.354                  (-2823.0, 1040.0)
   cos21_ct1_yearly     -420.9     977.1      0.642                  (-2239.0, 1475.0)
   sin22_ct1_yearly      968.5    1034.0      0.366                  (-1185.0, 2800.0)
   cos22_ct1_yearly      213.5    1033.0      0.842                  (-1627.0, 2244.0)
   sin23_ct1_yearly      593.9    1004.0      0.516                  (-1446.0, 2689.0)
   cos23_ct1_yearly    -2913.0    1104.0      0.008        **        (-5080.0, -840.9)
   sin24_ct1_yearly    -1020.0    1104.0      0.376                  (-3167.0, 1084.0)
   cos24_ct1_yearly     -433.4    1025.0      0.650                  (-2466.0, 1655.0)
   sin25_ct1_yearly    -2270.0    1081.0      0.032         *        (-4328.0, -187.4)
   cos25_ct1_yearly     -60.41    1040.0      0.952                  (-2030.0, 2085.0)
  cp0_2012_01_30_00     2899.0 1.147e+04      0.808            (-1.886e+04, 2.480e+04)
  cp1_2013_01_14_00 -2.130e+04 1.060e+04      0.042         *     (-4.188e+04, -276.8)
  cp2_2015_02_23_00    -1575.0    5732.0      0.794               (-1.266e+04, 9256.0)
  cp3_2017_10_02_00 -1.748e+04    3190.0     <2e-16       *** (-2.323e+04, -1.128e+04)
             y_lag4     4134.0    5552.0      0.456               (-6306.0, 1.513e+04)
             y_lag5  1.226e+04    4987.0      0.012         *      (1466.0, 2.086e+04)
             y_lag6    -2743.0    5746.0      0.612               (-1.367e+04, 9100.0)
Signif. Code: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Multiple R-squared: 0.9193,   Adjusted R-squared: 0.9054
F-statistic: 65.708 on 68 and 396 DF,   p-value: 1.110e-16
Model AIC: 11256.0,   model BIC: 11545.0

WARNING: the condition number is large, 2.17e+05. This might indicate that there are strong multicollinearity or other numerical problems.
WARNING: the F-ratio and its p-value on regularized methods might be misleading, they are provided only for reference purposes.
]
================================= CV Results ==================================
                                                                              0
rank_test_MAPE                                                                1
mean_test_MAPE                                                            10.34
split_test_MAPE                          (10.34, 15.4, 6.67, 11.39, 9.49, 8.78)
mean_train_MAPE                                                           15.57
split_train_MAPE                      (15.68, 15.65, 15.63, 15.54, 15.5, 15.44)
mean_fit_time                                                             18.89
mean_score_time                                                            1.01
param_estimator__auto_holiday_params                                       None
params                                                                       []
=========================== Train/Test Evaluation =============================
                                                              train             test
CORR                                                       0.958442         0.927707
R2                                                         0.918606        -1.017877
MSE                                                 49536598.782839  34669900.692205
RMSE                                                    7038.224121      5888.115207
MAE                                                     5322.253903      4775.374732
MedAE                                                   4027.174276      4324.400695
MAPE                                                      15.377647         6.111202
MedAPE                                                     8.106217         5.450027
sMAPE                                                      7.197916         2.917224
Q80                                                     2661.126952       955.074946
Q95                                                     2661.126952       238.768737
Q99                                                     2661.126952        47.753747
OutsideTolerance1p                                         0.950216              1.0
OutsideTolerance2p                                         0.880952             0.75
OutsideTolerance3p                                         0.829004              0.5
OutsideTolerance4p                                         0.774892              0.5
OutsideTolerance5p                                         0.679654              0.5
Outside Tolerance (fraction)                                   None             None
R2_null_model_score                                            None             None
Prediction Band Width (%)                                  91.11172        40.784758
Prediction Band Coverage (fraction)                        0.963203              1.0
Coverage: Lower Band                                       0.448052              1.0
Coverage: Upper Band                                       0.515152              0.0
Coverage Diff: Actual_Coverage - Intended_Coverage         0.013203             0.05
MIS                                                    38199.341036     33020.871899

Fit/backtest plot:

414 fig = result.backtest.plot()
415 plotly.io.show(fig)

Forecast plot:

419 fig = result.forecast.plot()
420 plotly.io.show(fig)

The components plot:

424 figs = result.forecast.plot_components()
425 for fig in figs:
426     plotly.io.show(fig)

Total running time of the script: ( 5 minutes 5.645 seconds)

Gallery generated by Sphinx-Gallery