pat_prefix_span: PrefixSpan sequences

View source: R/pat_prefix_span.R

pat_prefix_spanR Documentation

PrefixSpan sequences

Description

Frequent sequential pattern mining with PrefixSpan.

Usage

pat_prefix_span(
  support = 0,
  support_strategy = pat_support_threshold("min_count", min_count = 2),
  minlen = 1,
  maxlen = NULL,
  maxsize = NULL,
  mingap = NULL,
  maxgap = NULL,
  quality_filter = NULL
)

Arguments

support

minimum support threshold. If 0, estimated during fit() using support_strategy.

support_strategy

support threshold strategy created with pat_support_threshold()

minlen

minimum number of events per pattern

maxlen

maximum number of events per pattern (NULL = unbounded)

maxsize

maximum number of items per event (NULL = unbounded)

mingap

minimum gap between successive events (NULL = unbounded)

maxgap

maximum gap between successive events (NULL = unbounded)

quality_filter

optional quality filter created with patutils()

Details

PrefixSpan (Prefix-projected Sequential pattern mining) discovers frequent sequential patterns – ordered lists of itemsets – by growing patterns one prefix at a time and recursively mining the projected database of suffixes. A pattern grows by an i-extension (adding an item to its last itemset) or an s-extension (appending a new itemset); the support of a pattern is the fraction of input sequences in which it occurs in order. maxlen bounds the number of itemsets, maxsize the items per itemset, and mingap/maxgap constrain the time difference between consecutive matched events.

Sequences are given as a data frame with sequenceID, eventID and item columns, or as a list of sequences (each a list of itemsets, or of list(time, items) events).

Value

returns a pat_prefix_span object

References

Pei, J., Han, J., Mortazavi-Asl, B., Wang, J., Pinto, H., Chen, Q., Dayal, U., & Hsu, M. (2001). PrefixSpan: Mining Sequential Patterns Efficiently by Prefix-Projected Pattern Growth. ICDE, 215-224.

The canonical implementation is maintained in the Python pydaltoolbox port; this is a backport of it.

Examples

seqs <- data.frame(
  sequenceID = c(1,1,1,2,2,3),
  eventID    = c(10,20,20,10,20,10),
  item       = c("A","B","C","A","C","A")
)
pm <- pat_prefix_span(support = 0.5)
pm <- fit(pm, seqs)
seqs_found <- discover(pm, seqs)
evaluate(pm, seqs_found)$metrics

daltoolbox documentation built on Nov. 23, 2026, 9:08 a.m.