Spaces:
Sleeping
Sleeping
FEATURES["past_covariates_final"] = [] | |
for col in FEATURES["past_covariates"]: | |
new_features = data_preprocess[col].to_frame().copy() | |
# Lag Features | |
new_features[col+"_L7D"] = new_features[col].shift(7) | |
new_features[col+"_L14D"] = new_features[col].shift(14) | |
new_features[col+"_L21D"] = new_features[col].shift(21) | |
# Rolling Features | |
# Shift to move the new features into the prediction space (2019-01-01 to 2019-01-07) | |
new_features[col+"_RMean14D"] = new_features[col].shift(7).rolling('14D').mean() | |
# Differencing Features | |
# Shift to move the new features into the prediction space (2019-01-01 to 2019-01-07) | |
new_features[col+"_Diff7D"] = (new_features[col].shift(7) - new_features[col].shift(7).shift(7)) | |
FEATURES["past_covariates_final"].extend([col+"_L7D", col+"_L14D", col+"_L21D", col+"_RMean14D", col+"_Diff7D"]) | |
new_features = new_features.drop(columns=col) | |
data_preprocess = pd.concat([data_preprocess, new_features], axis=1) | |
assert len(data_preprocess.loc[:, FEATURES["past_covariates_final"]].columns) == len(FEATURES["past_covariates"])*5 |