How it works...
We first imported the train_test_split function from the model_selection module of scikit-learn. In the second step, we showed how to do the most basic split. We passed X and y objects to the train_test_split function. Additionally, we specified the size of the test set, as a fraction of all observations. For reproducibility, we also specified the random state. We also had to assign the output of the function to four new objects.
In Step 3, we took a different approach. By specifying shuffle=False, we assigned the first 80% of the data to the training set and the remaining 20% to the test set. This might come in handy when dealing with time series, where the order of observations matters.
In the last step, we also specified ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access