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

前端 未结 24 2029
猫巷女王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:08

    I bumped into this one, it can help too.

    set.seed(12)
    data = Sonar[sample(nrow(Sonar)),]#reshufles the data
    bound = floor(0.7 * nrow(data))
    df_train = data[1:bound,]
    df_test = data[(bound+1):nrow(data),]
    

提交回复
热议问题