Course Name: Introduction to Machine Learning for Trading, Section No: 4, Unit No: 2, Unit type: Notebook
How do I interpret the following line of code, specifically the contents in the square brackets?
diabetes_X_train = diabetes_X[:-20]
What is defined before and after the colon?
diabetes_X_train = diabetes_X[:-20]
This is called the slicing of an array. That is taking elements from one given index to another given index.
The above code slices from the start index to index 20 from the end. If there are 100 elements in a diabetes_X array, the above code will fetch all elements from the start till the 80th element.
Can refer to this to know more about array indexing and slicing.