Learn R Programming

ModelMap (version 2.3.4)

get.test: Randomly Divide Data into Training and Test Sets

Description

Uses random selection to split a dataset into training and test data sets

Usage

get.test(proportion.test, qdatafn = NULL, seed = NULL, folder=NULL, 
qdata.trainfn = paste(strsplit(qdatafn, split = ".csv")[[1]], "_train.csv", sep = ""), 
qdata.testfn = paste(strsplit(qdatafn, split = ".csv")[[1]], "_test.csv", sep = ""))

Arguments

proportion.test
Number. The proportion of the training data that will be randomly extracted for use as a test set. Value between 0 and 1.
qdatafn
String. The name (basename or full path) of the data file to be split into training and test data. This data should include both response and predictor variables. The file must be a comma-delimited file *.csv) with column headings and the pre
seed
Integer. The number used to initialize randomization to randomly select rows for a test data set. If you want to produce the same model later, use the same seed. If seed = NULL (the default), a new one is created each time.
folder
String. The folder used for all output from predictions and/or maps. Do not add ending slash to path string. If folder = NULL (default), a GUI interface prompts user to browse to a folder. To use the working directory, specify folde
qdata.trainfn
String. The name of the file output of training data. By default, _train appended after qdatafn.
qdata.testfn
String. The name of the file output of test data. By default, _test appended after qdatafn.

Value

  • Outputs a training data file and test data file. Unless qdata.trainfn or qdata.testfn are specified, the output will be located in the same folder as the original data file (qdatafn). The output will have the same rows and columns as the original data.

Details

This function should be run once, before starting analysis to create training and test sets. If the cross validation option is to be used with RF or SGB models, or if the OOB option is to be used for RF models, then this step is unnecessary.

Examples

Run this code
qdatafn<-system.file("external", "helpexamples","DATATRAIN.csv", package = "ModelMap")

qdata<-read.table(file=qdatafn,sep=",",header=TRUE,check.names=FALSE)

get.test(	proportion.test=0.2,
		qdatafn=qdatafn,
		seed=42,
		folder=getwd(),
		qdata.trainfn="example.train.csv",
		qdata.testfn="example.test.csv")

Run the code above in your browser using DataLab