pub fn generate_frequent_itemsets(
    raw_transactions: Vec<RawTransaction>,
    min_support: f32,
    k: ItemsetLength,
) -> (FrequentItemsets, Inventory) {
    let mut all_frequent_itemsets: FrequentItemsets = HashMap::with_capacity(k);
    let N = raw_transactions.len() as f32;
    let min_support_count = (min_support * N).ceil() as usize;

    // 1-itemset
    let (item_counts, inventory, mut transactions) =
        generate_frequent_1_itemset_counts(raw_transactions, min_support);

    // 2-itemset
    if k == 1 {
        let frequent_1_itemset_counts: ItemsetCounts = convert_to_itemset_counts(item_counts);
        all_frequent_itemsets.insert(1, frequent_1_itemset_counts);
    } else {
        transactions.retain(|transaction| transaction.len() >= 2);
        let candidates = item_counts.keys().combinations(2);
        let frequent_2_itemset_counts: ItemsetCounts =
            generate_frequent_2_itemset_counts(
                candidates,
                &transactions,
                min_support_count,
            );
        let frequent_1_itemset_counts: ItemsetCounts = convert_to_itemset_counts(item_counts);

        all_frequent_itemsets.insert(1, frequent_1_itemset_counts);
        all_frequent_itemsets.insert(2, frequent_2_itemset_counts);
    }

    // k-itemset, k >= 3
    for size in 3..=k {
        transactions.retain(|transaction| transaction.len() >= size);
        let candidates = generate_candidates_from_prev(&all_frequent_itemsets[&(size - 1_usize)]);
        let frequent_itemset_counts = generate_frequent_k_itemset_counts(
            candidates,
            &transactions,
            min_support_count,
        );

        all_frequent_itemsets.insert(size, frequent_itemset_counts);
    }

    (all_frequent_itemsets, inventory)
}
/// Generate frequent itemsets from a list of transactions.
Generate frequent itemsets from a list of transactions.
Generate frequent itemsets from a list of transactions .
pub fn generate_frequent_itemsets(
    raw_transactions: Vec<RawTransaction>,
    min_support: f32,
    k: ItemsetLength,
) -> (FrequentItemsets, Inventory) {
    let mut all_frequent_itemsets: FrequentItemsets = HashMap::with_capacity(k);
    let N = raw_transactions.len() as f32;
    let min_support_count = (min_support * N).ceil() as usize;
    // 1-itemset
    let (item_counts, inventory, mut transactions) =
        generate_frequent_1_itemset_counts(raw_transactions, min_support);
    // 2-itemset
    if k == 1 {
        let frequent_1_itemset_counts: ItemsetCounts = convert_to_itemset_counts(item_counts);
        all_frequent_itemsets.insert(1, frequent_1_itemset_counts);
    } else {
        transactions.retain(|transaction| transaction.len() >= 2);
        let candidates = item_counts.keys().combinations(2);
        let frequent_2_itemset_counts: ItemsetCounts =
            generate_frequent_2_itemset_counts(
                candidates,
                &transactions,
                min_support_count,
            );
        let frequent_1_itemset_counts: ItemsetCounts = convert_to_itemset_counts(item_counts);
        all_frequent_itemsets.insert(1, frequent_1_itemset_counts);
        all_frequent_itemsets.insert(2, frequent_2_itemset_counts);
    }
    // k-itemset, k >= 3
    for size in 3..=k {
        transactions.retain(|transaction| transaction.len() >= size);
        let candidates = generate_candidates_from_prev(&all_frequent_itemsets[&(size - 1_usize)]);
        let frequent_itemset_counts = generate_frequent_k_itemset_counts(
            candidates,
            &transactions,
            min_support_count,
        );
        all_frequent_itemsets.insert(size, frequent_itemset_counts);
    }
    (all_frequent_itemsets, inventory)
}
pub fn generate_frequent_itemsets ( raw_transactions : Vec < RawTransaction > , min_support : f32 , k : ItemsetLength , ) -> ( FrequentItemsets , Inventory ) { let mut all_frequent_itemsets : FrequentItemsets = HashMap :: with_capacity ( k ) ; let N = raw_transactions . len ( ) as f32 ; let min_support_count = ( min_support * N ) . ceil ( ) as usize ; // 1-itemset let ( item_counts , inventory , mut transactions ) = generate_frequent_1_itemset_counts ( raw_transactions , min_support ) ; // 2-itemset if k == 1 { let frequent_1_itemset_counts : ItemsetCounts = convert_to_itemset_counts ( item_counts ) ; all_frequent_itemsets . insert ( 1 , frequent_1_itemset_counts ) ; } else { transactions . retain ( | transaction | transaction . len ( ) >= 2 ) ; let candidates = item_counts . keys ( ) . combinations ( 2 ) ; let frequent_2_itemset_counts : ItemsetCounts = generate_frequent_2_itemset_counts ( candidates , & transactions , min_support_count , ) ; let frequent_1_itemset_counts : ItemsetCounts = convert_to_itemset_counts ( item_counts ) ; all_frequent_itemsets . insert ( 1 , frequent_1_itemset_counts ) ; all_frequent_itemsets . insert ( 2 , frequent_2_itemset_counts ) ; } // k-itemset, k >= 3 for size in 3 ..= k { transactions . retain ( | transaction | transaction . len ( ) >= size ) ; let candidates = generate_candidates_from_prev ( & all_frequent_itemsets [ & ( size - 1_usize ) ] ) ; let frequent_itemset_counts = generate_frequent_k_itemset_counts ( candidates , & transactions , min_support_count , ) ; all_frequent_itemsets . insert ( size , frequent_itemset_counts ) ; } ( all_frequent_itemsets , inventory ) }
Generate frequent itemsets from a list of transactions.
Generate frequent itemsets from a list of transactions .
raw_transactions
Vec<RawTransaction>
min_support
f32
k
ItemsetLength
raw_transactions
Vec<RawTransaction>
min_support
f32
k
ItemsetLength