While building the model, we need to have a training dataset that will be used to train the model, and then we will have a test dataset where the model that we built can be tested. Let's see the procedure to split the dataset into a training set and testing set:
# divide into sample training_positions<- sample(nrow(wcdata), size=floor((nrow(wcdata)*0.7)))
The preceding code will take the sample of a specific size—in this case, it is 70% of the original dataset. We are considering 70% of the data as the training dataset and the remaining will be considered as the test dataset. The dataset will be randomly split; it is very important to split the dataset on a random basis in order to ensure consistency in the behavior mix of the data in the test set as well as the train set. We can use the set.seed()
function to make sure that the output doesn't change while rerunning the code:
# Split into train and test based on the sample size traindata<-wcdata[training_positions...