SPAM

class PAMI.sequentialPatternMining.basic.SPAM.SPAM(iFile, minSup, sep='\t')[source]

Bases: _sequentialPatterns

Description:

SPAM is one of the fundamental algorithm to discover sequential frequent patterns in a transactional database. This program employs SPAM property (or downward closure property) to reduce the search space effectively. This algorithm employs breadth-first search technique to find the complete set of frequent patterns in a sequential database.

Reference:
  1. Ayres, J. Gehrke, T.Yiu, and J. Flannick. Sequential Pattern Mining Using Bitmaps. In Proceedings of the Eighth ACM SIGKDD International Conference on Knowledge Discovery and Data Mining. Edmonton, Alberta, Canada, July 2002.

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

minSupfloat 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.

startTimefloat

To record the start time of the mining process

endTimefloat

To record the completion time of the mining process

finalPatternsdict

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 sequences of a database in list

_idDatabasedict

To store the sequences of a database by bit map

_maxSeqLen:

the maximum length of subsequence in sequence.

Methods:
_creatingItemSets():

Storing the complete sequences of the database/input file in a database variable

_convert(value):

To convert the user specified minSup value

make2BitDatabase():

To make 1 length frequent patterns by breadth-first search technique and update Database to sequential database

DfsPruning(items,sStep,iStep):

the main algorithm of spam. This can search sstep and istep items and find next patterns, its sstep, and its istep. And call this function again by using them. Recursion until there are no more items available for exploration.

Sstep(s):

To convert bit to ssteo bit.The first time you get 1, you set it to 0 and subsequent ones to 1.(like 010101=>001111, 00001001=>00000111)

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 a 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

Executing the code on terminal:

Format:

(.venv) $ python3 SPAM.py <inputFile> <outputFile> <minSup> (<separator>)

Examples usage:

(.venv) $ python3 SPAM.py sampleDB.txt patterns.txt 10.0


        .. note:: minSup will be considered in times of minSup and count of database transactions

Sample run of the importing code:

import PAMI.sequentialPatternMining.basic.SPAM as alg

obj = alg.SPAM(iFile, minSup)

obj.mine()

sequentialPatternMining = obj.getPatterns()

print(“Total number of Frequent Patterns:”, len(frequentPatterns))

obj.savePatterns(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 Shota Suzuki under the supervision of Professor Rage Uday Kiran.

DfsPruning(items, sStep, iStep)[source]

the main algorithm of spam. This can search sstep and istep items and find next patterns, its sstep, and its istep. And call this function again by using them. Recursion until there are no more items available for exploration.

Attributes:

itemsstr

The pattrens I got before

sSteplist

Items presumed to have “sstep” relationship with “items”.(sstep is What appears later like a-b and a-c)

iSteplist

Items presumed to have “istep” relationship with “items”(istep is What appears in same time like ab and ac)

Sstep(s)[source]

To convert bit to Sstep bit.The first time you get 1, you set it to 0 and subsequent ones to 1.(like 010101=>001111, 00001001=>00000111)

:param s:list

to store each bit sequence

Returns:

nextS:list to store the bit sequence converted by sstep

countSup(n)[source]

count support

:param n:list

to store each bit sequence

Returns:

count: int support of this list

getMemoryRSS()[source]

Total amount of RSS memory consumed by the mining process will be retrieved from this function :return: returning RSS memory consumed by the mining process :rtype: float

getMemoryUSS()[source]

Total amount of USS memory consumed by the mining process will be retrieved from this function :return: returning USS memory consumed by the mining process :rtype: float

getPatterns()[source]

Function to send the set of frequent patterns after completion of the mining process :return: returning frequent patterns :rtype: dict

getPatternsAsDataFrame()[source]

Storing final frequent patterns in a dataframe :return: returning frequent patterns in a dataframe :rtype: pd.DataFrame

getRuntime()[source]

Calculating the total amount of runtime taken by the mining process :return: returning total amount of runtime taken by the mining process :rtype: float

make2BitDatabase()[source]

To make 1 length frequent patterns by breadth-first search technique and update Database to sequential database

printResults()[source]

This function is used to print the results

save(outFile)[source]

Complete set of frequent patterns will be loaded in to an output file :param outFile: name of the output file :type outFile: file

startMine()[source]

Frequent pattern mining process will start from here