Mining frequent sequential patterns using the PrefixSpan algorithm
Code: "mining_alg_sequential_pattern.py". Programming language: Python DMelt Version 1. Last modified: 12/08/2015. License: Pro
https://datamelt.org/code/cache/mining_alg_sequential_pattern_4024.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



from ca.pfv.spmf.algorithms.sequentialpatterns.BIDE_and_prefixspan import AlgoPrefixSpan;
from ca.pfv.spmf.algorithms.sequentialpatterns.BIDE_and_prefixspan import SequentialPattern;
from ca.pfv.spmf.algorithms.sequentialpatterns.BIDE_and_prefixspan import SequentialPatterns;
from ca.pfv.spmf.input.sequence_database_list_integers import SequenceDatabase;

# create input data
data="""1 -1 1 2 3 -1 1 3 -1 4 -1 3 6 -1 -2
1 -1 1 2 3 -1 1 3 -1 4 -1 3 6 -1 -2
1 4 -1 3 -1 2 3 -1 1 5 -1 -2
5 6 -1 1 2 -1 4 6 -1 3 -1 2 -1 -2
5 -1 7 -1 1 6 -1 3 -1 2 -1 3 -1 -2
"""
file = open("data.txt", "w")
file.write(data)
file.close()

sequenceDatabase = SequenceDatabase()
sequenceDatabase.loadFile("data.txt")
sequenceDatabase.print()

alg=AlgoPrefixSpan()

# execute the algorithm with minsup = 50 %
out="output.txt"
patterns = alg.runAlgorithm(sequenceDatabase, 0.2, out)
alg.printStatistics(sequenceDatabase.size());

print "result="
print open(out).read()

You see the box below because you did not login.