Split2TrainTest: Splitting Data into Training and Test Sets.

Description Usage Arguments Value See Also Examples

View source: R/BuddleMain.R

Description

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

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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]))

Buddle documentation built on Feb. 13, 2020, 5:07 p.m.