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 from collections import defaultdict
28 import warnings
29
30 warnings.filterwarnings("ignore")
31
32 import pandas as pd
33 import plotly
34
35 from greykite.common.data_loader import DataLoader
36 from greykite.framework.templates.autogen.forecast_config import ForecastConfig
37 from greykite.framework.templates.autogen.forecast_config import MetadataParam
38 from greykite.framework.templates.forecaster import Forecaster
39 from greykite.framework.templates.model_templates import ModelTemplateEnum
40 from greykite.framework.utils.result_summary import summarize_grid_search_results
41
42 # Loads dataset into pandas DataFrame
43 dl = DataLoader()
44 df = dl.load_peyton_manning()
45
46 # specify dataset information
47 metadata = MetadataParam(
48     time_col="ts",  # name of the time column ("date" in example above)
49     value_col="y",  # name of the value column ("sessions" in example above)
50     freq="D"  # "H" for hourly, "D" for daily, "W" for weekly, etc.
51               # Any format accepted by `pandas.date_range`
52 )

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 forecaster = Forecaster()  # Creates forecasts and stores the result
65 result = forecaster.run_forecast_config(  # result is also stored as `forecaster.forecast_result`.
66     df=df,
67     config=ForecastConfig(
68         model_template=ModelTemplateEnum.AUTO.name,
69         forecast_horizon=365,  # forecasts 365 steps ahead
70         coverage=0.95,         # 95% prediction intervals
71         metadata_param=metadata
72     )
73 )

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 ts = result.timeseries
90 fig = ts.plot()
91 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 grid_search = result.grid_search
110 cv_results = summarize_grid_search_results(
111     grid_search=grid_search,
112     decimals=2,
113     # The below saves space in the printed output. Remove to show all available metrics and columns.
114     cv_report_metrics=None,
115     column_order=["rank", "mean_test", "split_test", "mean_train", "split_train", "mean_fit_time", "mean_score_time", "params"])
116 # Transposes to save space in the printed output
117 cv_results["params"] = cv_results["params"].astype(str)
118 cv_results.set_index("params", drop=True, inplace=True)
119 cv_results.transpose()
params []
rank_test_MAPE 1
mean_test_MAPE 9.42
split_test_MAPE (11.18, 7.94, 9.14)
mean_train_MAPE 3.59
split_train_MAPE (2.97, 3.91, 3.88)
mean_fit_time 4.39
mean_score_time 1.15


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 backtest = result.backtest
127 fig = backtest.plot()
128 plotly.io.show(fig)

You can also check historical evaluation metrics (on the historical training/test set).

132 backtest_eval = defaultdict(list)
133 for metric, value in backtest.train_evaluation.items():
134     backtest_eval[metric].append(value)
135     backtest_eval[metric].append(backtest.test_evaluation[metric])
136 metrics = pd.DataFrame(backtest_eval, index=["train", "test"]).T
137 metrics
train test
CORR 0.839072 0.740281
R2 0.704038 0.470863
MSE 0.21158 0.270031
RMSE 0.459978 0.519645
MAE 0.330952 0.370574
MedAE 0.264489 0.31327
MAPE 3.939878 4.69518
MedAPE 3.240725 4.145243
sMAPE 1.974451 2.389867
Q80 0.165432 0.223393
Q95 0.165409 0.242446
Q99 0.165403 0.247527
OutsideTolerance1p 0.841463 0.856749
OutsideTolerance2p 0.676239 0.716253
OutsideTolerance3p 0.530685 0.606061
OutsideTolerance4p 0.400079 0.509642
OutsideTolerance5p 0.287175 0.37741
Outside Tolerance (fraction) None None
R2_null_model_score None None
Prediction Band Width (%) 23.228227 26.425585
Prediction Band Coverage (fraction) 0.959087 0.966942
Coverage: Lower Band 0.532258 0.360882
Coverage: Upper Band 0.426829 0.606061
Coverage Diff: Actual_Coverage - Intended_Coverage 0.009087 0.016942
MIS 2.645379 2.952778


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 forecast = result.forecast
148 fig = forecast.plot()
149 plotly.io.show(fig)

The forecasted values are available in df.

153 forecast.df.head().round(2)
ts actual forecast forecast_lower forecast_upper
0 2007-12-10 9.59 9.34 7.84 10.84
1 2007-12-11 8.52 8.35 7.31 9.39
2 2007-12-12 8.18 7.95 7.08 8.82
3 2007-12-13 8.07 7.69 6.79 8.59
4 2007-12-14 7.89 7.65 6.68 8.63


Model Diagnostics

