Appendix B
From the NbVFS scripts to spmviz
The scripts published with the NBVFS paper [5] run as a chain of programs that exchange CSV files: Data_prep.py converts the log to the SPMF format, runs CM-SPAM with the SPMF Java library and computes parents, confidences and cumulative confidences; NbVFS-WG.py, NbVFS-CM.py and NbVFS-TM.py draw the three views with pyvis, scikit-learn and Matplotlib. Every step has a counterpart in spmviz, listed below; no intermediate file is needed, and every intermediate result is an object that can be inspected.
Data preparation and mining
|
NbVFS scripts |
spmviz |
|
reading ind_log.csv or Transactional_database.csv |
SequenceDatabase.from_event_log; bundled as datasets.load_alarm_log, load_clickstream |
|
SPMF Convert_a_sequence_database_to_SPMF_format |
not needed; io.write_spmf if SPMF is used |
|
SPMF CM-SPAM with minimum support, lengths, maximum gap |
sv.mine(db, min_support, algorithm="cmspam", max_gap=..., max_length=...), or algorithm="spmf" |
|
parsing Freqseqs.csv (#SUP, #SID) |
io.read_patterns |
|
Sequences.csv: patterns, supports, lengths |
ps.to_frame() |
|
Sequence_attributes.csv: parent, confidence, P_conf, C_conf, added event |
ps.parents(), ps.confidence(), ps.cum_confidence(), ps.to_frame() columns confidence, cum_confidence, added |
|
filter by first event (filt, filt_ev) |
ps.filter(starts_with=...) or NBVFS(..., start_items=[...]) |
The three views
|
NbVFS scripts |
spmviz |
|
NbVFS-WG.py: NetworkX graph of parents and children, pyvis rendering |
NBVFS("wn").fit(ps); .graph_ is the NetworkX graph, .plot() draws it, interactive.to_pyvis gives the pyvis view |
|
random node colors per length |
a fixed, color-blind-safe palette by length [84] |
|
edge value from the child’s confidence |
weight="confidence" (extension confidence, the definition of the paper) or weight="cumulative" |
|
NbVFS-CM.py: Adj_matrix_C.csv, , max-product closure by repeated matrix products |
networks.confidence_matrix, networks.transitive_confidence (one Floyd–Warshall pass) |
|
NbVFS-TM.py: Adj_matrix_T.csv, Jaccard similarity |
ps.incidence(), measures.transaction_similarity(ps, "jaccard") |
|
sklearn.manifold.MDS on |
embedding.mds(1 - S, "sklearn"), or the deterministic default "smacof" started from classical scaling |
|
Matplotlib scatter with parent edges, highlighted start events |
NBVFS("cm").fit(ps).plot(start_items=[...]), NBVFS("tm") |
|
— |
NBVFS("fused"), pattern_communities, sublogs (new) |
A complete translation
The whole analysis of the paper for the click-stream, from the raw log to the three views and their files for Gephi, is
import spmviz as sv db = sv.datasets.load_clickstream() ps = sv.mine(db, min_support=0.01, algorithm="cmspam", max_gap=1, max_length=10) for view in ("wn", "cm", "tm"): model = sv.NBVFS(view, start_items=[2] if view == "wn" else None).fit(ps) model.plot() model.write(f"clickstream_{view}.gexf") # positions, colors, sizes for Gephi