Fitting model to training data
It's time to split your data into a training set to fit a model and a separate test set to evaluate the predictive power of the model. Before making this split however, we first sample 100% of the rows of house_prices without replacement and assign this to house_prices_shuffled. This has the effect of "shuffling" the rows, thereby ensuring that the training and test sets are randomly sampled.
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Modeling with Data in the Tidyverse
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Set random number generator seed value for reproducibility
set.seed(76)
# Randomly reorder the rows
house_prices_shuffled <- house_prices %>%
sample_frac(size = 1, replace = FALSE)
# Train/test split
train <- house_prices_shuffled %>%
slice(___:___)
test <- house_prices_shuffled %>%
slice(___:___)