Lag features convert a time series into rows that a supervised learning model can use. Each row represents one valid time step and contains earlier observations selected by the requested lags.
For a time step t and lags l_1 through l_k, construct
row(t)=[xt−l1,xt−l2,…,xt−lk]Here, x_t is the value at time t and l_j is the j-th requested lag. Begin at the largest lag so every referenced observation exists. Return the feature matrix as a list of lists, preserving the supplied lag order.
Input: series = [10, 20, 30, 40, 50], lags = [1, 2]
Output: [[20, 10], [30, 20], [40, 30]]
Explanation: At time 2, lag 1 selects 20 and lag 2 selects 10. The same lookup is repeated for each later time.
Input: series = [1, 2, 3, 4, 5], lags = [1]
Output: [[1], [2], [3], [4]]
Start the outer loop at max(lags).
Build each row with series[t - lag] for lags in their given order.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Lag features convert a time series into rows that a supervised learning model can use. Each row represents one valid time step and contains earlier observations selected by the requested lags.
For a time step t and lags l_1 through l_k, construct
row(t)=[xt−l1,xt−l2,…,xt−lk]Here, x_t is the value at time t and l_j is the j-th requested lag. Begin at the largest lag so every referenced observation exists. Return the feature matrix as a list of lists, preserving the supplied lag order.
Input: series = [10, 20, 30, 40, 50], lags = [1, 2]
Output: [[20, 10], [30, 20], [40, 30]]
Explanation: At time 2, lag 1 selects 20 and lag 2 selects 10. The same lookup is repeated for each later time.
Input: series = [1, 2, 3, 4, 5], lags = [1]
Output: [[1], [2], [3], [4]]
Start the outer loop at max(lags).
Build each row with series[t - lag] for lags in their given order.
Sign in to take notes on this problem
Accepts: array
Accepts: array