Description Usage Arguments Value Examples
View source: R/utility_functions.R
Utility function to randomly split a data frame into train and test sets.
1 | split_train_test(df, pctTrain)
|
df |
a data frame. |
pctTrain |
numeric value that specifies the percentage of rows to be included in the train set. The remaining rows are added to the test set. |
a list with the first element being the train set and the second element the test set.
1 2 3 4 5 6 7 8 9 10 11 12 13 | set.seed(1234)
dataset <- friedman1
nrow(dataset) # print number of rows
split1 <- split_train_test(dataset, pctTrain = 70) # select 70% for training
nrow(split1$trainset) # number of rows of the train set
nrow(split1$testset) # number of rows of the test set
head(split1$trainset) # display first rows of train set
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.