pub struct CrossValidation<'a> { /* private fields */ }Expand description
Stratified n-fold cross validation over a dataset, borrowing its rows.
The benign and malicious rows are each shuffled and dealt evenly across the folds, so every fold holds the dataset’s class proportions and every row is tested exactly once. A fold’s training set is every other fold’s rows with the majority class randomly cut down to the size of the minority class, so the model always trains on balanced labels; the rows cut are simply unused by that fold.
Implementations§
Source§impl<'a> CrossValidation<'a>
impl<'a> CrossValidation<'a>
Sourcepub fn new(dataset: &'a Dataset, folds: usize) -> Result<Self>
pub fn new(dataset: &'a Dataset, folds: usize) -> Result<Self>
Deal a dataset’s rows into folds stratified folds.
§Errors
Returns an error if there are fewer than two folds, the dataset fails
Dataset::validate or has no labels, or either class has fewer rows than there are
folds.
Sourcepub fn fold(&self, index: usize) -> Result<Fold<'a>>
pub fn fold(&self, index: usize) -> Result<Fold<'a>>
The training and test sets for one fold.
Which majority-class rows are left out of the training set is chosen afresh on every call, so two calls for the same fold can train on different rows.
§Errors
Returns an error if index isn’t a fold.
Sourcepub fn run_fold(
&self,
index: usize,
epochs: u32,
learning_rate: f32,
l1: f32,
l2: f32,
) -> Result<FoldResult>
pub fn run_fold( &self, index: usize, epochs: u32, learning_rate: f32, l1: f32, l2: f32, ) -> Result<FoldResult>
Train and test a fresh model on one fold, see LogisticRegression::fit.
§Errors
Returns an error if index isn’t a fold or training fails.
§Panics
This won’t panic as there will be a test result.
Sourcepub fn run(
&self,
epochs: u32,
learning_rate: f32,
l1: f32,
l2: f32,
metric: SelectionMetric,
) -> Result<CrossValidationReport>
pub fn run( &self, epochs: u32, learning_rate: f32, l1: f32, l2: f32, metric: SelectionMetric, ) -> Result<CrossValidationReport>
Train and test a fresh model on every fold in turn.
§Errors
Returns an error if any fold fails to train.
Trait Implementations§
Source§impl<'a> Clone for CrossValidation<'a>
impl<'a> Clone for CrossValidation<'a>
Auto Trait Implementations§
impl<'a> Freeze for CrossValidation<'a>
impl<'a> RefUnwindSafe for CrossValidation<'a>
impl<'a> Send for CrossValidation<'a>
impl<'a> Sync for CrossValidation<'a>
impl<'a> Unpin for CrossValidation<'a>
impl<'a> UnsafeUnpin for CrossValidation<'a>
impl<'a> UnwindSafe for CrossValidation<'a>
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
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> ⓘ
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> ⓘ
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