pub fn user_based_split<R: Rng>(
    interactions: &Interactions,
    rng: &mut R,
    test_fraction: f32,
) -> (Interactions, Interactions) {
    let denominator = 100_000;
    let train_cutoff = (test_fraction * denominator as f32) as u64;

    let range = Uniform::new(0, std::u64::MAX);
    let (key_0, key_1) = (range.sample(rng), range.sample(rng));

    let is_train = |x: &Interaction| {
        let mut hasher = SipHasher::new_with_keys(key_0, key_1);
        let user_id = x.user_id();
        hasher.write_usize(user_id);
        hasher.finish() % denominator > train_cutoff
    };

    interactions.split_by(is_train)
}
/// Split interactions between training and test sets so that no user is in both sets.
/// Useful for testing generalization where we want to test the model's performance on
/// users who have not been seen during training.
Split interactions between training and test sets so that no user is in both sets.
Useful for testing generalization where we want to test the model's performance on
users who have not been seen during training.
Split interactions between training and test sets so that no user is in both sets . Useful for testing generalization where we want to test the model ' s performance on users who have not been seen during training .
pub fn user_based_split<R: Rng>(
    interactions: &Interactions,
    rng: &mut R,
    test_fraction: f32,
) -> (Interactions, Interactions) {
    let denominator = 100_000;
    let train_cutoff = (test_fraction * denominator as f32) as u64;
    let range = Uniform::new(0, std::u64::MAX);
    let (key_0, key_1) = (range.sample(rng), range.sample(rng));
    let is_train = |x: &Interaction| {
        let mut hasher = SipHasher::new_with_keys(key_0, key_1);
        let user_id = x.user_id();
        hasher.write_usize(user_id);
        hasher.finish() % denominator > train_cutoff
    };
    interactions.split_by(is_train)
}
pub fn user_based_split < R : Rng > ( interactions : & Interactions , rng : & mut R , test_fraction : f32 , ) -> ( Interactions , Interactions ) { let denominator = 100_000 ; let train_cutoff = ( test_fraction * denominator as f32 ) as u64 ; let range = Uniform :: new ( 0 , std :: u64 :: MAX ) ; let ( key_0 , key_1 ) = ( range . sample ( rng ) , range . sample ( rng ) ) ; let is_train = | x : & Interaction | { let mut hasher = SipHasher :: new_with_keys ( key_0 , key_1 ) ; let user_id = x . user_id ( ) ; hasher . write_usize ( user_id ) ; hasher . finish ( ) % denominator > train_cutoff } ; interactions . split_by ( is_train ) }
Split interactions between training and test sets so that no user is in both sets.
Split interactions between training and test sets so that no user is in both sets .
interactions
&Interactions
rng
&mut R
test_fraction
f32