Learn R Programming

Buddle (version 2.0.1)

Split2TrainTest: Splitting Data into Training and Test Sets.

Description

Convert data into training and test sets so that the training set contains approximately the specified ratio of all labels.

Usage

Split2TrainTest(Y, X, train.ratio)

Arguments

Y

an n-by-1 vector of responses or labels.

X

an n-by-p design matrix of predictors.

train.ratio

a ratio of the size of the resulting training set to the size of data.

Value

A list of the following values:

y.train

the training set of Y.

y.test

the test set of Y.

x.train

the training set of X.

x.test

the test set of X.

See Also

CheckNonNumeric(), GetPrecision(), FetchBuddle(), MakeConfusionMatrix(), OneHot2Label(), TrainBuddle()

Examples

Run this code
# NOT RUN {
data(iris)

Label = c("setosa", "versicolor", "virginica")


train.ratio=0.8
Y = iris$Species 
X = cbind( iris$Sepal.Length, iris$Sepal.Width, iris$Petal.Length, iris$Petal.Width)

lst = Split2TrainTest(Y, X, train.ratio)

Ytrain = lst$y.train
Ytest = lst$y.test

length(Ytrain)
length(Ytest)

length(which(Ytrain==Label[1]))
length(which(Ytrain==Label[2]))
length(which(Ytrain==Label[3]))

length(which(Ytest==Label[1]))
length(which(Ytest==Label[2]))
length(which(Ytest==Label[3]))




# }

Run the code above in your browser using DataLab