I’m developing a tree-based model classifier (XGBoost) using some healthcare (patient visits) data. The data has a time dimension, and I want to observe if there is a longitudinal effect for the prediction of the target feature. To predict the target for the current visit (Timepoint n), it should incorporate information from the previous visit(s) (T0 to T(N-1)). The input shape is visit_time, features, and target/label. Let’s say, I have a patient with 5 visits (T1 – T5). The idea is that the first prediction (T1) will be just based on the features for this timepoint. To predict T2, I want to add information from T1. Then, for T3, it will be T1 + T2, and so on, T5 (T1+ T2 + T3 + T4). The number of timepoints (visits) vary for each patient.

I read that I can add lags and rolling windows. But still couldn’t figure out the best way to do it. Any thoughts on what and how to do it for my scenario?