利用caret包的createDataPartition()函数将数据集分为一定比例的训练集和验证集
Create the training and test datasets
set.seed(100)
记下随机数种子,以便重复结果
Step 1: Get row numbers for the training data
trainRowNumbers <- createDataPartition(data$diabetes, p=0.8, list=FALSE)
p值为训练集所占比例(p=0.8, train:test = 4:1)
createDataPartition()返回行号
list=F以防止将结果作为列表返回
Step 2: Create the training dataset
train.data <- data[trainRowNumbers,]
Step 3: Create the test dataset
test.data <- data[-trainRowNumbers,]