The test-train split
In a disciplined machine learning workflow it is crucial to withhold a portion of your data (testing data) from any decision-making process. This allows you to independently assess the performance of your model when it is finalized. The remaining data, the training data, is used to build and select the best model.
In this exercise, you will use the rsample
package to split your data to perform the initial train-test split of your gapminder
data.
Note: Since this is a random split of the data it is good practice to set a seed before splitting it.
This is a part of the course
“Machine Learning in the Tidyverse”
Exercise instructions
- Split your data into 75% training and 25% testing using the
initial_split()
function and assign it togap_split
. - Extract the training data frame from
gap_split
using thetraining()
function. - Extract the testing data frame from
gap_split
using thetesting()
function. - Ensure that the dimensions of your new data frames are what you expected by using the
dim()
function ontraining_data
andtesting_data
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
set.seed(42)
# Prepare the initial split object
gap_split <- initial_split(___, prop = ___)
# Extract the training data frame
training_data <- ___
# Extract the testing data frame
testing_data <- ___
# Calculate the dimensions of both training_data and testing_data
dim(___)
dim(___)