Lab 1: Why -1 while slicing the series for calling the function instead of using the slow loop

Hi,

I’m not understanding the reason behind slicing compared to the slow loop which is near the end of this lab.
To my understanding: The last window of the slow loop is series[1440-1460], predicting at t=1460. And for the single cell, the last window contains series[1439-1459], predicting at t=1459.

But then 1460 is left out, isn’t it? So why we’re doing -1 in forecast_series = series[split_time - window_size:-1].

How is the index predicting 1461 if we don’t do -1? Isn’t running the model on time 1440-1460 predicts for time 1460? Thank you in advance.
This is the Lab 1 of Week 3 that I am referring to

is this ungraded lab @amp1590
this section comes with a note mentioning

Note: You might notice that the first line slices the series at split_time - window_size:-1 which is a bit different from the slower for-loop code. That is because we want the model to have its last prediction to align with the last point of the validation set (i.e. t=1460). You were able to do that with the slower for-loop code by specifying the for-loop’s range(). With the more efficient function above, you don’t have that mechanism so you instead just remove the last point when slicing the series. If you don’t, then the function will generate a prediction at t=1461 which is outside the validation set range.

So if you notice, it mention for the loop we mention the range which must have let the model predict at the range when t=1460 but in the case of

Reduce the original series
forecast_series = series[split_time - window_size:-1]

it’s not mentioning a range but series provided with time at which model needs to stop it’s prediction at t=1460. so mentioning that -1 , will stop the function generation at 1460 and not at t=1461 which is outside the validation set range.

1 Like

Thank you @Deepti_Prasad . I figured I misunderstood the concept previously. Given the window_size=20, for example, for time window 0-19, it predicts t=20. So, forecast_series = series[split_time - window_size:-1] actually takes the indexes 980-1459 so that the last prediction predicts the time=1460.

1 Like

I am somehow unable to your other post, I typed thrice my response there but it isn’t accepting.

ok my response went through on that post.

glad you understood.

Keep learning!!!