def setUp(self): self.oil = ts_io.read_ts('oil', 'fpp', False) self.aus = ts_io.read_ts('austourists', 'fpp', False) self.gold = ts_io.read_ts('gold', as_pandas=False) self.tsn = converters.ts([1, 2, NA, 4]) self.tss = converters.ts([1, 2, 3, 1, 2, 3, 1, NA, 3], frequency=3) self.vss = [1,2,3,4] * 4 self.vns = range(10) r = [ 0.00287731, 0.58436909, 0.37650672, 0.10024602, 0.46983146, 0.36542408, 0.47136475, 0.79978803, 0.70349953, 0.69531808, 0.54447409, 0.82227504, 0.99736304, 0.91404314, 0.42225177, 0.14696605, 0.08098318, 0.11046747, 0.8412757 , 0.73562921] self.rnd = converters.sequence_as_series(r, freq=4)
def setUp(self): self.oil = ts_io.read_ts('oil', 'fpp', False) self.aus = ts_io.read_ts('austourists', 'fpp', False) self.gold = ts_io.read_ts('gold', as_pandas=False) self.tsn = converters.ts([1, 2, NA, 4]) self.tss = converters.ts([1, 2, 3, 1, 2, 3, 1, NA, 3], frequency=3) self.vss = [1, 2, 3, 4] * 4 self.vns = range(10) r = [ 0.00287731, 0.58436909, 0.37650672, 0.10024602, 0.46983146, 0.36542408, 0.47136475, 0.79978803, 0.70349953, 0.69531808, 0.54447409, 0.82227504, 0.99736304, 0.91404314, 0.42225177, 0.14696605, 0.08098318, 0.11046747, 0.8412757, 0.73562921 ] self.rnd = converters.sequence_as_series(r, freq=4) self.fc = importr('forecast')
def test_prediction_intervals(self): pred = converters.prediction_intervals(converters.ts(self.fc_oil)) self.assertEqual(pred.shape, (10, 5)) self.assertEqual(list(pred.index), range(2011, 2021)) self.assertEqual( list(pred.columns), [u'point_fc', u'lower80', u'upper80', u'lower95', u'upper95']) self.assertAlmostEqual(pred.point_fc[2011], self.fc_oil.rx2('mean').rx(1)[0], places=3) self.assertAlmostEqual(pred.point_fc[2020], self.fc_oil.rx2('mean').rx(10)[0], places=3) lower = self.fc_oil.rx2('lower') upper = self.fc_oil.rx2('upper') self.assertAlmostEqual(pred.lower80[2011], lower.rx(1, 1)[0], places=3) self.assertAlmostEqual(pred.lower80[2020], lower.rx(10, 1)[0], places=3) self.assertAlmostEqual(pred.upper80[2011], upper.rx(1, 1)[0], places=3) self.assertAlmostEqual(pred.upper80[2020], upper.rx(10, 1)[0], places=3) self.assertAlmostEqual(pred.lower95[2011], lower.rx(1, 2)[0], places=3) self.assertAlmostEqual(pred.lower95[2020], lower.rx(10, 2)[0], places=3) self.assertAlmostEqual(pred.upper95[2011], upper.rx(1, 2)[0], places=3) self.assertAlmostEqual(pred.upper95[2020], upper.rx(10, 2)[0], places=3) self.assertRaises(ValueError, converters.prediction_intervals, self.oil_ts)
def test_get_index(self): oil_idx = converters._get_index(converters.ts(self.oil_ts)) self.assertEqual(oil_idx, range(1965, 2011)) aus_idx = converters._get_index(self.aus_ts) self.assertEqual(len(aus_idx), 2) self.assertEqual(len(aus_idx[0]), 48) self.assertEqual(len(aus_idx[1]), 48) self.assertEqual(aus_idx[1], [1, 2, 3, 4] * 12)
def test_accuracy(self): acc1 = wrappers.accuracy(converters.ts(self.fc_oil)) acdf1 = converters.accuracy(acc1) acdf1.shape == (7, 1) list(acdf1.columns) == ['Train'] acc2 = wrappers.accuracy(self.fc_oil, 350) acdf2 = converters.accuracy(acc2) acdf2.shape == (7, 2) set(acdf2.columns) == {'Train', 'Test'} self.assertTrue(acdf1.Train.round(5).equals(acdf2.Train.round(5))) r_test_vals = list(acc2.rx(2, True)) r_cols = list(robjects.r.colnames(acc2)) self.assertAlmostEqual(acdf2.Test['ME'], r_test_vals[r_cols.index('ME')], places=3) self.assertAlmostEqual(acdf2.Test['MAE'], r_test_vals[r_cols.index('MAE')], places=3) self.assertAlmostEqual(acdf2.Test['RMSE'], r_test_vals[r_cols.index('RMSE')], places=3)
def test_tsclean(self): gold_py = converters.ts_as_series(converters.ts(self.gold)) clean_py = wrappers.tsclean(gold_py) self.assertFalse(clean_py.isnull().any()) clean_r = self.fc.tsclean(converters.ts(self.gold)) self.assertAlmostEqual(clean_py[770], clean_r.rx(770), places=3)
def test_ts(self): ts = converters.ts(self.vss, deltat=0.25, end=(1,1)) self.assertEqual(wrappers.frequency(ts), 4) self.assertEqual(tuple(robjects.r('end')(ts)), (1.0, 1.0)) self.assertEqual(tuple(robjects.r('start')(ts)), (-3.0, 2.0))