Package: pycspade
PycspadeWhat is this?This is a python wrapper for the C++ implementation of C-SPADE algorithm by the author, Mohammed J. Zaki
Original code was downloaded fromhttp://www.cs.rpi.edu/~zaki/www-new/pmwiki.php/Software/Software#toc11Since this is just a wrapper it is as fast as the C++ codeHow to install?Compatible with Python 2 and 3.
On Windows, Visual Studio 2015 Build Tools is also required.pipinstallCythonpycspadeHow to use?Your data needs to be in a particular format similar to the following:1 1 3 8 37 42
1 2 4 4 11 37 42
2 1 2 10 73
2 2 1 72
2 3 3 4 24 77
...The first number is the sequence index, the second is the event index, the third is the number of elements,
followed by the element, space separatedLet's call this filedata.txt. You will call cspade as following:frompycspade.helpersimportspade,print_result# To get raw SPADE outputresult=spade(filename='tests/zaki.txt',support=0.3,parse=False)print(result['mined'])1--442--444--226--444->6--224->2--222->1--224->1--226->1--224->6->1--224->2->1--22print(result['logger'])CONF492.72.5
args.MINSUPPORT24MINMAX141SUPP42SUPP44SUPP26SUPP4numfreq4:SUMSUPSUMDIFF=00EXTRARYSZ2465792OPENED/tmp/cspade-WWv9bQWBYdDyH85T.idx
OFF938WroteOfftBOUNDS15WROTEINVERTCleanedupsuccessful:/tmp/cspade-WWv9bQWBYdDyH85T.tpose
Cleanedupsuccessful:/tmp/cspade-WWv9bQWBYdDyH85T.idx
Cleanedupsuccessful:/tmp/cspade-WWv9bQWBYdDyH85T.data
Cleanedupsuccessful:/tmp/cspade-WWv9bQWBYdDyH85T.confprint(result['summary'])CONF492.52.710140.7810254TPOSESEQNOF2/tmp/cspade-WWv9bQWBYdDyH85T.data0.3421F1stats=[400]SPADE/tmp/cspade-WWv9bQWBYdDyH85T.tpose0.32700000-11100100452000000000000000000000000000000000000000000000000000000000000000000000000000000# To also get other sequence mining's measures, incl. lift, support, confidence:result=spade(filename='tests/zaki.txt',support=0.3,parse=True)# Pretty print result:print_result(result)OccursAccumSupportConfidLiftSequence4141.0000000N/AN/A(1)461.0000000N/AN/A(2)240.50000000.50000000.5000000(2)->(1)220.5000000N/AN/A(4)220.50000001.00000001.0000000(4)->(1)220.50000001.00000001.0000000(4)->(2)220.50000001.00000001.0000000(4)->(2)->(1)220.50000001.00000001.0000000(4)->(6)220.50000001.00000001.0000000(4)->(6)->(1)461.0000000N/AN/A(6)240.50000000.50000000.5000000(6)->(1)You can provide cspade with list of sequences instead of a file:data=[[1,10,[3,4]],[1,15,[1,2,3]],[1,20,[1,2,6]],[1,25,[1,3,4,6]],[2,15,[1,2,6]],[2,20,[5]],[3,10,[1,2,6]],[4,10,[4,7,8]],[4,20,[2,6]],[4,25,[1,7,8]]]result=spade(data=data,support=0.01)print_result(result)The resultseqis a string, that have multiple rows and looks like this:22 80 -> 72 -> 42 -> 22 -- 2 2
22 -> 45 71 -> 42 -- 1 1
80 -> 45 71 -> 42 -- 1 1
22 80 -> 45 71 -> 42 -- 1 1Let's decipher the first row:2280->72->42->22--22It gives you the frequent sequence followed by support (the last two numbers, which will be the same in this application).
The row reads: the itemset (22 80) is followed by (72) followed by (42) followed by (22).There're a lot of parameters that can be passed to this function. most important ones are:support: this is the minimum support level, default to 0 (not excluding anything)max_gap: The max number of itemset that can be skipped in a sequencemin_gap: The min number of itemset that must be skipped in a sequenceRead the original paper and the C++ implementation for more detailsHow to contribute?Fork this repoMake changePull requestHow to recompile to use in IDE?rm cspade.cpp; python setup.py build_ext --inplaceLicenceMIT