Example #1
0
 def test_simulated_historical_forecasts_default_value_check(self):
     m = Prophet()
     m.fit(self.__df)
     # Default value of period should be equal to 0.5 * horizon
     df_shf1 = diagnostics.simulated_historical_forecasts(m,
                                                          horizon='10 days',
                                                          k=1)
     df_shf2 = diagnostics.simulated_historical_forecasts(m,
                                                          horizon='10 days',
                                                          k=1,
                                                          period='5 days')
     self.assertAlmostEqual(
         ((df_shf1 - df_shf2)**2)[['y', 'yhat']].sum().sum(), 0.0)
Example #2
0
 def test_simulated_historical_forecasts(self):
     m = Prophet()
     m.fit(self.__df)
     k = 2
     for p in [1, 10]:
         for h in [1, 3]:
             period = '{} days'.format(p)
             horizon = '{} days'.format(h)
             df_shf = diagnostics.simulated_historical_forecasts(
                 m, horizon=horizon, k=k, period=period)
             # All cutoff dates should be less than ds dates
             self.assertTrue((df_shf['cutoff'] < df_shf['ds']).all())
             # The unique size of output cutoff should be equal to 'k'
             self.assertEqual(len(np.unique(df_shf['cutoff'])), k)
             self.assertEqual(
                 max(df_shf['ds'] - df_shf['cutoff']),
                 pd.Timedelta(horizon),
             )
             dc = df_shf['cutoff'].diff()
             dc = dc[dc > pd.Timedelta(0)].min()
             self.assertTrue(dc >= pd.Timedelta(period))
             # Each y in df_shf and self.__df with same ds should be equal
             df_merged = pd.merge(df_shf, self.__df, 'left', on='ds')
             self.assertAlmostEqual(
                 np.sum((df_merged['y_x'] - df_merged['y_y'])**2), 0.0)
Example #3
0
 def test_simulated_historical_forecasts_logistic(self):
     m = Prophet(growth='logistic')
     df = self.__df.copy()
     df['cap'] = 40
     m.fit(df)
     df_shf = diagnostics.simulated_historical_forecasts(m,
                                                         horizon='3 days',
                                                         k=2,
                                                         period='3 days')
     # All cutoff dates should be less than ds dates
     self.assertTrue((df_shf['cutoff'] < df_shf['ds']).all())
     # The unique size of output cutoff should be equal to 'k'
     self.assertEqual(len(np.unique(df_shf['cutoff'])), 2)
     # Each y in df_shf and self.__df with same ds should be equal
     df_merged = pd.merge(df_shf, df, 'left', on='ds')
     self.assertAlmostEqual(
         np.sum((df_merged['y_x'] - df_merged['y_y'])**2), 0.0)
 def test_simulated_historical_forecasts_extra_regressors(self):
     m = Prophet()
     m.add_seasonality(name='monthly', period=30.5, fourier_order=5)
     m.add_regressor('extra')
     df = self.__df.copy()
     df['cap'] = 40
     df['extra'] = range(df.shape[0])
     m.fit(df)
     df_shf = diagnostics.simulated_historical_forecasts(m,
                                                         horizon='3 days',
                                                         k=2,
                                                         period='3 days')
     # All cutoff dates should be less than ds dates
     self.assertTrue((df_shf['cutoff'] < df_shf['ds']).all())
     # The unique size of output cutoff should be equal to 'k'
     self.assertEqual(len(np.unique(df_shf['cutoff'])), 2)
     # Each y in df_shf and self.__df with same ds should be equal
     df_merged = pd.merge(df_shf, df, 'left', on='ds')
     self.assertAlmostEqual(
         np.sum((df_merged['y_x'] - df_merged['y_y'])**2), 0.0)