Loading...
The University of Aizu, Aizu-Wakamatsu, Japan
+81-8048340999

Mining interesting patterns using an algorithm

In this page, we first describe the basic syntax to implement a mining algorithm. Next, we provide an example to implement a mining algorithm.


Syntax to implement an algorithm

# import the necessary algorithm from the PAMI library
from PAMI.<model>.<basic/closed/maximal/topK> import <algorithmName> as alg

# Call the necessary algorithm by passing necessary input parameters. The input parameters include inputFileName and the user-specified constraints.
obj = alg.<algorithmName>(<input parameters>)

# Start the mining algorithm
obj.startMine()

# Collect the patterns discovered by the algorithm in the database
discoveredPatterns = obj.getDiscoveredPatterns()

# Print the total number of patterns
print("Total number of discovered patterns:", len(discoveredPatterns))

# Store the discovered patterns in a file.
obj.save('<outputFileName>')

# Output the discovered patterns as a data frame
Df = obj.getPatternInDataFrame()

# Calculate the [USS] memory consumed by the algorithm
print("Total Memory in USS:", obj.getMemoryUSS())

# Calculate the RSS memory consumed by the algorithm. We suggest using RSS memory for the memory comparison
print("Total Memory in RSS", obj.getMemoryRSS())

# Calculate the runtime requirements by the algorithm
print("Total ExecutionTime in seconds:", obj.getRuntime())

Example: Mining frequent patterns in a transactional database using FP-growth

Note: Click here to download the transactional database

#import the frequent pattern mining algorithm
from PAMI.frequentPattern.basic import FPGrowth as alg

#inputFile = 'fileName'
inputFile = 'Transactional_T10I4D100K.csv'

#specify the constraints used in the model
minSup=400

#create the object of the mining algorithm
obj = alg.FPGrowth(inputFile, minSup)

#start the mining process
obj.startMine()

#Print the number of interesting patterns generated
print("Total number of Frequent Patterns:", len(obj.getPatterns()))

#Save the generated patterns in a file
obj.save('outputFile.tsv')

# Determine the memory consumed by the mining algorithm
print("Total Memory in RSS", obj.getMemoryRSS())

# Determine the total runtime consumed by the mining algorithm
print("Total ExecutionTime in seconds:", obj.getRuntime())