Skip to main content

train_test_split

Function train_test_split 

Source
pub fn train_test_split(
    n_samples: usize,
    test_size: f64,
    seed: Option<u64>,
) -> CoreResult<SplitIndices>
Expand description

Split data indices into training and test sets.

§Arguments

  • n_samples - Total number of samples
  • test_size - Fraction of data to use for testing (0.0 .. 1.0)
  • seed - Optional random seed for reproducibility

§Example

use scirs2_core::data_split::train_test_split;

let (train, test) = train_test_split(100, 0.2, Some(42)).expect("split failed");
assert_eq!(train.len() + test.len(), 100);
assert_eq!(test.len(), 20);