Type Alias TrainTestSplitResult

Source
pub type TrainTestSplitResult<F> = (Array<F, IxDyn>, Array<F, IxDyn>, Array<F, IxDyn>, Array<F, IxDyn>);
Expand description

Split data into training and testing sets

§Arguments

  • x - Input data array
  • y - Target data array
  • test_size - Fraction of data to use for testing (between 0 and 1)
  • shuffle - Whether to shuffle the data before splitting
  • rng - Random number generator (only used if shuffle is true)

§Returns

  • A tuple of (x_train, x_test, y_train, y_test)

§Examples

use scirs2_neural::utils::train_test_split;
use ndarray::{Array, arr2};
use rand::rngs::SmallRng;
use rand::SeedableRng;

let mut rng = SmallRng::seed_from_u64(42);
let x = arr2(&[[1.0f64, 2.0], [3.0, 4.0], [5.0, 6.0], [7.0, 8.0]]).into_dyn();
let y = arr2(&[[0.0f64], [1.0], [0.0], [1.0]]).into_dyn();

let (x_train, x_test, y_train, y_test) =
    train_test_split::<f64, _>(&x, &y, 0.25, true, &mut rng).unwrap();

// Note: Since the implementation is incomplete (TODO in the code),
// we're just checking that the shapes are what we expect
assert_eq!(x_train.shape()[0], 3);
assert_eq!(x_train.shape()[1], 2);
assert_eq!(x_test.shape()[0], 1);
assert_eq!(x_test.shape()[1], 2);

Result type for train/test split