spmviz.patterns.PatternSet#

class spmviz.patterns.PatternSet(patterns, support, sids=None, n_sequences=None, db=None, params=None)[source]#

Bases: object

Frequent sequential patterns with their supports and supporting sequences.

Parameters:
patternsiterable of patterns
supportarray_like of int

Absolute supports \(\sigma(\varphi)\).

sidslist of array_like, optional

Indices of the supporting sequences of each pattern.

n_sequencesint, optional

Size of the database (taken from db when given).

dbSequenceDatabase, optional

The mined database; needed by analyses that look at the raw sequences.

paramsdict, optional

Parameters of the mining run (algorithm, thresholds, constraints).

Examples

>>> import spmviz as sv
>>> db = sv.SequenceDatabase(["abc", "abd", "acd", "bcd"])
>>> ps = sv.mine(db, min_support=0.5)
>>> len(ps), ps.support_of("a c")
(10, 2)
added_items()[source]#

The item added to the parent (the last item).

children(i=None)[source]#

Children (one-item extensions) of pattern i, or the full list of lists.

closed()[source]#

Closed patterns (no super-pattern with the same support).

confidence()[source]#

Extension confidence \(c(\varphi)=\sigma(\varphi)/\sigma(\pi(\varphi))\) (1 for single items).

cum_confidence()[source]#

Cumulative confidence \(\sigma(\varphi)/\sigma(\langle y_1\rangle)\).

filter(min_support=None, min_length=None, max_length=None, starts_with=None, ends_with=None, contains=None, min_confidence=None, mask=None)[source]#

Select patterns by support, length, first/last item, contained items or confidence.

starts_with/ends_with/contains take an item or a list of items (for contains a pattern, matched as a subpattern).

generators()[source]#

Generator patterns (no sub-pattern with the same support).

incidence(sparse=True)[source]#

Pattern–sequence incidence matrix \(\mathbf{T}\) (patterns in rows).

index_of(p)[source]#

Position of a pattern in the set (KeyError if absent).

labels(style='arrow')[source]#

Text labels of all patterns (style as in spmviz.format_pattern()).

last_items()[source]#

Last item of every pattern.

maximal()[source]#

Maximal patterns (no frequent super-pattern).

measures(**kwargs)[source]#

All pattern measures (see spmviz.measures.pattern_measures()).

parents()[source]#

Index of the parent \(\pi(\varphi)\) of every pattern (-1 for single items or absent parents).

prefix_closure()[source]#

Add the missing prefixes of every pattern (supports from the database).

roots()[source]#

Patterns without a parent in the set (the frequent single items when prefix-closed).

rules(min_confidence=0.0, **kw)[source]#

Sequential rules prefix ⇒ suffix (see spmviz.mining.sequential_rules()).

property sids#

Supporting sequence indices of every pattern (computed from db if missing).

sort(by='support', ascending=False)[source]#

Sorted copy; by is "support", "length", "confidence", "pattern" or a measure.

start_items()[source]#

First item of every pattern.

subset(idx)[source]#

A new pattern set with the selected patterns (order kept).

support_of(p)[source]#

Support of a pattern of the set.

to_frame(style='arrow')[source]#

One row per pattern: label, support, relative support, length, confidences, parent.

to_networkx(kind='extension', **kw)[source]#

A networkx graph of the pattern set: "extension", "lattice" or "similarity".

top(n=20, by='support')[source]#

The n best patterns by a measure.

write(path, **kw)[source]#

Write the pattern set (format from the extension: .csv, .json, .txt (SPMF), .xlsx).