Exemplo n.º 1
0
    def test_prediction_values_middle_out_middle_level(self):
        index = ['2000-01-01 00:00:00', '2000-01-01 00:00:01',
               '2000-01-01 00:00:02', '2000-01-01 00:00:03',
               '2000-01-01 00:00:04', '2000-01-01 00:00:05',
               '2000-01-01 00:00:06', '2000-01-01 00:00:07',
               '2000-01-01 00:00:08', '2000-01-01 00:00:09',
               '2000-01-01 00:00:10', '2000-01-01 00:00:11',
               '2000-01-01 00:00:12', '2000-01-01 00:00:13',
               '2000-01-01 00:00:14', '2000-01-01 00:00:15',
               '2000-01-01 00:00:16', '2000-01-01 00:00:17',
               '2000-01-01 00:00:18', '2000-01-01 00:00:19']
        time_series_model = AR(p=2, horizon=3)
        data1_list = [1 for i in range(20)]
        data2_list = [1 for i in range(10)]+[0 for i in range(10)]
        data3_list = [0 for i in range(10)]+[1 for i in range(10)]
        data4_list = [0 for i in range(20)]
        data5_list = [0.5 for i in range(20)]
        data1 = pd.DataFrame(index=index, data=data1_list)
        data2 = pd.DataFrame(index=index, data=data2_list)
        data3 = pd.DataFrame(index=index, data=data3_list)
        data4 = pd.DataFrame(index=index, data=data4_list)
        data5 = pd.DataFrame(index=index, data=data5_list)

        data = {'data1': data1, 'data2': data2, 'data3': data3, 'data4': data4, 'data5': data5}
        tree_adj = {'data1': ['data2', 'data3'], 'data2': ['data4', 'data5'], 'data3': []}
        prediction = HierarchicalMiddleOut(model=time_series_model, hierarchy_tree=tree_adj, root='data1', method='tdsga')
        prediction.fit(data).predict(data)
Exemplo n.º 2
0
    def test_prediction_values_middle_out_middle_level(self):
        index = [
            "2000-01-01 00:00:00",
            "2000-01-01 00:00:01",
            "2000-01-01 00:00:02",
            "2000-01-01 00:00:03",
            "2000-01-01 00:00:04",
            "2000-01-01 00:00:05",
            "2000-01-01 00:00:06",
            "2000-01-01 00:00:07",
            "2000-01-01 00:00:08",
            "2000-01-01 00:00:09",
            "2000-01-01 00:00:10",
            "2000-01-01 00:00:11",
            "2000-01-01 00:00:12",
            "2000-01-01 00:00:13",
            "2000-01-01 00:00:14",
            "2000-01-01 00:00:15",
            "2000-01-01 00:00:16",
            "2000-01-01 00:00:17",
            "2000-01-01 00:00:18",
            "2000-01-01 00:00:19",
        ]
        time_series_model = AR(p=2, horizon=3)
        data1_list = [1 for i in range(20)]
        data2_list = [1 for i in range(10)] + [0 for i in range(10)]
        data3_list = [0 for i in range(10)] + [1 for i in range(10)]
        data4_list = [0 for i in range(20)]
        data5_list = [0.5 for i in range(20)]
        data1 = pd.DataFrame(index=index, data=data1_list)
        data2 = pd.DataFrame(index=index, data=data2_list)
        data3 = pd.DataFrame(index=index, data=data3_list)
        data4 = pd.DataFrame(index=index, data=data4_list)
        data5 = pd.DataFrame(index=index, data=data5_list)

        data = {
            "data1": data1,
            "data2": data2,
            "data3": data3,
            "data4": data4,
            "data5": data5,
        }
        tree_adj = {
            "data1": ["data2", "data3"],
            "data2": ["data4", "data5"],
            "data3": [],
        }
        prediction = HierarchicalMiddleOut(
            model=time_series_model,
            hierarchy_tree=tree_adj,
            root="data1",
            method="tdsga",
        )
        prediction.fit(data).predict(data)
