16. Splitting the Dataset into the Training set and Test set
MAKING THE MACHINE LEARNING MODELS
Activity
Splitting the Datasets in Python
# Splitting the dataset into the Training set and Test set
import sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)Splitting the Datasets in R
# Splitting the data set into the Training set and Test set
# install.packages('caTools')
set.seed(123)
split = sample.split(datasets$Purchased, SplitRatio = 0.8)
training_set = subset(dataset, split == TRUE)
test_set = subset(dataset, split == FALSE)Last updated