The component plot shows how your dataset’s trend, seasonality, event / holiday and other patterns are handled in the model. When called, with defaults, function displays three plots: 1) components of the model, 2) linear trend and changepoints, and 3) the residuals of the model and smoothed estimates of the residuals. By clicking different legend entries, the visibility of lines in each plot can be toggled on or off.

164 fig = forecast.plot_components()
165 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.

171 summary = result.model[-1].summary()  # -1 retrieves the estimator from the pipeline
172 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.285      -0.2706     -0.04415       0.1896        3.493

            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.09797   0.1695   0.5779    0.563              (-0.2345, 0.4304)
 events_C...w Year-1    -0.1061    0.185  -0.5733    0.566              (-0.4689, 0.2567)
 events_C...w Year-2    0.07617   0.1485    0.513    0.608               (-0.215, 0.3673)
 events_C...w Year+1    0.06588    0.185   0.3561    0.722              (-0.2968, 0.4286)
 events_C...w Year+2     0.1726   0.1483    1.163    0.245              (-0.1183, 0.4634)
events_Christmas Day    -0.5242   0.1745   -3.003    0.003        **   (-0.8664, -0.1819)
 events_C...as Day-1    -0.2812    0.174   -1.616    0.106             (-0.6224, 0.06001)
 events_C...as Day-2   -0.07288   0.1727  -0.4221    0.673              (-0.4114, 0.2657)
 events_C...as Day+1    -0.3112   0.1748    -1.78    0.075         .   (-0.6539, 0.03156)
 events_C...as Day+2     0.1857   0.1742    1.066    0.287              (-0.1559, 0.5273)
 events_E...Ireland]    -0.2971   0.1738   -1.709    0.088         .   (-0.6379, 0.04377)
 events_E...eland]-1    -0.1327  0.08692   -1.527    0.127             (-0.3031, 0.03775)
 events_E...eland]-2   -0.06678  0.08793  -0.7595    0.448              (-0.2392, 0.1056)
 events_E...eland]+1    -0.1274   0.1737  -0.7335    0.463               (-0.468, 0.2132)
 events_E...eland]+2   -0.02439   0.1722  -0.1416    0.887               (-0.362, 0.3133)
  events_Good Friday    -0.1945   0.1745   -1.114    0.265              (-0.5368, 0.1477)
events_Good Friday-1    -0.1127   0.1725  -0.6531    0.514              (-0.4509, 0.2256)
events_Good Friday-2   -0.02749   0.1727  -0.1592    0.874              (-0.3662, 0.3112)
events_Good Friday+1   -0.06678  0.08793  -0.7595    0.448              (-0.2392, 0.1056)
events_Good Friday+2    -0.1327  0.08692   -1.527    0.127             (-0.3031, 0.03775)
 events_I...ence Day    0.07398   0.1246    0.594    0.553              (-0.1703, 0.3182)
 events_I...ce Day-1    0.02949   0.1245    0.237    0.813              (-0.2145, 0.2735)
 events_I...ce Day-2   -0.04536   0.1244  -0.3646    0.715              (-0.2893, 0.1986)
 events_I...ce Day+1   -0.02739   0.1246  -0.2199    0.826              (-0.2716, 0.2169)
 events_I...ce Day+2   -0.04383   0.1244  -0.3524    0.725              (-0.2877, 0.2001)
    events_Labor Day    -0.3435   0.1236    -2.78    0.005        **   (-0.5859, -0.1012)
  events_Labor Day-1    -0.1277   0.1236   -1.033    0.302              (-0.3702, 0.1147)
  events_Labor Day-2   -0.05103   0.1236  -0.4129    0.680              (-0.2934, 0.1913)
  events_Labor Day+1    -0.2501   0.1236   -2.024    0.043         * (-0.4924, -0.007785)
  events_Labor Day+2     -0.264   0.1235   -2.137    0.033         *  (-0.5061, -0.02181)
 events_Memorial Day    -0.3549   0.1749    -2.03    0.042         *  (-0.6978, -0.01203)
 events_M...al Day-1    -0.1862   0.1748   -1.065    0.287               (-0.529, 0.1566)
 events_M...al Day-2    0.05332   0.1746   0.3054    0.760               (-0.289, 0.3957)
 events_M...al Day+1    0.03209   0.1749   0.1835    0.854              (-0.3109, 0.3751)
 events_M...al Day+2     0.3282   0.1749    1.876    0.061         .   (-0.01479, 0.6713)
