Split2TrainTest {Buddle} | R Documentation |
Convert data into training and test sets so that the training set contains approximately the specified ratio of all labels.
Split2TrainTest(Y, X, train.ratio)
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. |
A list of the following values:
the training set of Y.
the test set of Y.
the training set of X.
the test set of X.
CheckNonNumeric(), GetPrecision(), FetchBuddle(), MakeConfusionMatrix(), OneHot2Label(), TrainBuddle()
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]))