Get startedGet started for free

Data resampling

The first step in a machine learning project is to create training and test datasets for model fitting and evaluation. The test dataset provides an estimate of how your model will perform on new data and helps to guard against overfitting.

You will be working with the telecom_df dataset which contains information on customers of a telecommunications company. The outcome variable is canceled_service and it records whether a customer canceled their contract with the company. The predictor variables contain information about customers' cell phone and Internet usage as well as their contract type and monthly charges.

The telecom_df tibble has been loaded into your session.

This exercise is part of the course

Modeling with tidymodels in R

View Course

Exercise instructions

  • Create an rsample object, telecom_split, that contains the instructions for randomly splitting the telecom_df data into training and test datasets.
    • Allocate 75% of the data into training and stratify the results by canceled_service.
  • Pass the telecom_split object to the appropriate rsample functions to create the training and test datasets.
  • Check the number of rows in each datasets by passing them to the nrow() function.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create data split object
telecom_split <- ___(___, prop = ___,
                     strata = ___)

# Create the training data
telecom_training <- ___ %>% 
  ___

# Create the test data
telecom_test <- ___ %>% 
  ___

# Check the number of rows
nrow(___)
nrow(___)
Edit and Run Code