Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyTedde committed Jan 10, 2022
1 parent ea1b575 commit 7b4ad08
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions R/partition.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ create_kfold <- function(X, k = 10, strata, seed){
create_kfold_closure <- function(x){
partition_size <- floor(x / k)
remainder <- x %% k
c(rep(1:k, partition_size), sample(k, size = remainder))
# Partition_item is the vector of the fold ids. Try the best to have
# sensitively the same number of items by fold
partition_item <- c(rep(1:k, partition_size), sample(k, size = remainder))
# Return a randomized vector of items
sample(partition_item, size = length(partition_item))
}
# -- Closure function that create the data partitions -- #

# -- Do the data partitions need to be stratified ? -- ####
if(missing(strata)){
K <- create_kfold_closure(nrow(X))
sample(K, size = length(K))
}else{
id <- X[[strata]]
id_ord <- order(id)
Expand Down

0 comments on commit 7b4ad08

Please sign in to comment.