pub struct StratifiedShuffleSplit<L> { /* private fields */ }Expand description
Stratified random-permutation cross-validation.
Like ShuffleSplit, but every split keeps
approximately the dataset’s class proportions in both its train and test
subsets. Class labels are supplied at construction (generic
L: Eq + Hash + Clone) and stored, so the splitter still satisfies the plain
CvSplitter interface.
Per-class subset sizes are allocated proportionally and rounded, so realised sizes may differ from the requested totals by a sample or two — the guarantee is proportional balance, not an exact global count.
use ndarray::Array1;
use model_selection_rs::splitters::{CvSplitter, StratifiedShuffleSplit, SubsetSize};
let mut v = vec![0; 80];
v.extend(std::iter::repeat(1).take(20));
let y = Array1::from(v);
let sss = StratifiedShuffleSplit::new(3, &y)
.with_test_size(SubsetSize::Fraction(0.2))
.with_seed(0);
let splits = sss.split(100).unwrap();
assert_eq!(splits.len(), 3);Implementations§
Source§impl<L: Eq + Hash + Clone> StratifiedShuffleSplit<L>
impl<L: Eq + Hash + Clone> StratifiedShuffleSplit<L>
Sourcepub fn new(n_splits: usize, y: &Array1<L>) -> Self
pub fn new(n_splits: usize, y: &Array1<L>) -> Self
Create a StratifiedShuffleSplit over class labels y, with a default
test size of 10%.
Sourcepub fn with_test_size(self, test_size: SubsetSize) -> Self
pub fn with_test_size(self, test_size: SubsetSize) -> Self
Set the (approximate) total test-subset size.
Sourcepub fn with_train_size(self, train_size: SubsetSize) -> Self
pub fn with_train_size(self, train_size: SubsetSize) -> Self
Set the (approximate) total train-subset size.
Trait Implementations§
Source§impl<L: Clone> Clone for StratifiedShuffleSplit<L>
impl<L: Clone> Clone for StratifiedShuffleSplit<L>
Source§fn clone(&self) -> StratifiedShuffleSplit<L>
fn clone(&self) -> StratifiedShuffleSplit<L>
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<L: Eq + Hash + Clone> CvSplitter for StratifiedShuffleSplit<L>
impl<L: Eq + Hash + Clone> CvSplitter for StratifiedShuffleSplit<L>
Auto Trait Implementations§
impl<L> Freeze for StratifiedShuffleSplit<L>
impl<L> RefUnwindSafe for StratifiedShuffleSplit<L>where
L: RefUnwindSafe,
impl<L> Send for StratifiedShuffleSplit<L>where
L: Send,
impl<L> Sync for StratifiedShuffleSplit<L>where
L: Sync,
impl<L> Unpin for StratifiedShuffleSplit<L>where
L: Unpin,
impl<L> UnsafeUnpin for StratifiedShuffleSplit<L>
impl<L> UnwindSafe for StratifiedShuffleSplit<L>where
L: 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