diff --git a/PAMI/uncertainFrequentPattern/basic/CUFPTree.py b/PAMI/uncertainFrequentPattern/basic/CUFPTree.py index e6fecd1c..dd0f6c5e 100644 --- a/PAMI/uncertainFrequentPattern/basic/CUFPTree.py +++ b/PAMI/uncertainFrequentPattern/basic/CUFPTree.py @@ -1,14 +1,16 @@ # CUFPTree is one of the fundamental algorithm to discover frequent patterns in a uncertain transactional database using CUFP-Tree # # **Importing this algorithm into a python program** -# -------------------------------------------------------- -# # # from PAMI.uncertainFrequentPattern.basic import CUFPTree as alg # # obj = alg.CUFPTree(iFile, minSup,oFile,sep) # -# obj.startMine() +# iFile = 'sampleDB.txt' +# +# minSup = 10 # can also be specified between 0 and 1 +# +# obj.mine() # # frequentPatterns = obj.getPatterns() # @@ -32,7 +34,6 @@ # - __copyright__ = """ Copyright (C) 2021 Rage Uday Kiran @@ -48,8 +49,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . - Copyright (C) 2021 Rage Uday Kiran - """ import pandas as pd @@ -72,6 +71,7 @@ class _Item: item : int or word Represents the name of the item + probability : float Represent the existential probability(likelihood presence) of an item """ @@ -89,10 +89,13 @@ class _Node(object): item : int storing item of a node + probability : int To maintain the expected support of node + parent : node To maintain the parent of every node + children : list To maintain the children of node @@ -109,6 +112,14 @@ def __init__(self, item, children) -> None: self.parent = None def addChild(self, node) -> None: + """ + This method adds a child node to the current node in the frequent pattern tree. It updates the children + dictionary of the current node with the new child node and sets the parent of the child node to the current node. + + :param node: The child node to be added. + :type node: _Node + :return: None + """ self.children[node.item] = node node.parent = self @@ -121,10 +132,13 @@ class _Tree(object): root : Node Represents the root node of the tree + summaries : dictionary storing the nodes with same item name + info : dictionary stores the support of items + :Methods: addTransaction(transaction) @@ -150,6 +164,7 @@ def __init__(self) -> None: def addTransaction(self, transaction) -> None: """ adding transaction into tree + :param transaction : it represents the one self.Database in database :type transaction : list :return: None @@ -189,6 +204,7 @@ def addTransaction(self, transaction) -> None: def addConditionalPattern(self, transaction, sup) -> None: """ constructing conditional tree from prefixPaths + :param transaction : it represents the one self.Database in database :type transaction : list :param sup : support of prefixPath taken at last child of the path @@ -215,6 +231,7 @@ def addConditionalPattern(self, transaction, sup) -> None: def conditionalPatterns(self, alpha) -> Tuple[List, List, dict]: """ generates all the conditional patterns of respective node + :param alpha : it represents the Node in tree :type alpha : _Node :return: Tuple @@ -312,11 +329,13 @@ def generatePatterns(self, prefix) -> None: class CUFPTree(_ab._frequentPatterns): """ + About this algorithm + ==================== + :Description: It is one of the fundamental algorithm to discover frequent patterns in a uncertain transactional database using CUFP-Tree. - :Reference: - Chun-Wei Lin Tzung-PeiHong, 'new mining approach for uncertain databases using CUFP trees', - Expert Systems with Applications, Volume 39, Issue 4, March 2012, Pages 4084-4093, https://doi.org/10.1016/j.eswa.2011.09.087 + :Reference: Chun-Wei Lin Tzung-PeiHong, 'new mining approach for uncertain databases using CUFP trees', + Expert Systems with Applications, Volume 39, Issue 4, March 2012, Pages 4084-4093, https://doi.org/10.1016/j.eswa.2011.09.087 :param iFile: str : Name of the Input file to mine complete set of Uncertain Frequent Patterns @@ -332,40 +351,53 @@ class CUFPTree(_ab._frequentPatterns): iFile : file Name of the Input file or path of the input file + oFile : file Name of the output file or path of the 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 + sep : str This variable is used to distinguish items from one another in a transaction. The default seperator is tab space or \t. However, the users can override their default separator. + memoryUSS : float To store the total amount of USS memory consumed by the program + memoryRSS : float To store the total amount of RSS memory consumed by the program + startTime:float To record the start time of the mining process + endTime:float To record the completion time of the mining process + Database : list To store the transactions of a database in list + mapSupport : Dictionary To maintain the information of item and their frequency + lno : int To represent the total no of transaction + tree : class To represents the Tree class + itemSetCount : int To represents the total no of patterns + finalPatterns : dict To store the complete patterns :Methods: - startMine() + mine() Mining process will start from here getPatterns() Complete set of patterns will be retrieved with this function @@ -392,11 +424,14 @@ class CUFPTree(_ab._frequentPatterns): startMine() Mining process will start from this function - **Methods to execute code on terminal** - -------------------------------------------- + Execution methods + ================= - .. code-block:: console + **Terminal command** + + + .. code-block:: console Format: @@ -406,19 +441,21 @@ class CUFPTree(_ab._frequentPatterns): (.venv) $ python3 CUFPTree.py sampleTDB.txt patterns.txt 3 + .. note:: minSup will be considered in support count or frequency + **Calling from a python program** - .. note:: minSup will be considered in support count or frequency - - **Importing this algorithm into a python program** - ---------------------------------------------------- .. code-block:: python from PAMI.uncertainFrequentPattern.basic import CUFPTree as alg - obj = alg.CUFPTree(iFile, minSup)v + iFile = 'sampleDB.txt' - obj.startMine() + minSup = 10 # can also be specified between 0 and 1 + + obj = alg.CUFPTree(iFile, minSup) + + obj.mine() frequentPatterns = obj.getPatterns() @@ -440,11 +477,13 @@ class CUFPTree(_ab._frequentPatterns): print("Total ExecutionTime in seconds:", run) - **Credits:** - -------------- + Credits + ======= + + + The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran. + """ - The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran. -""" _startTime = float() _endTime = float() _minSup = str() @@ -463,6 +502,7 @@ def __init__(self, iFile, minSup, sep='\t') -> None: def _creatingItemSets(self) -> None: """ Scans the uncertain transactional dataset + :return: None """ self._Database = [] @@ -547,7 +587,7 @@ def _buildTree(data, info) -> '_Tree': :param data : it represents the one self.Database in database :type data : list :param info : it represents the support of each item - :type info : dictionary + :type info : dict :return: Dictionary """ @@ -621,7 +661,6 @@ def _convert(self, value) -> float: def _removeFalsePositives(self) -> None: """ - To remove the false positive patterns generated in frequent patterns. :return: patterns with accurate probability @@ -650,10 +689,12 @@ def _removeFalsePositives(self) -> None: sample = sample + i + "\t" self._finalPatterns[sample] = y - @deprecated("It is recommended to use mine() instead of startMine() for mining process") + @deprecated( + "It is recommended to use 'mine()' instead of 'startMine()' for mining process. Starting from January 2025, 'startMine()' will be completely terminated.") def startMine(self) -> None: """ Main method where the patterns are mined by constructing tree and remove the false patterns by counting the original support of a patterns. + :return: None """ self.mine() @@ -661,6 +702,7 @@ def startMine(self) -> None: def mine(self) -> None: """ Main method where the patterns are mined by constructing tree and remove the false patterns by counting the original support of a patterns. + :return: None """ global minSup @@ -686,6 +728,7 @@ def mine(self) -> None: def getMemoryUSS(self) -> float: """ + 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 @@ -696,6 +739,7 @@ def getMemoryUSS(self) -> float: def getMemoryRSS(self) -> float: """ + 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 @@ -706,6 +750,7 @@ def getMemoryRSS(self) -> float: def getRuntime(self) -> float: """ + Calculating the total amount of runtime taken by the mining process :return: returning total amount of runtime taken by the mining process @@ -716,6 +761,7 @@ def getRuntime(self) -> float: def getPatternsAsDataFrame(self) -> _ab._pd.DataFrame: """ + Storing final frequent patterns in a dataframe :return: returning frequent patterns in a dataframe @@ -731,6 +777,7 @@ def getPatternsAsDataFrame(self) -> _ab._pd.DataFrame: def save(self, outFile: str) -> None: """ + Complete set of frequent patterns will be loaded in to an output file :param outFile: name of the output file @@ -745,6 +792,7 @@ def save(self, outFile: str) -> None: def getPatterns(self) -> dict: """ + Function to send the set of frequent patterns after completion of the mining process :return: returning frequent patterns @@ -755,7 +803,6 @@ def getPatterns(self) -> dict: def printResults(self) -> None: """ This function is used to print the results - :return: None """ print("Total number of Uncertain Frequent Patterns:", len(self.getPatterns())) print("Total Memory in USS:", self.getMemoryUSS()) diff --git a/PAMI/uncertainFrequentPattern/basic/PUFGrowth.py b/PAMI/uncertainFrequentPattern/basic/PUFGrowth.py index 30eb745e..e2b33316 100644 --- a/PAMI/uncertainFrequentPattern/basic/PUFGrowth.py +++ b/PAMI/uncertainFrequentPattern/basic/PUFGrowth.py @@ -1,34 +1,38 @@ # PUFGrowth is one of the fundamental algorithm to discover frequent patterns in a uncertain transactional database using PUF-Tree. # # **Importing this algorithm into a python program** -# -------------------------------------------------------- # -# from PAMI.uncertainFrequentPattern.basic import puf as alg +# from PAMI.uncertainFrequentPattern.basic import puf as alg # -# obj = alg.PUFGrowth(iFile, minSup) +# iFile = 'sampleDB.txt' # -# obj.startMine() +# minSup = 10 # can also be specified between 0 and 1 # -# frequentPatterns = obj.getPatterns() +# obj = alg.PUFGrowth(iFile, minSup) # -# print("Total number of Frequent Patterns:", len(frequentPatterns)) +# obj.mine() # -# obj.save(oFile) +# frequentPatterns = obj.getPatterns() # -# Df = obj.getPatternsAsDataFrame() +# print("Total number of Frequent Patterns:", len(frequentPatterns)) # -# memUSS = obj.getMemoryUSS() +# obj.save(oFile) # -# print("Total Memory in USS:", memUSS) +# Df = obj.getPatternsAsDataFrame() # -# memRSS = obj.getMemoryRSS() +# memUSS = obj.getMemoryUSS() # -# print("Total Memory in RSS", memRSS) +# print("Total Memory in USS:", memUSS) # -# run = obj.getRuntime() +# memRSS = obj.getMemoryRSS() # -# print("Total ExecutionTime in seconds:", run) +# print("Total Memory in RSS", memRSS) # +# run = obj.getRuntime() +# +# print("Total ExecutionTime in seconds:", run) +# + __copyright__ = """ Copyright (C) 2021 Rage Uday Kiran @@ -36,16 +40,16 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . - Copyright (C) 2021 Rage Uday Kiran """ - from PAMI.uncertainFrequentPattern.basic import abstract as _ab from typing import List, Tuple import deprecated @@ -58,11 +62,14 @@ class _Item: """ A class used to represent the item with probability in transaction of dataset + :Attributes: - item : int or word - Represents the name of the item - probability : float - Represent the existential probability(likelihood presence) of an item + + item : int or word + Represents the name of the item + + probability : float + Represent the existential probability(likelihood presence) of an item """ def __init__(self, item, probability) -> None: @@ -73,15 +80,21 @@ def __init__(self, item, probability) -> None: class _Node(object): """ A class used to represent the node of frequentPatternTree + :Attributes: - item : int - storing item of a node - probability : int - To maintain the expected support of node - parent : node - To maintain the parent of every node - children : list - To maintain the children of node + + item : int + storing item of a node + + probability : int + To maintain the expected support of node + + parent : node + To maintain the parent of every node + + children : list + To maintain the children of node + :Methods: addChild(itemName) storing the children to their respective parent nodes @@ -95,7 +108,12 @@ def __init__(self, item, children) -> None: def addChild(self, node) -> None: """ - This function is used to add a child + This method adds a child node to the current node in the frequent pattern tree. It updates the children + dictionary of the current node with the new child node and sets the parent of the child node to the current node. + + :param node: The child node to be added. + :type node: _Node + :return: None """ self.children[node.item] = node node.parent = self @@ -104,13 +122,18 @@ def addChild(self, node) -> None: class _Tree(object): """ A class used to represent the frequentPatternGrowth tree structure + Attributes: - root : Node - Represents the root node of the tree - summaries : dictionary - storing the nodes with same item name - info : dictionary - stores the support of items + + root : Node + Represents the root node of the tree + + summaries : dictionary + storing the nodes with same item name + + info : dictionary + stores the support of items + :Methods: addTransaction(transaction) creating transaction as a branch in frequentPatternTree @@ -135,6 +158,7 @@ def __init__(self) -> None: def addTransaction(self, transaction) -> None: """ Adding transaction into tree + :param transaction : it represents the one self.Database in database :type transaction : list """ @@ -173,6 +197,7 @@ def addTransaction(self, transaction) -> None: def addConditionalPattern(self, transaction, sup) -> None: """ Constructing conditional tree from prefixPaths + :param transaction : it represents the one self.Database in database :type transaction : list :param sup : support of prefixPath taken at last child of the path @@ -198,6 +223,7 @@ def addConditionalPattern(self, transaction, sup) -> None: def conditionalPatterns(self, alpha) -> Tuple[List, List, dict]: """ Generates all the conditional patterns of respective node + :param alpha : it represents the Node in tree :type alpha : _Node """ @@ -220,6 +246,7 @@ def conditionalPatterns(self, alpha) -> Tuple[List, List, dict]: def removeNode(self, nodeValue) -> None: """ Removing the node from tree + :param nodeValue : it represents the node in tree :type nodeValue : node """ @@ -230,6 +257,7 @@ def removeNode(self, nodeValue) -> None: def conditionalTransactions(self, condPatterns, support) -> Tuple[List, List, dict]: """ It generates the conditional patterns with frequent items + :param condPatterns : conditionalPatterns generated from conditionalPattern method for respective node :type condPatterns : list :support : the support of conditional pattern in tree @@ -260,6 +288,7 @@ def conditionalTransactions(self, condPatterns, support) -> Tuple[List, List, di def generatePatterns(self, prefix) -> None: """ Generates the patterns + :param prefix : forms the combination of items :type prefix : list """ @@ -285,48 +314,64 @@ def generatePatterns(self, prefix) -> None: class PUFGrowth(_ab._frequentPatterns): """ + About this algorithm + ==================== + :Description: It is one of the fundamental algorithm to discover frequent patterns in a uncertain transactional database using PUF-Tree. - :Reference: - Carson Kai-Sang Leung, Syed Khairuzzaman Tanbeer, "PUF-Tree: A Compact Tree Structure for Frequent Pattern Mining of Uncertain Data", - Pacific-Asia Conference on Knowledge Discovery and Data Mining(PAKDD 2013), https://link.springer.com/chapter/10.1007/978-3-642-37453-1_2 + :Reference: Carson Kai-Sang Leung, Syed Khairuzzaman Tanbeer, "PUF-Tree: A Compact Tree Structure for Frequent Pattern Mining of Uncertain Data", + Pacific-Asia Conference on Knowledge Discovery and Data Mining(PAKDD 2013), https://link.springer.com/chapter/10.1007/978-3-642-37453-1_2 :Attributes: + iFile : file Name of the Input file or path of the input file + oFile : file Name of the output file or path of the 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 + sep : str This variable is used to distinguish items from one another in a transaction. The default seperator is tab space or \t. However, the users can override their default separator. + memoryUSS : float To store the total amount of USS memory consumed by the program + memoryRSS : float To store the total amount of RSS memory consumed by the program + startTime : float To record the start time of the mining process + endTime : float To record the completion time of the mining process + Database : list To store the transactions of a database in list + mapSupport : Dictionary To maintain the information of item and their frequency + lno : int To represent the total no of transaction + tree : class To represents the Tree class + itemSetCount : int To represents the total no of patterns + finalPatterns : dict To store the complete patterns :Methods: - startMine() + mine() Mining process will start from here getPatterns() Complete set of patterns will be retrieved with this function @@ -353,23 +398,38 @@ class PUFGrowth(_ab._frequentPatterns): startMine() Mining process will start from this function - **Methods to execute code on terminal** - ----------------------------------------- - Format: - >>> python3 PUFGrowth.py - Example: - >>> python3 PUFGrowth.py sampleTDB.txt patterns.txt 3 + Execution methods + ================= + + + **Terminal command** + + .. code-block:: console + + Format: + + (.venv) $ python3 PUFGrowth.py + + Example Usage: + + (.venv) $ python3 PUFGrowth.py sampleDB.txt patterns.txt 10.0 - .. note:: minSup will be considered in support count or frequency + .. note:: minSup can be specified in support count or a value between 0 and 1. + + + **Calling from a python program** - **Importing this algorithm into a python program** - ----------------------------------------------------- .. code-block:: python + from PAMI.uncertainFrequentPattern.basic import puf as alg + iFile = 'sampleDB.txt' + + minSup = 10 # can also be specified between 0 and 1 + obj = alg.PUFGrowth(iFile, minSup) - obj.startMine() + obj.startmine() frequentPatterns = obj.getPatterns() @@ -391,10 +451,13 @@ class PUFGrowth(_ab._frequentPatterns): print("Total ExecutionTime in seconds:", run) - **Credits:** - -------------------- + Credits + ======= + + The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran. -""" + """ + _startTime = float() _endTime = float() _minSup = str() @@ -471,6 +534,7 @@ def _creatingItemSets(self) -> None: def _frequentOneItem(self) -> Tuple[dict, List]: """ Takes the self.Database and calculates the support of each item in the dataset and assign the ranks to the items by decreasing support and returns the frequent items list + :param self.Database : it represents the one self.Database in database :type self.Database : list """ @@ -490,7 +554,8 @@ def _frequentOneItem(self) -> Tuple[dict, List]: @staticmethod def _buildTree(data, info) -> '_Tree': """ - it takes the self.Database and support of each item and construct the main tree with setting root node as null + It takes the self.Database and support of each item and construct the main tree with setting root node as null + :param data : it represents the one self.Database in database :type data : list :param info : it represents the support of each item @@ -505,7 +570,8 @@ def _buildTree(data, info) -> '_Tree': def _updateTransactions(self, dict1) -> List: """ - remove the items which are not frequent from self.Database and updates the self.Database with rank of items + Remove the items which are not frequent from self.Database and updates the self.Database with rank of items + :param dict1 : frequent items with support :type dict1 : dictionary """ @@ -527,6 +593,7 @@ def _updateTransactions(self, dict1) -> List: def _check(i, x) -> int: """ To check the presence of item or pattern in transaction + :param x: it represents the pattern :type x : list :param i : represents the uncertain self.Database @@ -546,6 +613,7 @@ def _check(i, x) -> int: def _convert(self, value) -> float: """ To convert the type of user specified minSup value + :param value: user specified minSup value :return: converted type minSup value """ @@ -563,6 +631,7 @@ def _convert(self, value) -> float: def _removeFalsePositives(self) -> None: """ To remove the false positive patterns generated in frequent patterns + :return: patterns with accurate probability """ global _finalPatterns @@ -589,7 +658,8 @@ def _removeFalsePositives(self) -> None: sample = sample + i + "\t" self._finalPatterns[sample] = y - @deprecated("It is recommended to use mine() instead of startMine() for mining process") + @deprecated( + "It is recommended to use 'mine()' instead of 'startMine()' for mining process. Starting from January 2025, 'startMine()' will be completely terminated.") def startMine(self) -> None: """ Main method where the patterns are mined by constructing tree and remove the false patterns by counting the original support of a patterns @@ -622,7 +692,9 @@ def mine(self) -> None: def getMemoryUSS(self) -> float: """ + 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 """ @@ -631,7 +703,9 @@ def getMemoryUSS(self) -> float: def getMemoryRSS(self) -> float: """ + 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 """ @@ -640,7 +714,9 @@ def getMemoryRSS(self) -> float: def getRuntime(self) -> float: """ + Calculating the total amount of runtime taken by the mining process + :return: returning total amount of runtime taken by the mining process :rtype: float """ @@ -649,7 +725,9 @@ def getRuntime(self) -> float: def getPatternsAsDataFrame(self) -> _ab._pd.DataFrame: """ + Storing final frequent patterns in a dataframe + :return: returning frequent patterns in a dataframe :rtype: pd.DataFrame """ @@ -663,7 +741,9 @@ def getPatternsAsDataFrame(self) -> _ab._pd.DataFrame: def save(self, outFile: str) -> None: """ + Complete set of frequent patterns will be loaded in to an output file + :param outFile: name of the output file :type outFile: csv file """ @@ -675,7 +755,9 @@ def save(self, outFile: str) -> None: def getPatterns(self) -> dict: """ + Function to send the set of frequent patterns after completion of the mining process + :return: returning frequent patterns :rtype: dict """ diff --git a/PAMI/uncertainFrequentPattern/basic/TUFP.py b/PAMI/uncertainFrequentPattern/basic/TUFP.py index 3a392bfc..7f29d27a 100644 --- a/PAMI/uncertainFrequentPattern/basic/TUFP.py +++ b/PAMI/uncertainFrequentPattern/basic/TUFP.py @@ -3,31 +3,37 @@ # **Importing this algorithm into a python program** # -------------------------------------------------------- # -# from PAMI.uncertainFrequentPattern.basic import TUFP as alg +# from PAMI.uncertainFrequentPattern.basic import TUFP as alg # -# obj = alg.TUFP(iFile, minSup) +# iFile = 'sampleDB.txt' # -# obj.startMine() +# minSup = 10 # can also be specified between 0 and 1 # -# frequentPatterns = obj.getPatterns() +# obj = alg.TUFP(iFile, minSup) # -# print("Total number of Frequent Patterns:", len(frequentPatterns)) +# obj.startMine() # -# obj.save(oFile) +# frequentPatterns = obj.getPatterns() # -# Df = obj.getPatternsAsDataFrame() +# print("Total number of Frequent Patterns:", len(frequentPatterns)) # -# memUSS = obj.getMemoryUSS() +# obj.save(oFile) # -# print("Total Memory in USS:", memUSS) +# Df = obj.getPatternsAsDataFrame() # -# memRSS = obj.getMemoryRSS() +# memUSS = obj.getMemoryUSS() # -# print("Total Memory in RSS", memRSS) +# print("Total Memory in USS:", memUSS) # -# run = obj.getRuntime() +# memRSS = obj.getMemoryRSS() # -# print("Total ExecutionTime in seconds:", run) +# print("Total Memory in RSS", memRSS) +# +# run = obj.getRuntime() +# +# print("Total ExecutionTime in seconds:", run) +# + __copyright__ = """ Copyright (C) 2021 Rage Uday Kiran @@ -35,16 +41,16 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . - Copyright (C) 2021 Rage Uday Kiran """ - from PAMI.uncertainFrequentPattern.basic import abstract as _ab from typing import List, Dict, Union import pandas as pd @@ -57,11 +63,14 @@ class _Item: """ A class used to represent the item with probability in transaction of dataset + :Attributes: + item : int or word - Represents the name of the item + Represents the name of the item + probability : float - Represent the existential probability(likelihood presence) of an item + Represent the existential probability(likelihood presence) of an item """ def __init__(self, item, probability) -> None: @@ -71,48 +80,64 @@ def __init__(self, item, probability) -> None: class TUFP(_ab._frequentPatterns): """ + About this algorithm + ==================== + :Description: It is one of the fundamental algorithm to discover top-k frequent patterns in a uncertain transactional database using CUP-Lists. - :Reference: - Tuong Le, Bay Vo, Van-Nam Huynh, Ngoc Thanh Nguyen, Sung Wook Baik 5, "Mining top-k frequent patterns from uncertain databases", - Springer Science+Business Media, LLC, part of Springer Nature 2020, https://doi.org/10.1007/s10489-019-01622-1 + :Reference: Tuong Le, Bay Vo, Van-Nam Huynh, Ngoc Thanh Nguyen, Sung Wook Baik 5, "Mining top-k frequent patterns from uncertain databases", + Springer Science+Business Media, LLC, part of Springer Nature 2020, https://doi.org/10.1007/s10489-019-01622-1 :Attributes: + iFile : file Name of the Input file or path of the input file + oFile : file Name of the output file or path of the 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 + sep : str This variable is used to distinguish items from one another in a transaction. The default seperator is tab space or \t. However, the users can override their default separator. + memoryUSS : float To store the total amount of USS memory consumed by the program + memoryRSS : float To store the total amount of RSS memory consumed by the program + startTime : float To record the start time of the mining process + endTime : float To record the completion time of the mining process + Database : list To store the transactions of a database in list + mapSupport : Dictionary To maintain the information of item and their frequency + lno : int To represent the total no of transaction + tree : class To represents the Tree class + itemSetCount : int To represents the total no of patterns + finalPatterns : dict To store the complete patterns :Methods: - startMine() + mine() Mining process will start from here getPatterns() Complete set of patterns will be retrieved with this function @@ -139,20 +164,36 @@ class TUFP(_ab._frequentPatterns): startMine() Mining process will start from this function - **Methods to execute code on terminal** - ----------------------------------------- - Format: - >>> python3 TUFP.py - Example: - >>> python3 TUFP.py sampleTDB.txt patterns.txt 0.6 - .. note:: minSup will be considered in support count or frequency + Execution methods + ================= + + + **Terminal command** + + + .. code-block:: console + + Format: + + (.venv) $ python3 TUFP.py + + Example Usage: + + (.venv) $ python3 TUFP.py sampleDB.txt patterns.txt 0.6 + + .. note:: minSup can be specified in support count or a value between 0 and 1. + + + **Calling from a python program** - **Importing this algorithm into a python program** - ------------------------------------------------------ .. code-block:: python from PAMI.uncertainFrequentPattern.basic import TUFP as alg + iFile = 'sampleDB.txt' + + minSup = 10 # can also be specified between 0 and 1 + obj = alg.TUFP(iFile, minSup) obj.startMine() @@ -165,7 +206,7 @@ class TUFP(_ab._frequentPatterns): Df = obj.getPatternsAsDataFrame() - memUSS = obj.getmemoryUSS() + memUSS = obj.getMemoryUSS() print("Total Memory in USS:", memUSS) @@ -177,9 +218,11 @@ class TUFP(_ab._frequentPatterns): print("Total ExecutionTime in seconds:", run) - **Credits:** - --------------- - The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran. + Credits + ======= + + + The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran. """ _startTime = float() @@ -257,7 +300,8 @@ def _creatingItemSets(self) -> None: def _frequentOneItem(self) -> List[str]: """ - takes the self.Database and calculates the support of each item in the dataset and assign the ranks to the items by decreasing support and returns the frequent items list + Takes the self.Database and calculates the support of each item in the dataset and assign the ranks to the items by decreasing support and returns the frequent items list + :param self.Database : it represents the one self.Database in database :type self.Database : list """ @@ -287,6 +331,7 @@ def _frequentOneItem(self) -> List[str]: def _convert(value: Union[int, float, str]) -> Union[int, float]: """ To convert the type of user specified minSup value + :param value: user specified minSup value :return: converted type minSup value """ @@ -304,6 +349,7 @@ def _convert(value: Union[int, float, str]) -> Union[int, float]: def _save(self, prefix: List[str], suffix: List[str], tidSetI: Dict[int, float]) -> None: """ Saves the patterns that satisfy the periodic frequent property. + :param prefix: the prefix of a pattern :type prefix: list :param suffix: the suffix of a patterns @@ -337,6 +383,7 @@ def _save(self, prefix: List[str], suffix: List[str], tidSetI: Dict[int, float]) def _Generation(self, prefix: List[str], itemSets: List[str], tidSets: List[Dict[int, float]]) -> None: """ Equivalence class is followed and checks for the patterns generated for periodic-frequent patterns. + :param prefix: main equivalence prefix :type prefix: periodic-frequent item or pattern :param itemSets: patterns which are items combined with prefix and satisfying the periodicity and frequent with their timestamps @@ -372,7 +419,8 @@ def _Generation(self, prefix: List[str], itemSets: List[str], tidSets: List[Dict self._Generation(newPrefix, classItemSets, classTidSets) # self.save(prefix, list(set(itemSetX)), tidSetI) - @deprecated("It is recommended to use mine() instead of startMine() for mining process") + @deprecated( + "It is recommended to use 'mine()' instead of 'startMine()' for mining process. Starting from January 2025, 'startMine()' will be completely terminated.") def startMine(self) -> None: """ Main method where the patterns are mined by constructing tree and remove the false patterns by counting the original support of a patterns @@ -413,7 +461,9 @@ def mine(self) -> None: def getMemoryUSS(self) -> float: """ + 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 """ @@ -422,7 +472,9 @@ def getMemoryUSS(self) -> float: def getMemoryRSS(self) -> float: """ + 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 """ @@ -431,7 +483,9 @@ def getMemoryRSS(self) -> float: def getRuntime(self) -> float: """ + Calculating the total amount of runtime taken by the mining process + :return: returning total amount of runtime taken by the mining process :rtype: float """ @@ -440,7 +494,9 @@ def getRuntime(self) -> float: def getPatternsAsDataFrame(self) -> pd.DataFrame: """ + Storing final frequent patterns in a dataframe + :return: returning frequent patterns in a dataframe :rtype: pd.DataFrame """ @@ -454,7 +510,9 @@ def getPatternsAsDataFrame(self) -> pd.DataFrame: def save(self, outFile: str) -> None: """ + Complete set of frequent patterns will be loaded in to an output file + :param outFile: name of the output file :type outFile: file """ @@ -466,7 +524,9 @@ def save(self, outFile: str) -> None: def getPatterns(self) -> Dict[str, float]: """ + Function to send the set of frequent patterns after completion of the mining process + :return: returning frequent patterns :rtype: dict """ diff --git a/PAMI/uncertainFrequentPattern/basic/TubeP.py b/PAMI/uncertainFrequentPattern/basic/TubeP.py index b379a2f6..9e60897e 100644 --- a/PAMI/uncertainFrequentPattern/basic/TubeP.py +++ b/PAMI/uncertainFrequentPattern/basic/TubeP.py @@ -1,33 +1,38 @@ # TUFP is one of the fundamental algorithm to discover top-k frequent patterns in a uncertain transactional database using CUP-Lists. # # **Importing this algorithm into a python program** -# -------------------------------------------------------- # -# from PAMI.uncertainFrequentPattern.basic import TUFP as alg +# from PAMI.uncertainFrequentPattern.basic import TUFP as alg # -# obj = alg.TUFP(iFile, minSup) +# iFile = 'sampleDB.txt' # -# obj.startMine() +# minSup = 10 # can also be specified between 0 and 1 # -# frequentPatterns = obj.getPatterns() +# obj = alg.TUFP(iFile, minSup) # -# print("Total number of Frequent Patterns:", len(frequentPatterns)) +# obj.mine() # -# obj.save(oFile) +# frequentPatterns = obj.getPatterns() # -# Df = obj.getPatternsAsDataFrame() +# print("Total number of Frequent Patterns:", len(frequentPatterns)) # -# memUSS = obj.getMemoryUSS() +# obj.save(oFile) # -# print("Total Memory in USS:", memUSS) +# Df = obj.getPatternsAsDataFrame() # -# memRSS = obj.getMemoryRSS() +# memUSS = obj.getMemoryUSS() # -# print("Total Memory in RSS", memRSS) +# print("Total Memory in USS:", memUSS) # -# run = obj.getRuntime() +# memRSS = obj.getMemoryRSS() # -# print("Total ExecutionTime in seconds:", run) +# print("Total Memory in RSS", memRSS) +# +# run = obj.getRuntime() +# +# print("Total ExecutionTime in seconds:", run) +# + __copyright__ = """ Copyright (C) 2021 Rage Uday Kiran @@ -35,13 +40,14 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . - Copyright (C) 2021 Rage Uday Kiran """ @@ -56,11 +62,14 @@ class _Item: """ A class used to represent the item with probability in transaction of dataset + :Attributes: + item : int or word - Represents the name of the item + Represents the name of the item + probability : float - Represent the existential probability(likelihood presence) of an item + Represent the existential probability(likelihood presence) of an item """ def __init__(self, item, probability) -> None: @@ -70,48 +79,64 @@ def __init__(self, item, probability) -> None: class TUFP(_ab._frequentPatterns): """ + About this algorithm + ==================== + :Description: It is one of the fundamental algorithm to discover top-k frequent patterns in a uncertain transactional database using CUP-Lists. - :Reference: - Tuong Le, Bay Vo, Van-Nam Huynh, Ngoc Thanh Nguyen, Sung Wook Baik 5, "Mining top-k frequent patterns from uncertain databases", - Springer Science+Business Media, LLC, part of Springer Nature 2020, https://doi.org/10.1007/s10489-019-01622-1 + :Reference: Tuong Le, Bay Vo, Van-Nam Huynh, Ngoc Thanh Nguyen, Sung Wook Baik 5, "Mining top-k frequent patterns from uncertain databases", + Springer Science+Business Media, LLC, part of Springer Nature 2020, https://doi.org/10.1007/s10489-019-01622-1 :Attributes: + iFile : file Name of the Input file or path of the input file + oFile : file Name of the output file or path of the 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 + sep : str This variable is used to distinguish items from one another in a transaction. The default seperator is tab space or \t. However, the users can override their default separator. + memoryUSS : float To store the total amount of USS memory consumed by the program + memoryRSS : float To store the total amount of RSS memory consumed by the program + startTime : float To record the start time of the mining process + endTime : float To record the completion time of the mining process + Database : list To store the transactions of a database in list + mapSupport : Dictionary To maintain the information of item and their frequency + lno : int To represent the total no of transaction + tree : class To represents the Tree class + itemSetCount : int To represents the total no of patterns + finalPatterns : dict To store the complete patterns :Methods: - startMine() + mine() Mining process will start from here getPatterns() Complete set of patterns will be retrieved with this function @@ -138,23 +163,40 @@ class TUFP(_ab._frequentPatterns): startMine() Mining process will start from this function - **Methods to execute code on terminal** - ----------------------------------------- - Format: - >>> python3 TUFP.py - Example: - >>> python3 TUFP.py sampleTDB.txt patterns.txt 0.6 + Execution methods + ================= + + + **Terminal command** + + + .. code-block:: console - .. note:: minSup will be considered in support count or frequency + Format: + + (.venv) $ python3 TUFP.py + + Example Usage: + + (.venv) $ python3 TUFP.py sampleDB.txt patterns.txt 10.0 + + .. note:: minSup can be specified in support count or a value between 0 and 1. + + + **Calling from a python program** - **Importing this algorithm into a python program** - ------------------------------------------------------ .. code-block:: python + from PAMI.uncertainFrequentPattern.basic import TUFP as alg + + iFile = 'sampleDB.txt' + + minSup = 10 # can also be specified between 0 and 1 + obj = alg.TUFP(iFile, minSup) - obj.startMine() + obj.mine() frequentPatterns = obj.getPatterns() @@ -176,9 +218,10 @@ class TUFP(_ab._frequentPatterns): print("Total ExecutionTime in seconds:", run) - **Credits:** - --------------- - The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran. + Credits + ======= + + The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran. """ _startTime = float() @@ -254,7 +297,8 @@ def _creatingItemSets(self) -> None: def _frequentOneItem(self) -> List[str]: """ - takes the self.Database and calculates the support of each item in the dataset and assign the ranks to the items by decreasing support and returns the frequent items list + Takes the self.Database and calculates the support of each item in the dataset and assign the ranks to the items by decreasing support and returns the frequent items list + :param self.Database : it represents the one self.Database in database :type self.Database : list """ @@ -284,6 +328,7 @@ def _frequentOneItem(self) -> List[str]: def _convert(value: Union[int, float, str]) -> Union[int, float]: """ To convert the type of user specified minSup value + :param value: user specified minSup value :return: converted type minSup value """ @@ -301,6 +346,7 @@ def _convert(value: Union[int, float, str]) -> Union[int, float]: def _save(self, prefix: List[str], suffix: List[str], tidSetI: Dict[int, float]) -> None: """ Saves the patterns that satisfy the periodic frequent property. + :param prefix: the prefix of a pattern :type prefix: list :param suffix: the suffix of a patterns @@ -335,6 +381,7 @@ def _save(self, prefix: List[str], suffix: List[str], tidSetI: Dict[int, float]) def _Generation(self, prefix: List[str], itemSets: List[str], tidSets: List[Dict[int, float]]) -> None: """ Equivalence class is followed and checks for the patterns generated for periodic-frequent patterns. + :param prefix: main equivalence prefix :type prefix: periodic-frequent item or pattern :param itemSets: patterns which are items combined with prefix and satisfying the periodicity and frequent with their timestamps @@ -370,7 +417,8 @@ def _Generation(self, prefix: List[str], itemSets: List[str], tidSets: List[Dict self._Generation(newPrefix, classItemSets, classTidSets) #self.save(prefix, list(set(itemSetX)), tidSetI) - @deprecated("It is recommended to use mine() instead of startMine() for mining process") + @deprecated( + "It is recommended to use 'mine()' instead of 'startMine()' for mining process. Starting from January 2025, 'startMine()' will be completely terminated.") def startMine(self) -> None: """ Main method where the patterns are mined by constructing tree and remove the false patterns by counting the original support of a patterns @@ -412,7 +460,9 @@ def mine(self) -> None: def getMemoryUSS(self) -> float: """ + 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 """ @@ -421,7 +471,9 @@ def getMemoryUSS(self) -> float: def getMemoryRSS(self) -> float: """ + 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 """ @@ -430,7 +482,9 @@ def getMemoryRSS(self) -> float: def getRuntime(self) -> float: """ + Calculating the total amount of runtime taken by the mining process + :return: returning total amount of runtime taken by the mining process :rtype: float """ @@ -439,7 +493,9 @@ def getRuntime(self) -> float: def getPatternsAsDataFrame(self) -> pd.DataFrame: """ + Storing final frequent patterns in a dataframe + :return: returning frequent patterns in a dataframe :rtype: pd.DataFrame """ @@ -453,7 +509,9 @@ def getPatternsAsDataFrame(self) -> pd.DataFrame: def save(self, outFile: str) -> None: """ + Complete set of frequent patterns will be loaded in to an output file + :param outFile: name of the output file :type outFile: file """ @@ -465,7 +523,9 @@ def save(self, outFile: str) -> None: def getPatterns(self) -> Dict[str, float]: """ + Function to send the set of frequent patterns after completion of the mining process + :return: returning frequent patterns :rtype: dict """ diff --git a/PAMI/uncertainFrequentPattern/basic/TubeS.py b/PAMI/uncertainFrequentPattern/basic/TubeS.py index dc95d89e..51bce8ec 100644 --- a/PAMI/uncertainFrequentPattern/basic/TubeS.py +++ b/PAMI/uncertainFrequentPattern/basic/TubeS.py @@ -1,33 +1,36 @@ # TubeS is one of the fastest algorithm to discover frequent patterns in a uncertain transactional database. # # **Importing this algorithm into a python program** -# -------------------------------------------------------- # -# from PAMI.uncertainFrequentPattern.basic import TubeS as alg +# from PAMI.uncertainFrequentPattern.basic import TubeS as alg # -# obj = alg.TubeS(iFile, minSup) +# iFile = 'sampleDB.txt' # -# obj.startMine() +# minSup = 10 # can also be specified between 0 and 1 # -# frequentPatterns = obj.getPatterns() +# obj = alg.TubeS(iFile, minSup) # -# print("Total number of Frequent Patterns:", len(frequentPatterns)) +# obj.mine() # -# obj.save(oFile) +# frequentPatterns = obj.getPatterns() # -# Df = obj.getPatternsAsDataFrame() +# print("Total number of Frequent Patterns:", len(frequentPatterns)) # -# memUSS = obj.getMemoryUSS() +# obj.save(oFile) # -# print("Total Memory in USS:", memUSS) +# Df = obj.getPatternsAsDataFrame() # -# memRSS = obj.getMemoryRSS() +# memUSS = obj.getMemoryUSS() # -# print("Total Memory in RSS", memRSS) +# print("Total Memory in USS:", memUSS) # -# run = obj.getRuntime() +# memRSS = obj.getMemoryRSS() # -# print("Total ExecutionTime in seconds:", run) +# print("Total Memory in RSS", memRSS) +# +# run = obj.getRuntime() +# +# print("Total ExecutionTime in seconds:", run) # @@ -37,13 +40,14 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . - Copyright (C) 2021 Rage Uday Kiran """ from PAMI.uncertainFrequentPattern.basic import abstract as _fp @@ -57,11 +61,14 @@ class _Item: """ A class used to represent the item with probability in transaction of dataset - :Attributes + + :Attributes: + item : int or word - Represents the name of the item + Represents the name of the item + probability : float - Represent the existential probability(likelihood presence) of an item + Represent the existential probability(likelihood presence) of an item """ def __init__(self, item, probability): @@ -72,16 +79,23 @@ def __init__(self, item, probability): class _Node(object): """ A class used to represent the node of frequentPatternTree + :Attributes: + item : int storing item of a node + probability : int To maintain the expected support of node + parent : node To maintain the parent of every node + children : list To maintain the children of node + :Methods: + addChild(itemName) storing the children to their respective parent nodes """ @@ -104,6 +118,7 @@ def addChild(self, node): def Second(transaction, i): """ To calculate the second probability of a node in transaction + :param transaction: transaction in a database :param i: index of item in transaction :return: second probability of a node @@ -120,6 +135,7 @@ def Second(transaction, i): def printTree(root): """ To print the tree with root node through recursion + :param root: root node of tree :return: details of tree """ @@ -131,13 +147,18 @@ def printTree(root): class _Tree(object): """ A class used to represent the frequentPatternGrowth tree structure + :Attributes: + root : Node - Represents the root node of the tree + Represents the root node of the tree + summaries : dictionary - storing the nodes with same item name + storing the nodes with same item name + info : dictionary - stores the support of items + stores the support of items + :Methods: addTransaction(transaction) creating transaction as a branch in frequentPatternTree @@ -161,7 +182,8 @@ def __init__(self): def addTransaction(self, transaction): """ - adding transaction into tree + Adding transaction into tree + :param transaction : it represents the one transactions in database :type transaction : list """ @@ -207,7 +229,8 @@ def addTransaction(self, transaction): def addConditionalTransaction(self, transaction, sup, second): """ - constructing conditional tree from prefixPaths + Constructing conditional tree from prefixPaths + :param transaction : it represents the one transactions in database :type transaction : list :param sup : support of prefixPath taken at last child of the path @@ -238,7 +261,8 @@ def addConditionalTransaction(self, transaction, sup, second): def conditionalPatterns(self, alpha): """ - generates all the conditional patterns of respective node + Generates all the conditional patterns of respective node + :param alpha : it represents the Node in tree :type alpha : _Node """ @@ -263,6 +287,7 @@ def conditionalPatterns(self, alpha): def conditionalTransactions(self, condPatterns, support): """ It generates the conditional patterns with frequent items + :param condPatterns : conditional patterns generated from conditionalPatterns() method for respective node :type condPatterns : list :param support : the support of conditional pattern in tree @@ -292,7 +317,8 @@ def conditionalTransactions(self, condPatterns, support): def removeNode(self, nodeValue): """ - removing the node from tree + Removing the node from tree + :param nodeValue : it represents the node in tree :type nodeValue : node """ @@ -301,7 +327,8 @@ def removeNode(self, nodeValue): def generatePatterns(self, prefix): """ - generates the patterns + Generates the patterns + :param prefix : forms the combination of items :type prefix : list """ @@ -335,48 +362,64 @@ def generatePatterns(self, prefix): class TubeS(_fp._frequentPatterns): """ + About this algorithm + ==================== + :Description: TubeS is one of the fastest algorithm to discover frequent patterns in a uncertain transactional database. - :Reference: - Carson Kai-Sang Leung and Richard Kyle MacKinnon. 2014. Fast Algorithms for Frequent Itemset Mining from Uncertain Data. - In Proceedings of the 2014 IEEE International Conference on Data Mining (ICDM '14). IEEE Computer Society, USA, 893–898. https://doi.org/10.1109/ICDM.2014.146 + :Reference: Carson Kai-Sang Leung and Richard Kyle MacKinnon. 2014. Fast Algorithms for Frequent Itemset Mining from Uncertain Data. + In Proceedings of the 2014 IEEE International Conference on Data Mining (ICDM '14). IEEE Computer Society, USA, 893–898. https://doi.org/10.1109/ICDM.2014.146 :Attributes: + iFile : file Name of the Input file or path of the input file + oFile : file Name of the output file or path of the 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 + sep : str This variable is used to distinguish items from one another in a transaction. The default seperator is tab space or \t. However, the users can override their default separator. + memoryUSS : float To store the total amount of USS memory consumed by the program + memoryRSS : float To store the total amount of RSS memory consumed by the program + startTime : float To record the start time of the mining process + endTime : float To record the completion time of the mining process + Database : list To store the transactions of a database in list + mapSupport : Dictionary To maintain the information of item and their frequency + lno : int To represent the total no of transaction + tree : class To represents the Tree class + itemSetCount : int To represents the total no of patterns + finalPatterns : dict To store the complete patterns :Methods: - startMine() + mine() Mining process will start from here getPatterns() Complete set of patterns will be retrieved with this function @@ -401,23 +444,38 @@ class TubeS(_fp._frequentPatterns): convert() to convert the user specified value - **Methods to execute code on terminal** - -------------------------------------------- - Format: - >>> python3 TubeS.py - Example: - >>> python3 TubeS.py sampleTDB.txt patterns.txt 3 - .. note:: minSup will be considered in support count or frequency + Execution methods + ================= + + + **Terminal command** + + + .. code-block:: console + + Format: + + (.venv) $ python3 TubeS.py + + Example Usage: + + (.venv) $ python3 TubeS.py sampleDB.txt patterns.txt 10.0 + + .. note:: minSup can be specified in support count or a value between 0 and 1. + + **Calling from a python program** - **Importing this algorithm into a python program** - --------------------------------------------------- .. code-block:: python from PAMI.uncertainFrequentPattern.basic import TubeS as alg + iFile = 'sampleDB.txt' + + minSup = 10 # can also be specified between 0 and 1 + obj = alg.TubeS(iFile, minSup) - obj.startMine() + obj.mine() frequentPatterns = obj.getPatterns() @@ -439,10 +497,13 @@ class TubeS(_fp._frequentPatterns): print("Total ExecutionTime in seconds:", run) - **Credits:** - --------------- - The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran. -""" + Credits + ======= + + + The complete program was written by P.Likhitha under the supervision of Professor Rage Uday Kiran. + """ + _startTime = float() _endTime = float() _minSup = float() @@ -535,7 +596,8 @@ def _frequentOneItem(self): def _buildTree(self, data, info): """ - it takes the transactions and support of each item and construct the main tree with setting root node as null + It takes the transactions and support of each item and construct the main tree with setting root node as null + :param data : it represents the one transactions in database :type data : list :param info : it represents the support of each item @@ -549,7 +611,8 @@ def _buildTree(self, data, info): def updateTransactions(self, dict1): """ - remove the items which are not frequent from transactions and updates the transactions with rank of items + Remove the items which are not frequent from transactions and updates the transactions with rank of items + :param dict1 : frequent items with support :type dict1 : dictionary """ @@ -569,6 +632,7 @@ def updateTransactions(self, dict1): def _Check(self, i, x): """ To check the presence of item or pattern in transaction + :param x: it represents the pattern :type x : list :param i : represents the uncertain transactions @@ -586,6 +650,7 @@ def _Check(self, i, x): def _convert(self, value): """ To convert the type of user specified minSup value + :param value: user specified minSup value :return: converted type minSup value """ @@ -603,6 +668,7 @@ def _convert(self, value): def _removeFalsePositives(self): """ To remove the false positive patterns generated in frequent patterns. + :return: Patterns with accurate probability """ global _finalPatterns @@ -629,7 +695,8 @@ def _removeFalsePositives(self): sample = sample + i + "\t" self._finalPatterns[sample] = y - @deprecated("It is recommended to use mine() instead of startMine() for mining process") + @deprecated( + "It is recommended to use 'mine()' instead of 'startMine()' for mining process. Starting from January 2025, 'startMine()' will be completely terminated.") def startMine(self): """ Main method where the patterns are mined by constructing tree and remove the false patterns by counting the original support of a patterns @@ -662,7 +729,9 @@ def mine(self): def getMemoryUSS(self): """ + 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 """ @@ -671,7 +740,9 @@ def getMemoryUSS(self): def getMemoryRSS(self): """ + 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 """ @@ -680,7 +751,9 @@ def getMemoryRSS(self): def getRuntime(self): """ + Calculating the total amount of runtime taken by the mining process + :return: returning total amount of runtime taken by the mining process :rtype: float """ @@ -689,7 +762,9 @@ def getRuntime(self): def getPatternsAsDataFrame(self): """ + Storing final frequent patterns in a dataframe + :return: returning frequent patterns in a dataframe :rtype: pd.DataFrame """ @@ -703,7 +778,9 @@ def getPatternsAsDataFrame(self): def save(self, outFile): """ + Complete set of frequent patterns will be loaded in to an output file + :param outFile: name of the output file :type outFile: file """ @@ -715,7 +792,9 @@ def save(self, outFile): def getPatterns(self): """ + Function to send the set of frequent patterns after completion of the mining process + :return: returning frequent patterns :rtype: dict """