pub struct CrossValidation {
pub number_of_folds: i64,
pub stratified: bool,
pub random_seed: i64,
pub scheme_name: String,
pub description: String,
}Expand description
Partition-based scheme for estimating generalization performance.
Fields§
§number_of_folds: i64Number of folds.
stratified: boolWhether folds are stratified.
random_seed: i64Random seed.
scheme_name: StringUnique name identifying a resampling scheme.
description: StringFree-text description.
Implementations§
Source§impl CrossValidation
impl CrossValidation
Sourcepub fn run(
&self,
n: usize,
fit_score: impl FnMut(&[usize], &[usize]) -> f64,
) -> Result<CvScores>
pub fn run( &self, n: usize, fit_score: impl FnMut(&[usize], &[usize]) -> f64, ) -> Result<CvScores>
Runs k-fold cross-validation using this scheme’s own configuration.
Reads the fold count from number_of_folds and
seeds the deterministic PRNG from random_seed, then
delegates to cross_validate. The i64 seed is reinterpreted to u64
bit-for-bit via i64::cast_unsigned (not a numeric as cast, which the
style.rs guard bans), so a positive seed maps to the same magnitude.
This makes the parameter struct itself executable against the numerics.
§Arguments
n— number of observations to partition into folds.fit_score— invoked once per fold asfit_score(train_idx, test_idx), returning that fold’s score.
§Returns
The aggregated CvScores over the configured number of folds.
§Errors
Error::InvalidInputwhennumber_of_foldsis negative or unrepresentable asusize, or when the resolved fold count is< 2(matchingStratifiedCrossValidation::folds).Error::InsufficientDatawhen the fold count exceedsn.
§Examples
use stats_claw::resampling::CrossValidation;
let cv = CrossValidation { number_of_folds: 5, random_seed: 42, ..Default::default() };
let scores = cv.run(20, |_train, _test| 1.0)?;
assert_eq!(scores.fold_scores().len(), 5);
// Every fold scored 1.0, so the mean is 1.0 and the spread is zero.
assert!((scores.mean() - 1.0).abs() < 1e-12);
assert!(scores.std_error().abs() < 1e-12);Trait Implementations§
Source§impl Clone for CrossValidation
impl Clone for CrossValidation
Source§fn clone(&self) -> CrossValidation
fn clone(&self) -> CrossValidation
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 Debug for CrossValidation
impl Debug for CrossValidation
Source§impl Default for CrossValidation
impl Default for CrossValidation
Source§fn default() -> CrossValidation
fn default() -> CrossValidation
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CrossValidation
impl RefUnwindSafe for CrossValidation
impl Send for CrossValidation
impl Sync for CrossValidation
impl Unpin for CrossValidation
impl UnsafeUnpin for CrossValidation
impl UnwindSafe for CrossValidation
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