SPADE
- class PAMI.sequentialPatternMining.basic.SPADE.SPADE(iFile, minSup, sep='\t')[source]
Bases:
_sequentialPatterns
- Description:
SPADE is one of the fundamental algorithm to discover sequential frequent patterns in a transactional database.
This program employs SPADE property (or downward closure property) to reduce the search space effectively.
This algorithm employs breadth-first search technique when 1-2 length patterns and depth-first serch when above 3 length patterns to find the complete set of frequent patterns in a transactional database.
- Reference:
Mohammed J. Zaki. 2001. SPADE: An Efficient Algorithm for Mining Frequent Sequences. Mach. Learn. 42, 1-2 (January 2001), 31-60. DOI=10.1023/A:1007652502315 http://dx.doi.org/10.1023/A:1007652502315
- Parameters:
iFile – str : Name of the Input file to mine complete set of Sequential frequent patterns
oFile – str : Name of the output file to store complete set of Sequential frequent patterns
minSup – float or int or str : minSup measure constraints the minimum number of transactions in a database where a pattern must appear Example: minSup=10 will be treated as integer, while minSup=10.0 will be treated as float
sep – str : This variable is used to distinguish items from one another in a transaction. The default seperator is tab space. However, the users can override their default separator.
- Attributes:
- iFilestr
Input file name or path of the input file
- oFilestr
Name of the output file or the path of output file
- minSup: float or int or str
The user can specify minSup either in count or proportion of database size. If the program detects the data type of minSup is integer, then it treats minSup is expressed in count. Otherwise, it will be treated as float. Example: minSup=10 will be treated as integer, while minSup=10.0 will be treated as float
- sepstr
This variable is used to distinguish items from one another in a transaction. The default seperator is tab space or . However, the users can override their default separator.
- startTime:float
To record the start time of the mining process
- endTime:float
To record the completion time of the mining process
- finalPatterns: dict
Storing the complete set of patterns in a dictionary variable
- memoryUSSfloat
To store the total amount of USS memory consumed by the program
- memoryRSSfloat
To store the total amount of RSS memory consumed by the program
- Databaselist
To store the transactions of a database in list
- _xLenDatabase: dict
To store the datas in different sequence separated by sequence, rownumber, length.
- _xLenDatabaseSamedict
To store the datas in same sequence separated by sequence, rownumber, length.
- Methods:
- mine()
Mining process will start from here
- getPatterns()
Complete set of patterns will be retrieved with this function
- savePatterns(oFile)
Complete set of frequent patterns will be loaded in to an output file
- getPatternsAsDataFrame()
Complete set of frequent patterns will be loaded in to a dataframe
- getMemoryUSS()
Total amount of USS memory consumed by the mining process will be retrieved from this function
- getMemoryRSS()
Total amount of RSS memory consumed by the mining process will be retrieved from this function
- getRuntime()
Total amount of runtime taken by the mining process will be retrieved from this function
- candidateToFrequent(candidateList)
Generates frequent patterns from the candidate patterns
- frequentToCandidate(frequentList, length)
Generates candidate patterns from the frequent patterns
Methods to execute code on terminal
Format: (.venv) $ python3 SPADE.py <inputFile> <outputFile> <minSup> Example usage: (.venv) $ python3 SPADE.py sampleDB.txt patterns.txt 10.0 .. note:: minSup will be considered in times of minSup and count of database transactions
Importing this algorithm into a python program
import PAMI.sequentialPatternMining.basic.SPADE as alg obj = alg.SPADE(iFile, minSup) obj.startMine() sequentialPatternMining = obj.getPatterns() print("Total number of Frequent Patterns:", len(frequentPatterns)) obj.save(oFile) Df = obj.getPatternInDataFrame() memUSS = obj.getMemoryUSS() print("Total Memory in USS:", memUSS) memRSS = obj.getMemoryRSS() print("Total Memory in RSS", memRSS) run = obj.getRuntime() print("Total ExecutionTime in seconds:", run)
Credits:
The complete program was written by Suzuki Shota under the supervision of Professor Rage Uday Kiran.
- getMemoryRSS()[source]
Total amount of RSS memory consumed by the mining process will be retrieved from this function
- Returns:
returning RSS memory consumed by the mining process
- Return type:
float
- getMemoryUSS()[source]
Total amount of USS memory consumed by the mining process will be retrieved from this function
- Returns:
returning USS memory consumed by the mining process
- Return type:
float
- getPatterns()[source]
Function to send the set of frequent patterns after completion of the mining process
- Returns:
returning frequent patterns
- Return type:
dict
- getPatternsAsDataFrame()[source]
Storing final frequent patterns in a dataframe
- Returns:
returning frequent patterns in a dataframe
- Return type:
pd.DataFrame
- getRuntime()[source]
Calculating the total amount of runtime taken by the mining process
- Returns:
returning total amount of runtime taken by the mining process
- Return type:
float
- make1LenDatabase()[source]
To make 1 length frequent patterns by breadth-first search technique and update Database to sequential database
- make2LenDatabase()[source]
To make 2 length frequent patterns by joining two one length patterns by breadth-first search technique and update xlen Database to sequential database
- make3LenDatabase()[source]
To call each 2 length patterns to make 3 length frequent patterns depth-first search technique
- makeNextRow(bs, latestWord, latestWord2)[source]
To make pattern row when two patterns have the latest word in different sequence
:param bs : previous pattern without the latest one :param latestWord : latest word of one previous pattern :param latestWord2 : latest word of other previous pattern
- makeNextRowSame(bs, latestWord, latestWord2)[source]
To make pattern row when one pattern have the latestWord1 in different sequence and other(latestWord2) in same
:param bs : previous pattern without the latest one :param latestWord : latest word of one previous pattern in same sequence :param latestWord2 : latest word of other previous pattern in different sequence
- makeNextRowSame2(bs, latestWord, latestWord2)[source]
To make pattern row when two patterns have the latest word in same sequence
:param bs : previous pattern without the latest one :param latestWord : latest word of one previous pattern :param latestWord2 : latest word of the other previous pattern
- makeNextRowSame3(bs, latestWord, latestWord2)[source]
To make pattern row when two patterns have the latest word in different sequence and both latest word is in same sequence
:param bs : previous pattern without the latest one :param latestWord : latest word of one previous pattern :param latestWord2 : latest word of other previous pattern
- makexLenDatabase(rowLen, bs, latestWord)[source]
To make “rowLen” length frequent patterns from pattern which the latest word is in same seq by joining “rowLen”-1 length patterns by depth-first search technique and update xlenDatabase to sequential database
- Parameters:
rowLen – row length of patterns.
:param bs : patterns without the latest one :param latestWord : latest word of patterns
- makexLenDatabaseSame(rowLen, bs, latestWord)[source]
To make 3 or more length frequent patterns from pattern which the latest word is in different seq by depth-first search technique and update xlenDatabase to sequential database
- Parameters:
rowLen – row length of previous patterns.
:param bs : previous patterns without the latest one :param latestWord : latest word of previous patterns