Docs · Machine learning

seq: sequential pattern mining.

Frequent sequential patterns, the equivalent of Spark MLlib's PrefixSpan restricted to single-item elements.

Module
ml_seq
Header
clio_ml/sequential_patterns.h

What it does

Frequent sequential patterns, the equivalent of Spark MLlib's PrefixSpan restricted to single-item elements. Level K candidates are frequent (K-1)-patterns extended by one frequent item and pruned unless every subsequence is frequent; support is counted in one paged pass per level. Counts are integers, so results are exact.

Rows

One sequence per row: L item ids stored as floats, padded with -1. clio_ml.COLUMNS["seq"] is 0.

Python

python
import numpy as np, clio_ml as cm
r = cm.fit_seq(S, num_items=500, min_support=0.05)   # S: item ids, -1 padded
for p in r.patterns[:5]: print(p.items, p.count)
  • fit_seq(X, **options) accepts an in-memory array or a paged Dataset from cm.dataset(X) or cm.assimilate(...).
  • Options: num_items (required), min_support (0.1, fraction of sequences), max_pattern_length (3), threads (256).
  • Result SequentialPatternResult: patterns (each with items and count, sorted by length then items), stats.

C++

cpp
SequentialPatternResult MineSequentialPatterns(Dataset &ds,
                                               const SequentialPatternOptions &opt);
SequentialPatternResult MineSequentialPatternsPlain(const float *data, u64 n_rows, u32 len,
                                                    u64 elems_per_page, u32 nblocks,
                                                    const SequentialPatternOptions &opt);

The paged call needs the runtime; the Plain call runs the same kernel over a plain copy of the data without one.

Related: frequent itemsets. Back to the machine learning overview.