Repository navigation
Fix validation and fold assignment in get_k_folds - #302
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The fold-splitting code mishandles non-finite and out-of-range k values and introduces O(n × k) grouping, causing quadratic work for leave-one-out assignments.
2 open issues
What changed in this PR
Updates get_k_folds() in the data-preprocessing utilities to validate inputs and produce consistent, balanced cross-validation assignments.
Changes:
- Adds checks for empty
y, invalidk, and invalidisList. - Uses one seeded random assignment for both return formats, with fold sizes differing by at most one observation.
- Clarifies parameter descriptions and return formats in comments.
| File | Description |
|---|---|
data_preprocessing/k_folds.r |
Adds input validation and replaces matrix-based grouping with shared randomized fold IDs. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes
get_k_folds()indata_preprocessing/k_folds.r.The function now validates its inputs and reports clear errors when
yis empty orkis invalid. Fold assignments are generated once, so the list and vector return formats represent the same randomized, reproducible assignment. Fold sizes differ by at most one observation.Tests
kvalues produce a clear error.