Splitting the dataset into the Training set and Test set
In Machine learning we have to train(teach) the machine with the data set, and at the same time we have test the learning of the machine agains the data set. In this case we have to divide the data set into two set call Training set and Test set.
In Python
from 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)
In R
# Splitting the dataset into Training set and Test set
#install.packages('caTools')
library(caTools)
set.seed(123)
split = sample.split(dataset$Purchased, SplitRatio = 0.8)
# split may be array like: [TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE,TRUE, TRUE, TRUE]
training_set = subset(dataset, split == TRUE)
test_set = subset(dataset, split == FALSE)
* Note: most probably test set size may be 20%
In Python
from 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)
In R
# Splitting the dataset into Training set and Test set
#install.packages('caTools')
library(caTools)
set.seed(123)
split = sample.split(dataset$Purchased, SplitRatio = 0.8)
# split may be array like: [TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE,TRUE, TRUE, TRUE]
training_set = subset(dataset, split == TRUE)
test_set = subset(dataset, split == FALSE)
* Note: most probably test set size may be 20%
Comments
Post a Comment