What will change if we give timestep = 10 instead of 20 in the code below?
timestep=20
X_list=[]
y_list=[]
for i in range(timestep,len(X)):
X_list.append(np.array(X.iloc[i-timestep:i]))
y_list.append(y.iloc[i])
Could anyone explain the solution to me..
Hello Vinayak,
In this code, we're basically trying to create all data points where we have the last 20 price values. So, we're iterating over the array holding the price using the code:
for i in range(timestep,len(X)):
Thereafter for each iteration, we are creating a new data point. Each data point is an array which holds 20 consecutive price values. This is done using the code:
X.iloc[i-timestep:i]
Which basically slices the last 20 values between i-20 and i. i is the current index of the price array.
Thereafter we store this entire slice/list between i-20 and i as numpy array in a python list. The array is created using the code:
np.array(X.iloc[i-timestep:i]
This array is then stored in the list X_list using the code:
X_list.append(np.array(X.iloc[i-timestep:i]))
Similarly, we store the current y value as well in y_list.
You can do the same for timestep=10. The difference will be that each data point you are storing in X_list will have last 10 values only.