X_train=np.array(X.iloc[:-test_size])
y_train=np.array(y[:-test_size])
X_test=np.array(X.iloc[-test_size:])
y_test=np.array(y[-test_size:])
- I know that a -ve sign means taking the last of something. But is it really necessary to put a -ve sign in front of the test size?
- Why does X feature dataset makes use of iloc while y target dataset doesn't?
Hi Sean!
This code snippet is from which course/unit?
Thanks.
It's from neural networks in trading: DNN trading strategy
Hi Sean,
Please refer to the screenshot below:
- The X is a DataFrame and y is an array. "iloc" is a good way to extract rows from the DataFrame.
- The method without iloc also works on DataFrame , and the output is identical as can be seen in the code snippet above.
- The example of index slicing is shown which will help you understand that [-size:] chooses the last "size" number objects from the list.
- The [:-size] chooses the numbers except the last "size" objects in the list.
Hope this helps!