events_New Years Day    -0.1015   0.1737  -0.5846    0.559              (-0.4422, 0.2391)
 events_N...rs Day-1     0.1406   0.1745   0.8056    0.421              (-0.2016, 0.4827)
 events_N...rs Day-2      0.382   0.1739    2.197    0.028         *    (0.04106, 0.7229)
 events_N...rs Day+1     0.3132   0.1721     1.82    0.069         .   (-0.02421, 0.6505)
 events_N...rs Day+2     0.3664   0.1709    2.143    0.032         *    (0.03121, 0.7016)
        events_Other  -0.002273  0.03038  -0.0748    0.940             (-0.06185, 0.0573)
      events_Other-1   0.003215  0.03003   0.1071    0.915             (-0.05567, 0.0621)
      events_Other-2    0.02355  0.02963   0.7948    0.427            (-0.03455, 0.08165)
      events_Other+1 -0.0008269  0.03039 -0.02721    0.978            (-0.06042, 0.05877)
      events_Other+2 -0.0009795  0.02972 -0.03295    0.974             (-0.05926, 0.0573)
 events_Thanksgiving    -0.1692   0.1761  -0.9604    0.337              (-0.5146, 0.1762)
 events_T...giving-1    -0.3575   0.1761    -2.03    0.042         *  (-0.7027, -0.01222)
 events_T...giving-2    -0.2172   0.1761   -1.233    0.218              (-0.5624, 0.1281)
 events_T...giving+1   -0.06851   0.1759  -0.3894    0.697              (-0.4135, 0.2765)
 events_T...giving+2    -0.1385   0.1756  -0.7884    0.431              (-0.4829, 0.2059)
 events_Veterans Day    -0.1303   0.1801  -0.7234    0.469              (-0.4835, 0.2229)
 events_V...ns Day-1    -0.1875   0.1796   -1.044    0.297              (-0.5396, 0.1646)
 events_V...ns Day-2    -0.1725   0.1791  -0.9634    0.335              (-0.5236, 0.1786)
 events_V...ns Day+1    -0.1148   0.1803  -0.6372    0.524              (-0.4683, 0.2386)
 events_V...ns Day+2    -0.1945   0.1801    -1.08    0.280              (-0.5478, 0.1587)
       str_dow_2-Tue   -0.06016   0.1392  -0.4322    0.666               (-0.333, 0.2127)
       str_dow_3-Wed   -0.01622   0.1423  -0.1139    0.909              (-0.2953, 0.2629)
       str_dow_4-Thu    -0.2363   0.1448   -1.632    0.103             (-0.5202, 0.04765)
       str_dow_5-Fri    -0.1255   0.1487  -0.8443    0.399               (-0.4171, 0.166)
       str_dow_6-Sat    -0.2567   0.1509   -1.701    0.089         .   (-0.5526, 0.03917)
       str_dow_7-Sun     0.7555   0.1629    4.638 3.68e-06       ***      (0.4361, 1.075)
                 ct1      26.65    8.076    3.299 9.82e-04       ***       (10.81, 42.48)
      is_weekend:ct1     -2.404      8.0  -0.3004    0.764                (-18.09, 13.28)
   str_dow_2-Tue:ct1      10.07     15.6   0.6456    0.519                (-20.52, 40.67)
   str_dow_3-Wed:ct1       10.4    12.15   0.8557    0.392                (-13.43, 34.22)
   str_dow_4-Thu:ct1      25.69     13.4    1.916    0.055         .     (-0.5959, 51.97)
   str_dow_5-Fri:ct1      15.88    13.55    1.172    0.241                (-10.69, 42.44)
   str_dow_6-Sat:ct1      15.64     12.9    1.212    0.225                (-9.655, 40.93)
   str_dow_7-Sun:ct1     -18.04    14.77   -1.221    0.222                 (-47.0, 10.92)
   cp0_2008_02_04_00     -32.87    8.749   -3.757 1.76e-04       ***     (-50.02, -15.71)
 is_weeke...02_04_00      3.752    8.603   0.4361    0.663                (-13.12, 20.62)
 str_dow_...02_04_00     -9.511    16.91  -0.5624    0.574                (-42.68, 23.65)
 str_dow_...02_04_00     -11.55    13.14   -0.879    0.379                (-37.31, 14.21)
 str_dow_...02_04_00     -24.96    14.47   -1.726    0.085         .        (-53.33, 3.4)
 str_dow_...02_04_00     -14.93    14.61   -1.022    0.307                (-43.57, 13.72)
 str_dow_...02_04_00     -14.93    13.86   -1.077    0.281                (-42.11, 12.25)
 str_dow_...02_04_00      18.68    15.86    1.177    0.239                (-12.43, 49.78)
   cp1_2008_09_15_00     -27.59    12.05   -2.289    0.022         *     (-51.22, -3.955)
 is_weeke...09_15_00     -13.19    11.02   -1.197    0.231                 (-34.79, 8.41)
 str_dow_...09_15_00     0.7006     23.2   0.0302    0.976                (-44.79, 46.19)
 str_dow_...09_15_00     -13.11    17.73  -0.7395    0.460                (-47.87, 21.65)
 str_dow_...09_15_00     -29.58    19.26   -1.536    0.125                (-67.34, 8.188)
 str_dow_...09_15_00     -28.59    19.12   -1.495    0.135                (-66.09, 8.901)
 str_dow_...09_15_00     -25.19    17.65   -1.427    0.154                (-59.81, 9.421)
 str_dow_...09_15_00      11.99    20.16   0.5949    0.552                (-27.54, 51.52)
   cp2_2008_10_13_00      39.07    13.91    2.809    0.005        **        (11.8, 66.35)
 is_weeke...10_13_00      15.16    12.67    1.196    0.232                (-9.691, 40.01)
 str_dow_...10_13_00     -5.871    26.72  -0.2198    0.826                (-58.26, 46.51)
 str_dow_...10_13_00      18.55     20.4    0.909    0.363                (-21.46, 58.55)
 str_dow_...10_13_00      36.39    22.17    1.642    0.101                (-7.076, 79.86)
 str_dow_...10_13_00      36.56     22.0    1.662    0.097         .       (-6.575, 79.7)
 str_dow_...10_13_00      29.49     20.3    1.453    0.146                 (-10.31, 69.3)
 str_dow_...10_13_00     -14.32    23.19  -0.6176    0.537                (-59.79, 31.15)
   cp3_2009_01_12_00     0.7521    4.072   0.1847    0.853                (-7.232, 8.736)
 is_weeke...01_12_00     -2.176     3.65  -0.5962    0.551                (-9.334, 4.981)
 str_dow_...01_12_00      6.293    7.695   0.8178    0.414                (-8.795, 21.38)
 str_dow_...01_12_00     -2.441    5.859  -0.4166    0.677                (-13.93, 9.048)
 str_dow_...01_12_00     -6.215    6.369  -0.9758    0.329                 (-18.7, 6.274)
 str_dow_...01_12_00     -8.428    6.329   -1.332    0.183                (-20.84, 3.983)
 str_dow_...01_12_00     -3.405    5.841   -0.583    0.560                (-14.86, 8.047)
 str_dow_...01_12_00      1.227    6.668   0.1841    0.854                 (-11.85, 14.3)
   cp4_2009_09_14_00     -6.071    3.237   -1.876    0.061         .     (-12.42, 0.2752)
 is_weeke...09_14_00      1.099    2.894   0.3799    0.704                (-4.575, 6.774)
 str_dow_...09_14_00     -6.719    6.047   -1.111    0.267                (-18.58, 5.138)
 str_dow_...09_14_00     -5.856    4.628   -1.265    0.206                (-14.93, 3.219)
 str_dow_...09_14_00     -5.817    5.035   -1.155    0.248                (-15.69, 4.055)
 str_dow_...09_14_00     -1.093    5.004  -0.2185    0.827                 (-10.9, 8.719)
 str_dow_...09_14_00     -3.835    4.617  -0.8307    0.406                (-12.89, 5.217)
 str_dow_...09_14_00      4.933    5.267   0.9366    0.349                (-5.395, 15.26)
   cp5_2009_12_28_00      9.123    10.42   0.8752    0.382                (-11.32, 29.56)
 is_weeke...12_28_00      2.467    9.374   0.2632    0.792                (-15.91, 20.85)
 str_dow_...12_28_00      19.56     19.6   0.9979    0.318                 (-18.88, 58.0)
 str_dow_...12_28_00      19.83     15.1    1.313    0.189                (-9.779, 49.43)
 str_dow_...12_28_00      29.97     16.4    1.828    0.068         .       (-2.18, 62.12)
 str_dow_...12_28_00       15.2     16.3   0.9324    0.351                (-16.77, 47.17)
 str_dow_...12_28_00       17.0    15.01    1.133    0.257                (-12.42, 46.43)
 str_dow_...12_28_00     -14.53    17.08  -0.8507    0.395                (-48.02, 18.96)
   cp6_2010_01_25_00     -10.58    8.525   -1.241    0.215                (-27.29, 6.139)
 is_weeke...01_25_00     -3.631     7.69  -0.4722    0.637                (-18.71, 11.45)
 str_dow_...01_25_00     -15.58     16.1  -0.9672    0.334                 (-47.15, 16.0)
 str_dow_...01_25_00     -15.67    12.38   -1.265    0.206                (-39.95, 8.609)
 str_dow_...01_25_00     -25.07    13.45   -1.864    0.062         .      (-51.43, 1.299)
 str_dow_...01_25_00     -14.67    13.38   -1.097    0.273                 (-40.9, 11.56)
 str_dow_...01_25_00     -14.66    12.31   -1.191    0.234                 (-38.8, 9.476)
 str_dow_...01_25_00      11.02    14.01   0.7866    0.432                 (-16.45, 38.5)
   cp7_2011_01_31_00      5.131    1.227     4.18 3.00e-05       ***       (2.724, 7.538)
 is_weeke...01_31_00      2.202    1.128    1.952    0.051         .    (-0.01002, 4.415)
 str_dow_...01_31_00     0.3269    2.381   0.1373    0.891                (-4.343, 4.996)
 str_dow_...01_31_00      2.495    1.806    1.382    0.167                (-1.046, 6.036)
 str_dow_...01_31_00      4.294    1.962    2.189    0.029         *      (0.4469, 8.141)
 str_dow_...01_31_00      3.501    1.955     1.79    0.074         .     (-0.3336, 7.335)
 str_dow_...01_31_00       3.02     1.81    1.668    0.095         .     (-0.5298, 6.569)
 str_dow_...01_31_00    -0.8158    2.068  -0.3945    0.693                 (-4.87, 3.239)
   cp8_2011_07_18_00     -8.517    2.895   -2.942    0.003        **      (-14.19, -2.84)
 is_weeke...07_18_00     -2.906    2.623   -1.108    0.268                 (-8.05, 2.237)
 str_dow_...07_18_00     0.8645    5.543    0.156    0.876                 (-10.0, 11.73)
 str_dow_...07_18_00     -6.878    4.215   -1.632    0.103                (-15.14, 1.387)
 str_dow_...07_18_00      -10.5    4.567   -2.299    0.022         *     (-19.45, -1.544)
 str_dow_...07_18_00     -10.38    4.542   -2.285    0.022         *     (-19.29, -1.474)
 str_dow_...07_18_00     -5.772    4.209   -1.371    0.170                 (-14.02, 2.48)
 str_dow_...07_18_00      2.862    4.807   0.5954    0.552                (-6.564, 12.29)
   cp9_2011_10_17_00      17.99    10.94    1.644    0.100                (-3.471, 39.45)
 is_weeke...10_17_00     0.9085    10.13  0.08967    0.929                (-18.96, 20.77)
 str_dow_...10_17_00     -10.98    21.19   -0.518    0.605                (-52.54, 30.58)
 str_dow_...10_17_00      14.66    16.42   0.8928    0.372                (-17.53, 46.84)
 str_dow_...10_17_00      11.73    17.87   0.6567    0.511                 (-23.3, 46.77)
 str_dow_...10_17_00      25.68    17.78    1.444    0.149                (-9.184, 60.55)
 str_dow_...10_17_00     0.1983    16.37  0.01211    0.990                 (-31.91, 32.3)
 str_dow_...10_17_00     0.7104    18.53  0.03834    0.969                (-35.62, 37.04)
  cp10_2011_11_14_00     -35.93    17.82   -2.016    0.044         *    (-70.88, -0.9859)
 is_weeke...11_14_00     -2.852    16.63  -0.1715    0.864                (-35.45, 29.75)
 str_dow_...11_14_00      15.37    34.64   0.4438    0.657                (-52.55, 83.29)
 str_dow_...11_14_00     -13.45    26.95   -0.499    0.618                 (-66.29, 39.4)
 str_dow_...11_14_00     -1.963    29.38 -0.06681    0.947                (-59.58, 55.65)
 str_dow_...11_14_00     -45.33    29.29   -1.547    0.122                (-102.8, 12.11)
 str_dow_...11_14_00     -3.037    26.91  -0.1128    0.910                 (-55.8, 49.73)
 str_dow_...11_14_00     0.1828    30.37 0.006021    0.995                (-59.36, 59.73)
  cp11_2011_12_12_00       48.6    11.87    4.096 4.33e-05       ***       (25.34, 71.87)
 is_weeke...12_12_00      7.724     11.0   0.7019    0.483                 (-13.85, 29.3)
 str_dow_...12_12_00     -5.184    23.02  -0.2252    0.822                (-50.31, 39.95)
 str_dow_...12_12_00      11.39    17.71   0.6433    0.520                (-23.33, 46.11)
 str_dow_...12_12_00      2.754     19.3   0.1427    0.887                (-35.08, 40.59)
 str_dow_...12_12_00      41.38    19.32    2.142    0.032         *       (3.501, 79.27)
 str_dow_...12_12_00      14.91    17.77   0.8389    0.402                (-19.94, 49.75)
 str_dow_...12_12_00     -7.173    20.13  -0.3563    0.722                 (-46.65, 32.3)
  cp12_2012_02_13_00     -29.86    2.967   -10.07   <2e-16       ***     (-35.68, -24.05)
 is_weeke...02_13_00     -3.516    2.711   -1.297    0.195                  (-8.832, 1.8)
 str_dow_...02_13_00     -1.222    5.719  -0.2136    0.831                (-12.44, 9.993)
 str_dow_...02_13_00     -8.255    4.336   -1.904    0.057         .     (-16.76, 0.2458)
 str_dow_...02_13_00     -5.534    4.715   -1.174    0.241                (-14.78, 3.711)
 str_dow_...02_13_00     -14.24    4.727   -3.012    0.003        **     (-23.51, -4.971)
 str_dow_...02_13_00     -8.709    4.359   -1.998    0.046         *    (-17.26, -0.1615)
 str_dow_...02_13_00      5.187     4.97    1.044    0.297                (-4.559, 14.93)
  cp13_2013_02_04_00      3.984   0.3473    11.47   <2e-16       ***       (3.303, 4.665)
 is_weeke...02_04_00    0.06721   0.3273   0.2054    0.837               (-0.5745, 0.709)
 str_dow_...02_04_00     0.1161   0.6941   0.1673    0.867                (-1.245, 1.477)
 str_dow_...02_04_00       1.47   0.5263    2.793    0.005        **      (0.4378, 2.502)
 str_dow_...02_04_00       1.01   0.5719    1.766    0.077         .     (-0.1114, 2.131)
 str_dow_...02_04_00     0.6053    0.568    1.066    0.287               (-0.5085, 1.719)
 str_dow_...02_04_00     0.6845    0.524    1.306    0.192                (-0.343, 1.712)
 str_dow_...02_04_00    -0.6166   0.6004   -1.027    0.304               (-1.794, 0.5606)
  cp14_2014_01_20_00       -1.5   0.1559   -9.626   <2e-16       ***     (-1.806, -1.195)
 is_weeke...01_20_00     0.1607    0.148    1.085    0.278              (-0.1296, 0.4509)
 str_dow_...01_20_00   -0.07329   0.3114  -0.2354    0.814              (-0.6838, 0.5372)
 str_dow_...01_20_00    -0.3773   0.2363   -1.596    0.110              (-0.8406, 0.0861)
 str_dow_...01_20_00    -0.1941   0.2572  -0.7546    0.451              (-0.6984, 0.3102)
 str_dow_...01_20_00   -0.02313   0.2554 -0.09053    0.928               (-0.524, 0.4778)
 str_dow_...01_20_00    -0.2125   0.2354  -0.9029    0.367               (-0.6741, 0.249)
 str_dow_...01_20_00     0.3729   0.2701    1.381    0.167              (-0.1566, 0.9024)
 ct1:sin1_tow_weekly       11.2    7.728     1.45    0.147                (-3.951, 26.36)
 ct1:cos1_tow_weekly     -42.32    14.42   -2.936    0.003        **     (-70.59, -14.06)
 ct1:sin2_tow_weekly      11.66    9.519    1.225    0.221                (-7.009, 30.32)
 ct1:cos2_tow_weekly     -14.76    12.58   -1.173    0.241                (-39.43, 9.918)
 cp0_2008...w_weekly     -11.48    8.342   -1.376    0.169                (-27.84, 4.875)
 cp0_2008...w_weekly      38.12    15.62     2.44    0.015         *       (7.489, 68.74)
 cp0_2008...w_weekly     -10.46    10.25    -1.02    0.308                (-30.56, 9.642)
 cp0_2008...w_weekly      11.52    13.64   0.8444    0.399                (-15.23, 38.27)
 cp1_2008...w_weekly      1.652    11.08   0.1491    0.881                (-20.07, 23.38)
 cp1_2008...w_weekly      66.07    21.34    3.097    0.002        **       (24.23, 107.9)
 cp1_2008...w_weekly     -7.573    13.42  -0.5643    0.573                (-33.89, 18.74)
 cp1_2008...w_weekly      27.45    18.77    1.463    0.144                (-9.345, 64.25)
 cp2_2008...w_weekly     -1.745    12.75  -0.1369    0.891                (-26.75, 23.26)
 cp2_2008...w_weekly     -78.87    24.57    -3.21    0.001        **     (-127.1, -30.69)
 cp2_2008...w_weekly      7.088    15.44   0.4591    0.646                (-23.19, 37.36)
 cp2_2008...w_weekly     -28.55     21.6   -1.321    0.186                (-70.91, 13.81)
 cp3_2009...w_weekly       3.37    3.675   0.9171    0.359                (-3.836, 10.58)
 cp3_2009...w_weekly      17.64    7.094    2.487    0.013         *       (3.735, 31.55)
 cp3_2009...w_weekly      1.799    4.432    0.406    0.685                (-6.892, 10.49)
 cp3_2009...w_weekly      4.645    6.224   0.7464    0.456                (-7.558, 16.85)
 cp4_2009...w_weekly     -6.371    2.911   -2.188    0.029         *    (-12.08, -0.6625)
 cp4_2009...w_weekly      10.64    5.602      1.9    0.058         .     (-0.3413, 21.63)
 cp4_2009...w_weekly     -3.119    3.505  -0.8898    0.374                (-9.992, 3.754)
 cp4_2009...w_weekly      9.358    4.914    1.904    0.057         .     (-0.2768, 18.99)
 cp5_2009...w_weekly      18.74    9.452    1.983    0.047         *      (0.2082, 37.28)
 cp5_2009...w_weekly     -64.67    18.15   -3.563 3.73e-04       ***     (-100.3, -29.08)
 cp5_2009...w_weekly      10.87    11.39   0.9543    0.340                (-11.47, 33.21)
 cp5_2009...w_weekly     -43.84    15.88    -2.76    0.006        **      (-74.98, -12.7)
 cp6_2010...w_weekly     -13.13     7.76   -1.692    0.091         .      (-28.34, 2.089)
 cp6_2010...w_weekly      54.89    14.91    3.682 2.36e-04       ***       (25.66, 84.13)
 cp6_2010...w_weekly     -8.544    9.346  -0.9142    0.361                (-26.87, 9.782)
 cp6_2010...w_weekly      35.89    13.04    2.752    0.006        **       (10.32, 61.45)
 cp7_2011...w_weekly     0.7401    1.133   0.6535    0.514                (-1.481, 2.961)
 cp7_2011...w_weekly     -8.187    2.192   -3.735 1.92e-04       ***     (-12.48, -3.889)
 cp7_2011...w_weekly     0.7357    1.367   0.5381    0.591                (-1.945, 3.417)
 cp7_2011...w_weekly      -3.69    1.927   -1.915    0.056         .    (-7.468, 0.08813)
 cp8_2011...w_weekly      -1.02    2.631  -0.3878    0.698                (-6.178, 4.138)
 cp8_2011...w_weekly      24.11    5.079    4.748 2.16e-06       ***       (14.16, 34.07)
 cp8_2011...w_weekly    -0.3377    3.185   -0.106    0.916                (-6.582, 5.907)
 cp8_2011...w_weekly      10.24    4.475    2.288    0.022         *       (1.463, 19.01)
 cp9_2011...w_weekly    -0.1849    10.23 -0.01807    0.986                (-20.25, 19.88)
 cp9_2011...w_weekly     -35.08    19.45   -1.803    0.071         .      (-73.22, 3.067)
 cp9_2011...w_weekly     -3.118     12.4  -0.2514    0.802                 (-27.44, 21.2)
 cp9_2011...w_weekly     -5.833    17.07  -0.3417    0.733                (-39.31, 27.64)
 cp10_201...w_weekly      10.87    16.81   0.6467    0.518                 (-22.1, 43.84)
 cp10_201...w_weekly      36.18    31.81    1.137    0.255                 (-26.2, 98.56)
 cp10_201...w_weekly     -7.068    20.38  -0.3469    0.729                (-47.02, 32.89)
 cp10_201...w_weekly     -2.739    27.87 -0.09829    0.922                (-57.39, 51.91)
 cp11_201...w_weekly      -9.16    11.09  -0.8258    0.409                (-30.91, 12.59)
 cp11_201...w_weekly     -32.59    21.12   -1.544    0.123                (-73.99, 8.811)
 cp11_201...w_weekly      17.59    13.44    1.309    0.191                (-8.759, 43.94)
 cp11_201...w_weekly     -1.121    18.52 -0.06054    0.952                (-37.43, 35.19)
 cp12_201...w_weekly   -0.05409    2.725 -0.01985    0.984                (-5.397, 5.289)
 cp12_201...w_weekly      14.48     5.25    2.759    0.006        **       (4.189, 24.78)
 cp12_201...w_weekly     -6.418    3.296   -1.948    0.052         .    (-12.88, 0.04374)
 cp12_201...w_weekly      2.938    4.613   0.6369    0.524                (-6.107, 11.98)
 cp13_201...w_weekly      1.143   0.3279    3.486 4.98e-04       ***      (0.5001, 1.786)
 cp13_201...w_weekly    -0.4522   0.6355  -0.7115    0.477                (-1.698, 0.794)
 cp13_201...w_weekly     0.3947   0.3994   0.9883    0.323               (-0.3884, 1.178)
 cp13_201...w_weekly     0.2938   0.5615   0.5233    0.601               (-0.8072, 1.395)
 cp14_201...w_weekly     0.0652   0.1476   0.4416    0.659              (-0.2243, 0.3547)
 cp14_201...w_weekly    0.09055   0.2853   0.3173    0.751                (-0.4689, 0.65)
 cp14_201...w_weekly     0.2477   0.1803    1.374    0.170              (-0.1058, 0.6012)
 cp14_201...w_weekly  -0.002924   0.2529 -0.01156    0.991               (-0.4989, 0.493)
     sin1_tow_weekly     0.1345   0.1498   0.8981    0.369              (-0.1592, 0.4282)
     cos1_tow_weekly      1.132   0.1882    6.014 2.05e-09       ***        (0.7626, 1.5)
     sin2_tow_weekly   -0.05098    0.151  -0.3377    0.736               (-0.347, 0.2451)
     cos2_tow_weekly     0.6293   0.1873    3.359 7.93e-04       ***      (0.262, 0.9967)
     sin3_tow_weekly    0.03266   0.1483   0.2203    0.826              (-0.2581, 0.3234)
     cos3_tow_weekly     0.3233   0.1882    1.718    0.086         .   (-0.04576, 0.6924)
    sin2_tom_monthly    0.04801  0.02559    1.876    0.061         . (-0.002166, 0.09818)
    cos2_tom_monthly   -0.05846  0.02644   -2.211    0.027         * (-0.1103, -0.006604)
  sin3_toq_quarterly    0.06395  0.02621     2.44    0.015         *    (0.01256, 0.1153)
  cos3_toq_quarterly    0.01505  0.02635   0.5711    0.568             (-0.03661, 0.0667)
     sin1_ct1_yearly     -0.343  0.03079   -11.14   <2e-16       ***   (-0.4034, -0.2827)
     cos1_ct1_yearly      1.619  0.03253    49.78   <2e-16       ***       (1.556, 1.683)
     sin2_ct1_yearly    0.06825   0.0281    2.429    0.015         *    (0.01315, 0.1234)
     cos2_ct1_yearly    -0.1551  0.02838   -5.467 4.99e-08       ***   (-0.2108, -0.0995)
     sin3_ct1_yearly     0.5126  0.02789    18.38   <2e-16       ***     (0.4579, 0.5672)
     cos3_ct1_yearly   -0.06656  0.02713   -2.453    0.014         *  (-0.1198, -0.01336)
     sin4_ct1_yearly    0.04128  0.02767    1.492    0.136            (-0.01297, 0.09554)
     cos4_ct1_yearly    -0.2267  0.02544   -8.909   <2e-16       ***   (-0.2766, -0.1768)
     sin5_ct1_yearly    -0.1818  0.02765   -6.574 5.82e-11       ***    (-0.236, -0.1276)
     cos5_ct1_yearly   -0.03161  0.02518   -1.255    0.210            (-0.08099, 0.01777)
     sin6_ct1_yearly    -0.2297  0.02716   -8.455   <2e-16       ***   (-0.2829, -0.1764)
     cos6_ct1_yearly   -0.05741  0.02615   -2.196    0.028         * (-0.1087, -0.006146)
     sin7_ct1_yearly    -0.1066  0.02654   -4.015 6.10e-05       ***  (-0.1586, -0.05452)
     cos7_ct1_yearly    0.08943  0.02573    3.476 5.17e-04       ***    (0.03898, 0.1399)
     sin8_ct1_yearly    0.08512  0.02588    3.289    0.001        **    (0.03437, 0.1359)
     cos8_ct1_yearly     0.2241  0.02675     8.38   <2e-16       ***     (0.1717, 0.2766)
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 190 and 2772 DF,   p-value: 1.110e-16
Model AIC: 19378.0,   model BIC: 20528.0

WARNING: the condition number is large, 1.01e+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.

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))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


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.

193 future_df = result.timeseries.make_future_dataframe(
194     periods=4,
195     include_history=False)
196 future_df
ts y
2016-01-21 2016-01-21 NaN
2016-01-22 2016-01-22 NaN
2016-01-23 2016-01-23 NaN
2016-01-24 2016-01-24 NaN


Call .predict() to compute predictions

ts forecast quantile_summary err_std forecast_lower forecast_upper
0 2016-01-21 8.635691 (7.85033096598295, 9.421050045358017) 0.400701 7.850331 9.421050
1 2016-01-22 8.676583 (7.822691648070611, 9.53047458704558) 0.435667 7.822692 9.530475
2 2016-01-23 8.145422 (7.361120686378202, 8.929723614870865) 0.400161 7.361121 8.929724
3 2016-01-24 8.575459 (7.559803749081156, 9.591114769504241) 0.518201 7.559804 9.591115


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 52.612 seconds)

Gallery generated by Sphinx-Gallery