Preparing the Test Dataset

Learn how to split data into training and test datasets, and then prepare the test dataset for predictions.

Splitting the data

The first step of any machine learning project is splitting the data into training and test datasets. The training dataset is used throughout crafting machine learning models, including exploratory data analysis (EDA), feature engineering, training, and tuning. The test dataset is used at the end of the project as the final test of a machine learning model’s prediction quality.

The rsample package offers the initial_split(), training(), and testing() functions for splitting data. The following code demonstrates using the Adult Census Income dataset:

Get hands-on with 1400+ tech skills courses.