Exemplo n.º 3
0
 def test_prediction_values_middle_out_tdfp(self):
     index = ['2000-01-01 00:00:00', '2000-01-01 00:00:01',
            '2000-01-01 00:00:02', '2000-01-01 00:00:03',
            '2000-01-01 00:00:04', '2000-01-01 00:00:05',
            '2000-01-01 00:00:06', '2000-01-01 00:00:07',
            '2000-01-01 00:00:08', '2000-01-01 00:00:09',
            '2000-01-01 00:00:10', '2000-01-01 00:00:11',
            '2000-01-01 00:00:12', '2000-01-01 00:00:13',
            '2000-01-01 00:00:14', '2000-01-01 00:00:15',
            '2000-01-01 00:00:16', '2000-01-01 00:00:17',
            '2000-01-01 00:00:18', '2000-01-01 00:00:19']
     time_series_model = AR(p=2, horizon=3)
     data1_list = [1 for i in range(20)]
     data2_list = [1 for i in range(10)]+[0 for i in range(10)]
     data3_list = [0 for i in range(10)]+[1 for i in range(10)]
     data1 = pd.DataFrame(index=index, data=data1_list)
     data2 = pd.DataFrame(index=index, data=data2_list)
     data3 = pd.DataFrame(index=index, data=data3_list)
     data = {'data1': data1, 'data2': data2, 'data3': data3}
     tree_adj = {'data1': ['data2', 'data3'], 'data2': [], 'data3': []}
     values_prediction_data1 = [[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]]
     values_prediction_child = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
     test_prediction_data1 = pd.DataFrame(data=values_prediction_data1, columns=['y_1', 'y_2', 'y_3'], index=['2000-01-01 00:00:17', '2000-01-01 00:00:18', '2000-01-01 00:00:19'])
     test_prediction_data2 = pd.DataFrame(data=values_prediction_child, columns=['y_1', 'y_2', 'y_3'], index=['2000-01-01 00:00:17', '2000-01-01 00:00:18', '2000-01-01 00:00:19'])
     test_prediction_data3 = pd.DataFrame(data=values_prediction_data1, columns=['y_1', 'y_2', 'y_3'], index=['2000-01-01 00:00:17', '2000-01-01 00:00:18', '2000-01-01 00:00:19'])
     prediction = HierarchicalMiddleOut(model=time_series_model, hierarchy_tree=tree_adj, root='data1', method='tdfp')
     test_prediction_data = {'data1': test_prediction_data1, 'data2': test_prediction_data2, 'data3': test_prediction_data3}
     prediction = prediction.fit(data).predict()
     for key in test_prediction_data.keys():
         assert_frame_equal(test_prediction_data[key], prediction[key])
Exemplo n.º 4
0
 def test_prediction_values_middle_out_tdfp(self):
     index = [
         "2000-01-01 00:00:00",
         "2000-01-01 00:00:01",
         "2000-01-01 00:00:02",
         "2000-01-01 00:00:03",
         "2000-01-01 00:00:04",
         "2000-01-01 00:00:05",
         "2000-01-01 00:00:06",
         "2000-01-01 00:00:07",
         "2000-01-01 00:00:08",
         "2000-01-01 00:00:09",
         "2000-01-01 00:00:10",
         "2000-01-01 00:00:11",
         "2000-01-01 00:00:12",
         "2000-01-01 00:00:13",
         "2000-01-01 00:00:14",
         "2000-01-01 00:00:15",
         "2000-01-01 00:00:16",
         "2000-01-01 00:00:17",
         "2000-01-01 00:00:18",
         "2000-01-01 00:00:19",
     ]
     time_series_model = AR(p=2, horizon=3)
     data1_list = [1 for i in range(20)]
     data2_list = [1 for i in range(10)] + [0 for i in range(10)]
     data3_list = [0 for i in range(10)] + [1 for i in range(10)]
     data1 = pd.DataFrame(index=index, data=data1_list)
     data2 = pd.DataFrame(index=index, data=data2_list)
     data3 = pd.DataFrame(index=index, data=data3_list)
     data = {"data1": data1, "data2": data2, "data3": data3}
     tree_adj = {"data1": ["data2", "data3"], "data2": [], "data3": []}
     values_prediction_data1 = [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]
     values_prediction_child = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
     test_prediction_data1 = pd.DataFrame(
         data=values_prediction_data1,
         columns=["y_1", "y_2", "y_3"],
         index=["2000-01-01 00:00:17", "2000-01-01 00:00:18", "2000-01-01 00:00:19"],
     )
     test_prediction_data2 = pd.DataFrame(
         data=values_prediction_child,
         columns=["y_1", "y_2", "y_3"],
         index=["2000-01-01 00:00:17", "2000-01-01 00:00:18", "2000-01-01 00:00:19"],
     )
     test_prediction_data3 = pd.DataFrame(
         data=values_prediction_data1,
         columns=["y_1", "y_2", "y_3"],
         index=["2000-01-01 00:00:17", "2000-01-01 00:00:18", "2000-01-01 00:00:19"],
     )
     prediction = HierarchicalMiddleOut(
         model=time_series_model,
         hierarchy_tree=tree_adj,
         root="data1",
         method="tdfp",
     )
     test_prediction_data = {
         "data1": test_prediction_data1,
         "data2": test_prediction_data2,
         "data3": test_prediction_data3,
     }
     prediction = prediction.fit(data).predict()
     for key in test_prediction_data.keys():
         assert_frame_equal(test_prediction_data[key], prediction[key])