def __init__(self, raw_df, demo_raw, train_start_time='2017-10-01', train_end_time='2018-08-31', test_start_time='2018-09-01 00:00:00', test_end_time='2018-10-31 23:00:00'): self.raw_df = raw_df self.demo_raw = demo_raw self.train_start_time = train_start_time self.train_end_time = train_end_time # set train/test set self.test_start_time = test_start_time self.test_end_time = test_end_time # prediction window: use one week's data to predict next hour self.window = datetime.timedelta(hours=24 * 7) self.step = datetime.timedelta(hours=1) self.predict_start_time = datetime_utils.str_to_datetime( self.test_start_time) + self.window self.predict_end_time = datetime_utils.str_to_datetime( self.test_end_time) self.actual_end_time = self.predict_end_time - self.window self.train_df = raw_df[self.train_start_time:self.train_end_time] self.test_df = raw_df[self.test_start_time:self.test_end_time] self.grid_list = list(raw_df)
def __init__(self, raw_df, window = 168): self.raw_df = raw_df self.train_start_time = '2014-02-01' self.train_end_time = '2018-10-31' self.test_start_time = '2018-11-01 00:00:00' self.test_end_time = '2019-04-30 23:00:00' self.window = datetime.timedelta(hours=window) self.step = datetime.timedelta(hours=1) self.predict_start_time = datetime_utils.str_to_datetime(self.test_start_time) + self.window self.predict_end_time = datetime_utils.str_to_datetime(self.test_end_time) self.actual_end_time = self.predict_end_time - self.window self.train_df = raw_df[self.train_start_time: self.train_end_time] self.test_df = raw_df[self.test_start_time: self.test_end_time]
def __init__(self, demo_raw, train_start_time = '2014-02-01',train_end_time = '2018-10-31', test_start_time = '2018-11-01 00:00:00', test_end_time = '2019-05-01 23:00:00' ): self.demo_raw = demo_raw self.train_start_time = train_start_time self.train_end_time = train_end_time self.test_start_time = test_start_time self.test_end_time = test_end_time self.window = datetime.timedelta(hours=24 * 7) self.step = datetime.timedelta(hours=1) self.predict_start_time = datetime_utils.str_to_datetime(self.test_start_time) + self.window self.predict_end_time = datetime_utils.str_to_datetime(self.test_end_time) self.actual_end_time = self.predict_end_time - self.window self.train_hours = datetime_utils.get_total_hour_range(self.train_start_time, self.train_end_time)
def __init__(self, raw_df, demo_raw, train_start_time = '2014-02-01',train_end_time = '2018-10-31', test_start_time = '2018-11-01 00:00:00', test_end_time = '2019-04-30 23:00:00' ): self.raw_df = raw_df self.demo_raw = demo_raw self.train_start_time = train_start_time self.train_end_time = train_end_time self.test_start_time = test_start_time self.test_end_time = test_end_time self.window = datetime.timedelta(hours=24 * 7) self.step = datetime.timedelta(hours=3) self.predict_start_time = datetime_utils.str_to_datetime(self.test_start_time) + self.window self.predict_end_time = datetime_utils.str_to_datetime(self.test_end_time) self.actual_end_time = self.predict_end_time - self.window self.train_df = raw_df[self.train_start_time: self.train_end_time] self.test_df = raw_df[self.test_start_time: self.test_end_time] self.grid_list = list(raw_df)
def arr_to_df(self): predicted_df = pd.DataFrame(np.nan, index=self.test_df_cut[self.train_obj.predict_start_time: self.train_obj.predict_end_time].index, columns=list(self.test_df_cut)) sample_pred_squeeze = np.squeeze(self.predicted_vals) pred_shape = self.predicted_vals.shape # loop through time stamps for i in range(0, pred_shape[0]): temp_image = sample_pred_squeeze[i] temp_rot = np.rot90(temp_image, axes=(1,0)) dt = datetime_utils.str_to_datetime(self.train_obj.test_start_time) + datetime.timedelta(hours=i*3) predicted_timestamp = dt+self.train_obj.window predicted_timestamp_str = pd.to_datetime(datetime_utils.datetime_to_str(predicted_timestamp)) for c in range(pred_shape[1]): for r in range(pred_shape[2]): temp_str = str(r)+'_'+str(c) if temp_str in self.intersect_pos_set: predicted_df.loc[predicted_timestamp_str, temp_str] = temp_rot[r][c] return predicted_df