train_test {lessR} | R Documentation |
Create Training and Testing Data
Description
Given a data frame, create a list of either two components, train
and test
, or four components, for training and testing data: train_x
, train_y
, test_x
, and test_y
.
Usage
train_test(data, response=NULL, p_train=0.75, seed=NULL, matrix_out=FALSE)
Arguments
data |
Data frame that contains the variables. |
response |
Optional name of the response variable of the response values. |
p_train |
Percentage of the input data frame to be retained for training. |
seed |
Set to a usually odd value to reproduce results. |
matrix_out |
If |
Details
From the input data frame create training and testing data frames. If the response
is specified, create four component data frames with x and y variables separated. Otherwise create two component data frames, train
and test
.
Author(s)
David W. Gerbing (Portland State University; gerbing@pdx.edu)
Examples
d <- Read("Employee")
# create four component data frames that separate the response variable, y,
# from predictor variables, X: train_x, train_y, test_x, and test_y
out <- train_test(d, response=Salary)
names(out)
# then can copy to regular data frames apart from the list output structure
X_train <- out$train_x
y_train <- out$train_y
X_test <- out$test_x
y_test <- out$test_y
# create two component data frames, train and test, which retain all
# variables for the model in the same data frame
out <- train_test(d)
names(out)
# then can copy to regular data frames apart from the list output structure
d_train <- out$train
d_test <- out$test
[Package lessR version 4.3.6 Index]