How to split data into training/testing sets using sample function

前端 未结 24 1993
猫巷女王i
猫巷女王i 2020-11-22 10:43

I\'ve just started using R and I\'m not sure how to incorporate my dataset with the following sample code:

sample(x, size, replace = FALSE, prob = NULL)
         


        
24条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 11:04

    I can suggest using the rsample package:

    # choosing 75% of the data to be the training data
    data_split <- initial_split(data, prop = .75)
    # extracting training data and test data as two seperate dataframes
    data_train <- training(data_split)
    data_test  <- testing(data_split)
    

提交回复
热议问题