Package: gsp-python
GSP-pythonA Python implementation of the Generalized Sequential Patterns (GSP) algorithm for sequential pattern miningThis project implements the Generalized Sequential Patterns (GSP) algorithm to find frequent sequences within a given
dataset. This implementation includes parameters for themingap,maxgap, andmaxspantime constraints.The project also features a simple dataset generator.InstallationThe package can be installed via pip:python3 -m pip install gsp_pythonUsageThe GSP algorithm and the dataset generator can be executed either from the command line or by importing the package modules in a script.From the command lineTo run the GSP algorithm:python3 -m gsp_python GSP infile outfile minsup -t maxgap mingap maxspanWhere:infile: specifies the path of the file containing the dataset from which sequences must be mined from. The file must be a text file in which each data-sequence is terminated by ' -2', each element is terminated by ' -1', and each event is separated by a space.outfile: specifies the path of the output file where the result will be printed to. It will contain all frequent sequences found, each paired with their support count.minsup: specifies the minimum support threshold used during execution.-t maxgap mingap maxspan(optional): specifies themaxgap,mingap, andmaxspanvalues used during execution. If not specified, the default values ofinf, 0, andinfwill be used instead.For more information about additional optional arguments, type:python3 -m gsp_python GSP -hTo generate a random dataset:python3 -m gsp_python DatasetGen outfile size nevents maxevents avgelemsWhere:outfile: specifies the path of the output file where the dataset will be printed to. The format used is the same as the one accepted as input for the algorithm above.size: specifies the number of data-sequences.nevents: specifies the number of unique events.maxevents: specifies the maximum number of events per element.avgelems: specifies the average number of elements per data-sequence.For more information about additional optional arguments, type:python3 -m gsp_python DatasetGen -hFrom within a scriptTo run the GSP algorithm, usegsp_python.gsp.GSP()to create and initialize aGSPobject, providing the required arguments; then, call methodrun_gsp()to execute the algorithm (the result is returned as a list of tuples, each pairing a sequence with its support count).An example is given below:fromgsp_python.gspimportload_dsfromgsp_python.gspimportGSPdataset,dict1,dict2=load_ds("path/to/file.txt")algo_gsp=GSP(dataset,minsup=0.3,mingap=1,maxgap=2,maxspan=5)output=algo_gsp.run_gsp()Methodload_ds()loads the dataset contained in the file at the specified path (provided that it follows the format explained above), converting all events to integers. It also returns the dictionary (here assigned todict1) that can be used to convert each integer back to the corresponding event.To generate a random dataset, usegsp_python.dataset_gen.DatasetGenerator()to create and initialize aDatasetGenerator()object, providing the required arguments; then, call methodgenerate_sequence_dataset()to generate a dataset (the dataset is returned as alist[list[list[int]]]).An example is given below:fromgsp_python.dataset_genimportDatasetGeneratoralgo_dsgen=DatasetGenerator(size=100,nevents=8,maxevents=4,avgelems=16)algo_dsgen.generate_sequence_dataset()