Docs · Machine learning
fim: frequent itemsets and association rules.
Mines every itemset whose support is at least min_support, plus association rules, with the same output as Spark MLlib's FPGrowth. Candidates of size L are generated on the host from the frequent (L-1)-itemsets and counted in one paged pass per level.
- Module
- ml_fim
- Header
- clio_ml/frequent_itemsets.h
- Rows
- one 0/1 column per item
What it does
Counts are integers, so the result is exact and independent of paging or block order. Itemsets are returned sorted by size and then by items. Rules have a single consequent item.
Rows
One transaction per row with one 0/1 column per item. clio_ml.COLUMNS["fim"] is 0.
Python
python
import numpy as np, clio_ml as cm
T = (np.random.default_rng(1).random((4096, 8)) < 0.4).astype(np.float32)
r = cm.fit_fim(T, min_support=0.1, min_confidence=0.6, max_size=4)
for s in r.itemsets[:5]:
print(s.items, s.count)
for rule in r.rules[:5]:
print(rule.antecedent, "->", rule.consequent, rule.confidence, rule.lift)fit_fim(X, **options)callsMineFrequentItemsets.- Options (
FrequentItemsetOptions):min_support(0.05, fraction of transactions),min_confidence(0.6, for rules),max_size(4),threads(256). - Result
FrequentItemsetResult:itemsets(list ofItemsetwith ascendingitemsandcount),rules(list ofAssociationRulewithantecedent,consequent,confidence,lift),stats.
C++
cpp
struct FrequentItemsetOptions {
float min_support = 0.05f;
float min_confidence = 0.6f;
u32 max_size = 4;
u32 threads = 256;
ClusterExchange cluster;
};
struct Itemset { std::vector<u32> items; u64 count = 0; };
struct AssociationRule {
std::vector<u32> antecedent;
u32 consequent = 0;
double confidence = 0, lift = 0;
};
struct FrequentItemsetResult {
std::vector<Itemset> itemsets; // sorted by (size, items)
std::vector<AssociationRule> rules;
VecStats stats;
std::vector<float> Flatten() const;
};
FrequentItemsetResult MineFrequentItemsets(Dataset &ds, const FrequentItemsetOptions &opt);
FrequentItemsetResult MineFrequentItemsetsPlain(const float *data, u64 n_rows, u32 n_items,
u64 elems_per_page, u32 nblocks,
const FrequentItemsetOptions &opt);
FrequentItemsetResult MineFrequentItemsetsReference(/* same arguments */);The ChiMod is module ml_fim.
Related: sequential patterns, LDA.