Spaces:
Sleeping
Sleeping
File size: 1,109 Bytes
dad00c5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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 |