Ejemplo n.º 1
0
    def setUp(self):
        self.df = select_mungedata(2, 1, '2013-1-1', '2015-1-1')
        self.xtest = select_features('2015-1-1', '2015-1-10')
        self.actuals = select_mungedata_simple(2, 1, '2015-1-1', '2015-1-10')
        self.daily_avg = self.df.waittime.resample('D', how='mean')

        model = RandomForestRegressor(n_jobs=-1,
                                      n_estimators=2,
                                      random_state=1)
        self.im = IncrementalModel(self.df, model, categoricals=['event'])
        self.im.predict(self.xtest)
Ejemplo n.º 2
0
    def setUp(self):
        self.df = select_mungedata(2, 1, '2013-1-1', '2015-1-1')
        self.xtest = select_features('2015-1-1', '2015-1-10')
        self.actuals = select_mungedata_simple(2, 1, '2015-1-1', '2015-1-10')
        self.daily_avg = self.df.waittime.resample('D', how='mean')

        model = RandomForestRegressor(n_jobs=-1, n_estimators=2,
                                      random_state=1)
        self.im = IncrementalModel(self.df, model, categoricals=['event'])
        self.im.predict(self.xtest)
Ejemplo n.º 3
0
class TestIncrementalModel(unittest.TestCase):
    def setUp(self):
        self.df = select_mungedata(2, 1, '2013-1-1', '2015-1-1')
        self.xtest = select_features('2015-1-1', '2015-1-10')
        self.actuals = select_mungedata_simple(2, 1, '2015-1-1', '2015-1-10')
        self.daily_avg = self.df.waittime.resample('D', how='mean')

        model = RandomForestRegressor(n_jobs=-1,
                                      n_estimators=2,
                                      random_state=1)
        self.im = IncrementalModel(self.df, model, categoricals=['event'])
        self.im.predict(self.xtest)

    def test_deltas(self):
        df = self.im.deltas(self.df.waittime)
        self.assertAlmostEqual(
            df.loc['2014-2-20 15:30'].avg_delta_2,
            self.daily_avg.loc['2014-2-19'] - self.daily_avg.loc['2014-2-5'])

    def test_baseline(self):
        baseline = self.im.baseline()
        self.assertEqual(len(baseline), len(self.im.y_predict))
        self.assertEqual(baseline.loc['2015-1-2 21:30'],
                         baseline.loc['2015-1-9 21:30'])

    def test_set_actual(self):
        actual = select_mungedata_simple(2, 1, '2015-1-1', '2015-1-10')
        self.im.set_actual(actual.waittime)
        self.assertEqual(actual.ix[24].waittime, self.im.actual.ix[24])

    def test_run_Incremental(self):
        model = RandomForestRegressor(n_jobs=-1,
                                      n_estimators=2,
                                      random_state=1)
        im = run_Incremental(model, 2, 1, '2013-1-1', '2015-1-1', '2015-1-1',
                             '2015-1-10')

        self.assertEqual(im.score(), self.im.score(self.actuals.waittime))
Ejemplo n.º 4
0
class TestIncrementalModel(unittest.TestCase):
    def setUp(self):
        self.df = select_mungedata(2, 1, '2013-1-1', '2015-1-1')
        self.xtest = select_features('2015-1-1', '2015-1-10')
        self.actuals = select_mungedata_simple(2, 1, '2015-1-1', '2015-1-10')
        self.daily_avg = self.df.waittime.resample('D', how='mean')

        model = RandomForestRegressor(n_jobs=-1, n_estimators=2,
                                      random_state=1)
        self.im = IncrementalModel(self.df, model, categoricals=['event'])
        self.im.predict(self.xtest)

    def test_deltas(self):
        df = self.im.deltas(self.df.waittime)
        self.assertAlmostEqual(df.loc['2014-2-20 15:30'].avg_delta_2,
                               self.daily_avg.loc['2014-2-19'] -
                               self.daily_avg.loc['2014-2-5'])

    def test_baseline(self):
        baseline = self.im.baseline()
        self.assertEqual(len(baseline), len(self.im.y_predict))
        self.assertEqual(baseline.loc['2015-1-2 21:30'],
                         baseline.loc['2015-1-9 21:30'])

    def test_set_actual(self):
        actual = select_mungedata_simple(2, 1, '2015-1-1', '2015-1-10')
        self.im.set_actual(actual.waittime)
        self.assertEqual(actual.ix[24].waittime, self.im.actual.ix[24])

    def test_run_Incremental(self):
        model = RandomForestRegressor(n_jobs=-1, n_estimators=2,
                                      random_state=1)
        im = run_Incremental(model, 2, 1, '2013-1-1', '2015-1-1',
                             '2015-1-1', '2015-1-10')

        self.assertEqual(im.score(), self.im.score(self.actuals.waittime))