dna-casestudy / code /recurse_predict.py
davidna22's picture
Upload folder using huggingface_hub
dad00c5 verified
raw
history blame
1.11 kB
def predict_recurse(dataset, test, model, features_to_impute=['Target_L1D', 'Target_Diff7D', 'Target_Diff14D'], last_feature='Target_L6D'):
n_steps = len(test)
merged_data = pd.concat([dataset[-14:], test], axis=0)
all_index = merged_data.index
X_test = test.drop(columns="Target")
sd = -6 # Starting point for filling next value
# For each step, get the predictions
for i in range(n_steps-1):
pred = final_model.predict(X_test)[i]
# For the three features needed, compute the new value
X_test.loc[all_index[sd+i], features_to_impute[0]] = pred
X_test.loc[all_index[sd+i], features_to_impute[1]] = pred - merged_data.loc[all_index[sd+i-7], features_to_impute[1]]
X_test.loc[all_index[sd+i], features_to_impute[2]] = pred - merged_data.loc[all_index[sd+i-14], features_to_impute[2]]
# In the last iteration compute the Lag6D value
if i == 5:
X_test.loc[all_index[sd+i], last_feature] = pred - merged_data.loc[all_index[sd+i-6], last_feature]
final_preds = final_model.predict(X_test)
return final_preds