pub struct GroupKFold<G> { /* private fields */ }Expand description
Group K-fold cross-validation.
Guarantees that the samples of any one group (e.g. a patient id, a user id)
never straddle the train/test boundary within a fold. Group leakage — the
same entity contributing rows to both training and evaluation — is an
easy-to-miss correctness bug in real ML work; this splitter makes it
structurally impossible, complementing what
StratifiedKFold does for class balance.
Groups are assigned whole to folds using a greedy largest-group-first heuristic (the same idea scikit-learn uses): repeatedly place the largest remaining group into the fold that currently holds the fewest samples. This keeps fold sizes close without ever splitting a group.
The number of splits must not exceed the number of distinct groups.
use ndarray::array;
use model_selection_rs::splitters::{CvSplitter, GroupKFold};
let groups = array![1, 1, 2, 2, 3, 3, 4, 4];
let gkf = GroupKFold::new(2, &groups).unwrap();
let splits = gkf.split(groups.len()).unwrap();
assert_eq!(splits.len(), 2);Implementations§
Trait Implementations§
Source§impl<G: Clone> Clone for GroupKFold<G>
impl<G: Clone> Clone for GroupKFold<G>
Source§fn clone(&self) -> GroupKFold<G>
fn clone(&self) -> GroupKFold<G>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<G: Eq + Hash + Clone> CvSplitter for GroupKFold<G>
impl<G: Eq + Hash + Clone> CvSplitter for GroupKFold<G>
Auto Trait Implementations§
impl<G> Freeze for GroupKFold<G>
impl<G> RefUnwindSafe for GroupKFold<G>where
G: RefUnwindSafe,
impl<G> Send for GroupKFold<G>where
G: Send,
impl<G> Sync for GroupKFold<G>where
G: Sync,
impl<G> Unpin for GroupKFold<G>where
G: Unpin,
impl<G> UnsafeUnpin for GroupKFold<G>
impl<G> UnwindSafe for GroupKFold<G>where
G: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more