In R, using the intial_split() function with the default value (which are 0.75 for testing and 0.25 for training), I get the expected number of rows assigned to the testing split. I demonstrate this below with the randu dataset included in R which has 400 rows, so we expect 300 (400 * 0.75) in the training split and 100 (400 * 0.25) in the testing slipt. Here is the code and outputs:
> nrow(randu)
[1] 400
> randu_split <- initial_split(randu)
> randu_train <- training(randu_split)
> randu_test <- testing(randu_split)
> nrow(randu_train)
[1] 300
> nrow(randu_test)
[1] 100
However, when the proportion to attribute to the training and testing are changed to 0.80 and 0.20 using the proportion argument (prop = 4/5), the number of rows assigned to the different split is different than what is expected. In a dataset with 400 rows, I would expect 320 (400 * 0.80) in the training split and 80 (400 * 0.20) in the testing split.
> 400*0.8
[1] 320
> 400*0.2
[1] 80
However, this is not what I observed. Please see results below:
> randu_split_80_20 <- initial_split(randu, prop = 4/5)
> randu_train_eighty <- training(randu_split_80_20)
> randu_test_twenty <- testing(randu_split_80_20)
> nrow(randu_train_eighty)
[1] 321
> nrow(randu_test_twenty)
[1] 79
> nrow(randu_split_80_20)
analysis
321
Why is the intial_split() function with prop = 4/5 assigning 321 and not 320 rows to the training split? I tried this with different datasets and the assignment is always off by one. I also tried with prop = 9/10, and the number of samples returned in the split are also off by one compared to the expected number. Any ideas?