def test_TA(self): apc.bootstrap_forecast(apc.loss_TA(), B=10) apc.bootstrap_forecast(apc.loss_TA(), B=10, quantiles=[0.9]) apc.bootstrap_forecast(apc.loss_TA(), B=10, adj_residuals=False) f1 = apc.bootstrap_forecast(apc.loss_TA(), B=10, seed=1) f2 = apc.bootstrap_forecast(apc.loss_TA(), B=10, seed=1) for key in f1.keys(): self.assertTrue(np.allclose(f1[key].values, f2[key].values))
def test_TA_odp(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.fit('od_poisson_response', 'AC') model.simulate(repetitions=10) model.simulate(repetitions=10, sigma2=10) model.simulate(repetitions=10, od_poisson_dgp='neg_binomial')
def test_TA(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.plot_data_sums() model.plot_data_sums(logy=True) for simplify_ranges in ('start', 'mean', 'end', False): model.plot_data_sums(simplify_ranges) plt.close('all')
def test_TA(self): r = apc.r_test(apc.loss_TA(), 'od_poisson_response', 'Ad', R_stat='ql', R_dist='ls', data_format='CL') self.assertEqual(round(r['R_stat'], 5), 73.16521) self.assertEqual(round(r['p_value'], 5), 0.78526) self.assertEqual(round(r['power_at_R'], 5), 0.99896)
def test_TA(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.plot_data_heatmaps() for simplify_ranges in ('start', 'mean', 'end', False): model.plot_data_heatmaps(simplify_ranges) plt.close('all') for space in ('AC', 'AP', 'PA', 'PC', 'CA', 'CP'): model.plot_data_heatmaps(space=space) plt.close('all') model.plot_data_heatmaps(vmin=20)
def test_TA_odp(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.fit(family='od_poisson_response', predictor='AC') self.assertAlmostEqual(model.deviance, 1903014.004, 3) self.assertTrue( np.allclose( model.parameters.sum().values, np.array([10.99021854, 6.56495772, 0.37934664, 8.3525477]))) self.assertAlmostEqual(model.fitted_values.sum(), 34358090.000, 3)
def test_TA(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.fit('od_poisson_response', 'Ad') model.forecast() model.plot_forecast() model.plot_forecast(ic=True) model.plot_forecast('Age', aggregate=True) model.plot_forecast('Cohort') model.plot_forecast(from_to=(8, 13)) plt.close('all')
def test_TA(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.fit('od_poisson_response', 'Ad') model.plot_fit() for style in ('detrend', 'sum_sum'): model.plot_fit(style) plt.close('all') for sr in ('start', 'mean', 'end', False): model.plot_fit(simplify_ranges=sr) plt.close('all') model.plot_fit(around_coef=False)
def test_TA(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.fit('od_poisson_response', 'AC') for sr in ('start', 'mean', 'end', False): model.plot_residuals(simplify_ranges=sr) plt.close('all') for sp in ('AC', 'AP', 'PA', 'PC', 'CA', 'CP'): model.plot_data_heatmaps(space=sp) plt.close('all') for r in ('anscombe', 'deviance', 'pearson', 'response'): model.plot_residuals(kind=r)
def test_TA(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.plot_data_within() for simplify_ranges in ('start', 'mean', 'end', False): model.plot_data_within(simplify_ranges=simplify_ranges) plt.close('all') for aggregate in ('mean', 'sum'): model.plot_data_within(aggregate=aggregate) plt.close('all') model.plot_data_within(logy=True) model.plot_data_within(n_groups='all')
def test_TA(self): model = apc.Model() model.data_from_df(apc.loss_TA()) self.assertEqual(model.data_format, 'CA') self.assertEqual(model.I, 10) self.assertEqual(model.J, 10) self.assertEqual(model.K, 10) self.assertEqual(model.L, 0) self.assertEqual(model.n, 55) self.assertEqual(model.time_adjust, 1) self.assertAlmostEqual(model.data_vector.sum()['response'], 34358090.0, 3)
def test_TA_odp(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.fit('od_poisson_response', 'AC') model.identify() self.assertTrue( np.allclose( model.parameters_adhoc.sum().values, np.array([19.93493555, 12.35339911, 23.27262888, 12.98041616]))) self.assertTrue( np.allclose( model.identify('sum_sum', attach_to_self=False).sum().values, np.array([-40.35513352, 19.04311385, -62.3882387, 8.99524907])))
def test_TA(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.fit('od_poisson_response', 'AC') model.forecast() self.assertTrue(np.allclose( model.forecasts['Period'].iloc[1:,:].sum().values, np.array([ 13454319.7860026 , 3264385.92189263, 2168550.32629664, 2371474.89252264, 527736.31618658, 15678560.7866679 , 17716020.93110489, 18965575.06511772, 21401447.92641674 ]) ) ) self.assertTrue(np.allclose( model.forecasts['Age'].iloc[1:,:].sum().values, np.array([ 17824052.09094379, 5446971.56429764, 2703382.56455396, 4610723.51207401, 699136.02022292, 21535432.35438537, 24935149.09611903, 27020161.71376697, 31084672.01592125 ]) ) ) self.assertTrue(np.allclose( model.forecasts['Cohort'].iloc[1:,:].sum().values, np.array([ 18586221.79737546, 5480908.10291801, 2617925.92215297, 4585571.92139958, 729031.5957391 , 22320725.25838809, 25741623.42490841, 27839626.40066406, 31929460.02408297 ]) ) ) self.assertTrue(np.allclose( model.forecasts['Total'].sum().values, np.array([ 18680855.61192424, 2952921.04370912, 993729.36519777, 2682411.51615798, 732743.54115671, 20692875.08949177, 22535935.034052 , 23666265.45020602, 25869724.35611854 ]) ) )
def test_TA_odp(self): model = apc.Model() model.data_from_df(apc.loss_TA(), data_format='CL') model.fit(family='od_poisson_response', predictor='AC') model.fit_table() dev_table_Ad = model.fit_table(reference_predictor='Ad', attach_to_self=False) self.assertTrue( np.allclose( model.deviance_table.sum().values, np.array([ 6.14205640e+07, 4.26000000e+02, 0.00000000e+00, 4.42934379e+07, 1.02000000e+02, 6.42698087e+01, 8.77350747e-01 ]))) self.assertTrue( np.allclose( dev_table_Ad.sum().values, np.array([ 3.34371797e+07, 2.48000000e+02, 0.00000000e+00, 2.20883978e+07, 2.80000000e+01, 5.10659264e+01, 5.28199268e-02 ])))