Skip to content

Commit

Permalink
Implement custom create_folds function to replace caret dependency
Browse files Browse the repository at this point in the history
- Add create_folds function for k-fold cross-validation
- Removes dependency on caret::createFolds
- Supports both training and test set index generation
- Allows flexible output as list or vector
  • Loading branch information
sambhavnoobcoder authored Aug 15, 2024
1 parent bf02478 commit 4ae1974
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modules/assim.sequential/R/downscale_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ SDA_downscale_preprocess <- function(data_path, coords_path, date, carbon_pool)
return(list(input_data = input_data, site_coordinates = site_coordinates, carbon_data = carbon_data))
}

create_folds <- function(y, k, list = TRUE, returnTrain = FALSE) {
n <- length(y)
indices <- seq_len(n)
folds <- split(indices, cut(seq_len(n), breaks = k, labels = FALSE))

if (!returnTrain) {
folds <- folds # Test indices are already what we want
} else {
folds <- lapply(folds, function(x) indices[-x]) # Return training indices
}

if (!list) {
folds <- unlist(folds)
}

return(folds)
}

##' @title SDA Downscale Function
##' @name SDA_downscale
##' @author Joshua Ploshay, Sambhav Dixit
Expand Down

0 comments on commit 4ae1974

Please sign in to comment.