开始使用免费开始使用

Try an 80/20 split

Now that your dataset is randomly ordered, you can split the first 80% of it into a training set, and the last 20% into a test set. You can do this by choosing a split point approximately 80% of the way through your data:

split <- round(nrow(mydata) * 0.80)

You can then use this point to break off the first 80% of the dataset as a training set:

mydata[1:split, ]

And then you can use that same point to determine the test set:

mydata[(split + 1):nrow(mydata), ]

本练习是课程的一部分

Machine Learning with caret in R

查看课程

练习说明

  • Choose a row index to split on so that the split point is approximately 80% of the way through the diamonds dataset. Call this index split.
  • Create a training set called train using that index.
  • Create a test set called test using that index.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Determine row to split on: split


# Create train


# Create test
编辑并运行代码