From 44b0cc0c6b1e61c447901c84ec2c3a6b65851a64 Mon Sep 17 00:00:00 2001 From: Likhitha Date: Tue, 23 Apr 2024 10:32:00 +0900 Subject: [PATCH 1/3] Documentation --- .../basic/WUFIM.py | 140 ++++++++++++------ 1 file changed, 94 insertions(+), 46 deletions(-) diff --git a/PAMI/weightedUncertainFrequentPattern/basic/WUFIM.py b/PAMI/weightedUncertainFrequentPattern/basic/WUFIM.py index 3b6b41a5..88fc15fc 100644 --- a/PAMI/weightedUncertainFrequentPattern/basic/WUFIM.py +++ b/PAMI/weightedUncertainFrequentPattern/basic/WUFIM.py @@ -1,14 +1,16 @@ # WUFIM is one of the algorithm to discover weighted frequent patterns in an uncertain transactional database using PUF-Tree. # # **Importing this algorithm into a python program** -# -------------------------------------------------------- -# # # from PAMI.weightedUncertainFrequentPattern.basic import basic as alg # +# iFile = 'sampleDB.txt' +# +# minSup = 10 +# # obj = alg.basic(iFile, wFile, minSup, sep) # -# obj.startMine() +# obj.mine() # # Patterns = obj.getPatterns() # @@ -32,7 +34,6 @@ # - __copyright__ = """ Copyright (C) 2021 Rage Uday Kiran @@ -47,8 +48,7 @@ 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 ``_. - + along with this program. If not, see ``_. """ from PAMI.weightedUncertainFrequentPattern.basic import abstract as _ab @@ -67,10 +67,10 @@ class _Item: :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: int, probability: float) -> None: @@ -85,13 +85,16 @@ class _Node(object): :Attributes: item : int - storing item of a node + storing item of a node + probability : int - To maintain the expected support of node + To maintain the expected support of node + parent : node - To maintain the parent of every node + To maintain the parent of every node + children : list - To maintain the children of node + To maintain the children of node :Methods: @@ -106,6 +109,13 @@ def __init__(self, item, children: list) -> None: self.parent = None def addChild(self, node) -> None: + """ + This method is used to add a child node to the current node in the frequent pattern tree. + + :param node:The node to be added as a child + :type node:_Node + :return: None + """ self.children[node.item] = node node.parent = self @@ -118,8 +128,10 @@ 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 @@ -149,8 +161,8 @@ def addTransaction(self, transaction) -> None: """ Adding transaction into tree - :param transaction : it represents the one self.Database in database - :type transaction : list + :param transaction: it represents the one self.Database in database + :type transaction: list :return: None """ currentNode = self.root @@ -193,7 +205,6 @@ def addConditionalPattern(self, transaction, sup) -> None: :param sup : support of prefixPath taken at last child of the path :type sup : int :return: None - """ # This method takes transaction, support and constructs the conditional tree currentNode = self.root @@ -217,7 +228,7 @@ def conditionalPatterns(self, alpha) -> tuple: :param alpha : it represents the Node in tree :type alpha : _Node - + :return: tuple """ # This method generates conditional patterns of node by traversing the tree finalPatterns = [] @@ -236,7 +247,6 @@ def conditionalPatterns(self, alpha) -> tuple: return finalPatterns, support, info def removeNode(self, nodeValue) -> None: - """ Removing the node from tree @@ -310,9 +320,13 @@ def generatePatterns(self, prefix) -> None: class WUFIM(_ab._weightedFrequentPatterns): """ + About this algorithm + ==================== + :Description: It is one of the algorithm to discover weighted frequent patterns in a uncertain transactional database using PUF-Tree. - :Reference: Efficient Mining of Weighted Frequent Itemsets in Uncertain Databases, In book: Machine Learning and Data Mining in Pattern Recognition Chun-Wei Jerry Lin, Wensheng Gan, Philippe Fournier Viger, Tzung-Pei Hong + :Reference: Efficient Mining of Weighted Frequent Itemsets in Uncertain Databases. + In : Machine Learning and Data Mining in Pattern Recognition book Chun-Wei Jerry Lin, Wensheng Gan, Philippe Fournier Viger, Tzung-Pei Hong :param iFile: str : Name of the Input file to mine complete set of Weighted Uncertain Periodic Frequent Patterns @@ -329,39 +343,53 @@ class WUFIM(_ab._weightedFrequentPatterns): :Attributes: iFile : file - Name of the Input file or path of the input file + Name of the Input file or path of the input file + wFile : file - Name of the Input file or path of the input 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 + 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 + 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. + 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 + 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 + To store the total amount of RSS memory consumed by the program + startTime:float - To record the start time of the mining process + To record the start time of the mining process + endTime:float - To record the completion time of the mining process + To record the completion time of the mining process + Database : list - To store the transactions of a database in list + To store the transactions of a database in list + mapSupport : Dictionary - To maintain the information of item and their frequency + To maintain the information of item and their frequency + lno : int - To represent the total no of transaction + To represent the total no of transaction + tree : class - To represents the Tree class + To represents the Tree class + itemSetCount : int - To represents the total no of patterns + To represents the total no of patterns + finalPatterns : dict - To store the complete patterns + To store the complete patterns :Methods: @@ -392,11 +420,15 @@ class WUFIM(_ab._weightedFrequentPatterns): startMine() Mining process will start from this function - **Methods to execute code on terminal** - -------------------------------------------- - .. code-block:: console + Execution methods + ================= + + + **Terminal command** + .. code-block:: console + Format: (.venv) $ python3 basic.py @@ -405,19 +437,21 @@ class WUFIM(_ab._weightedFrequentPatterns): (.venv) $ python3 basic.py sampleTDB.txt patterns.txt 3 + .. note:: minSup will be considered in support count or frequency - .. note:: minSup will be considered in support count or frequency + **Calling from a python program** - - **Importing this algorithm into a python program** - ----------------------------------------------------- .. code-block:: python from PAMI.weightedUncertainFrequentPattern.basic import basic as alg + iFile = 'sampleDB.txt' + + minSup = 10 # can also be specified between 0 and 1 + obj = alg.basic(iFile, wFile, expSup, expWSup) - obj.startMine() + obj.mine() Patterns = obj.getPatterns() @@ -438,6 +472,7 @@ class WUFIM(_ab._weightedFrequentPatterns): run = obj.getRuntime() print("Total ExecutionTime in seconds:", run) + """ _startTime = float() _endTime = float() @@ -460,6 +495,7 @@ def __init__(self, iFile, wFile, expSup, expWSup, sep='\t') -> None: def _creatingItemSets(self) -> None: """ Scans the uncertain transactional dataset + :return: None """ self._Database = [] @@ -521,6 +557,7 @@ def _creatingItemSets(self) -> None: def _scanningWeights(self) -> None: """ Scans the uncertain transactional dataset + :return: None """ self._weights = {} @@ -582,6 +619,7 @@ def _frequentOneItem(self) -> tuple: 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 + :param data : it represents the one self.Database in database :type data : list :param info : it represents the support of each item @@ -659,6 +697,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 @@ -727,7 +766,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 """ @@ -736,7 +777,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 """ @@ -744,7 +787,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 """ @@ -753,7 +798,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 """ @@ -786,7 +833,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 """ @@ -795,7 +844,6 @@ def getPatterns(self) -> dict: def printResults(self) -> None: """ This function is used to print the results - :return: None """ print("Total number of Weighted Uncertain Frequent Patterns:", len(self.getPatterns())) print("Total Memory in USS:", self.getMemoryUSS()) From 054e6ef28ed38c925d58ffa2642fbbcdb93a4363 Mon Sep 17 00:00:00 2001 From: Likhitha Date: Tue, 23 Apr 2024 10:35:27 +0900 Subject: [PATCH 2/3] Documentation --- .../basic/WFRIMiner.py | 96 +++++++++++++------ 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/PAMI/weightedFrequentRegularPattern/basic/WFRIMiner.py b/PAMI/weightedFrequentRegularPattern/basic/WFRIMiner.py index 6063787e..37b6a738 100644 --- a/PAMI/weightedFrequentRegularPattern/basic/WFRIMiner.py +++ b/PAMI/weightedFrequentRegularPattern/basic/WFRIMiner.py @@ -1,15 +1,16 @@ -# WFRIMiner is one of the fundamental algorithm to discover weighted frequent regular patterns in a transactional database. -# It stores the database in compressed WFRI-tree decreasing the memory usage and extracts the patterns from tree.It employs downward closure property to reduce the search space effectively. +# WFRIMiner is one of the fundamental algorithm to discover weighted frequent regular patterns in a transactional database. It stores the database in compressed WFRI-tree decreasing the memory usage and extracts the patterns from tree.It employs downward closure property to reduce the search space effectively. # # **Importing this algorithm into a python program** -# -------------------------------------------------------- -# # # from PAMI.weightedFrequentRegularPattern.basic import WFRIMiner as alg # +# iFile = 'sampleDB.txt' +# +# minSup = 10 # can also be specified between 0 and 1 +# # obj = alg.WFRIMiner(iFile, WS, regularity) # -# obj.startMine() +# obj.mine() # # weightedFrequentRegularPatterns = obj.getPatterns() # @@ -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 - """ from PAMI.weightedFrequentRegularPattern.basic import abstract as _fp @@ -71,16 +70,21 @@ class _Node: A class used to represent the node of frequentPatternTree :Attributes: + itemId: int storing item of a node + counter: int To maintain the support of node + parent: node To maintain the parent of node + children: list To maintain the children of node :Methods: + addChild(node) Updates the nodes children list and parent for the given node @@ -119,10 +123,13 @@ class _Tree: A class used to represent the frequentPatternGrowth tree structure :Attributes: + root : Node The first node of the tree set to Null. + summaries : dictionary Stores the nodes itemId which shares same itemId + info : dictionary frequency of items in the transactions @@ -320,13 +327,15 @@ def generatePatterns(self, prefix: list) -> None: class WFRIMiner(_fp._weightedFrequentRegularPatterns): """ + About this algorithm + ==================== + :Description: WFRIMiner is one of the fundamental algorithm to discover weighted frequent regular patterns in a transactional database. * It stores the database in compressed WFRI-tree decreasing the memory usage and extracts the patterns from tree.It employs downward closure property to reduce the search space effectively. - :Reference: - K. Klangwisan and K. Amphawan, "Mining weighted-frequent-regular itemsets from transactional database," - 2017 9th International Conference on Knowledge and Smart Technology (KST), 2017, pp. 66-71, - doi: 10.1109/KST.2017.7886090. + :Reference: K. Klangwisan and K. Amphawan, "Mining weighted-frequent-regular itemsets from transactional database," + 2017 9th International Conference on Knowledge and Smart Technology (KST), 2017, pp. 66-71, + doi: 10.1109/KST.2017.7886090. :param iFile: str : Name of the Input file to mine complete set of Weighted Frequent Regular Patterns. @@ -335,43 +344,58 @@ class WFRIMiner(_fp._weightedFrequentRegularPatterns): :param 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. :param wFile: str : - This is a weighted file. + This is a weighted file. + + :Attributes: iFile : file Input file name or path of the input file + WS: float or int or str The user can specify WS either in count or proportion of database size. If the program detects the data type of WS is integer, then it treats WS is expressed in count. Otherwise, it will be treated as float. Example: WS=10 will be treated as integer, while WS=10.0 will be treated as float + regularity: float or int or str The user can specify regularity either in count or proportion of database size. If the program detects the data type of regularity is integer, then it treats regularity is expressed in count. Otherwise, it will be treated as float. Example: regularity=10 will be treated as integer, while regularity=10.0 will be treated as float + sep : str This variable is used to distinguish items from one another in a transaction. The default separator is tab space or \t. However, the users can override their default separator. + oFile : file Name of the output file or the path of the output file + startTime:float To record the start time of the mining process + endTime:float To record the completion time of the mining process + 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 + Database : list To store the transactions of a database in list + mapSupport : Dictionary To maintain the information of item and their frequency + lno : int it represents the total no of transactions + tree : class it represents the Tree class + finalPatterns : dict it represents to store the patterns @@ -396,10 +420,14 @@ class WFRIMiner(_fp._weightedFrequentRegularPatterns): frequentOneItem() Extracts the one-frequent patterns from transactions - **Methods to execute code on terminal** - ------------------------------------------- - .. code-block:: console + Execution methods + ================= + + + **Terminal command** + + .. code-block:: console Format: @@ -409,19 +437,22 @@ class WFRIMiner(_fp._weightedFrequentRegularPatterns): (.venv) $ python3 WFRIMiner.py sampleDB.txt patterns.txt 10 5 + .. note:: WS & regularity will be considered in support count or frequency - .. note:: WS & regularity will be considered in support count or frequency + **Calling from a python program** - **Importing this algorithm into a python program** - ---------------------------------------------------- .. code-block:: python from PAMI.weightedFrequentRegularpattern.basic import WFRIMiner as alg + iFile = 'sampleDB.txt' + + minSup = 10 # can also be specified between 0 and 1 + obj = alg.WFRIMiner(iFile, WS, regularity) - obj.startMine() + obj.mine() weightedFrequentRegularPatterns = obj.getPatterns() @@ -443,11 +474,12 @@ class WFRIMiner(_fp._weightedFrequentRegularPatterns): 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() @@ -474,6 +506,7 @@ def __init__(self, iFile, _wFile, WS, regularity, sep='\t') -> None: def _creatingItemSets(self) -> None: """ Storing the complete transactions of the database/input file in a database variable + :return: None """ self._Database = [] @@ -562,6 +595,7 @@ def _convert(self, value) -> float: def _frequentOneItem(self) -> List[str]: """ Generating One frequent items sets + :return: list """ global _lno, _wf, _weights @@ -600,9 +634,8 @@ def _updateTransactions(self, itemSet) -> List[List[int]]: """ Updates the items in transactions with rank of items according to their support - :Example: - oneLength = {'a':7, 'b': 5, 'c':'4', 'd':3} - rank = {'a':0, 'b':1, 'c':2, 'd':3} + :Example: oneLength = {'a':7, 'b': 5, 'c':'4', 'd':3} + rank = {'a':0, 'b':1, 'c':2, 'd':3} :param itemSet: list of one-frequent items :return: None @@ -653,15 +686,13 @@ def _savePeriodic(self, itemSet) -> str: @deprecated("It is recommended to use mine() instead of startMine() for mining process") def startMine(self) -> None: """ - main program to start the operation - :return: None + Frequent pattern mining process will start from here """ self.mine() def mine(self) -> None: """ - main program to start the operation - :return: None + Frequent pattern mining process will start from here """ global _WS, _regularity, _weights self._startTime = _fp._time.time() @@ -696,6 +727,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 @@ -706,6 +738,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 @@ -716,6 +749,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 @@ -726,6 +760,7 @@ def getRuntime(self) -> float: def getPatternsAsDataFrame(self) -> _fp._pd.DataFrame: """ + Storing final frequent patterns in a dataframe :return: returning frequent patterns in a dataframe @@ -741,6 +776,7 @@ def getPatternsAsDataFrame(self) -> _fp._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 @@ -755,6 +791,7 @@ 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 @@ -765,7 +802,6 @@ def getPatterns(self) -> Dict[str, float]: def printResults(self) -> None: """ This function is used to print the results - :return: None """ print("Total number of Weighted Frequent Regular Patterns:", len(self.getPatterns())) print("Total Memory in USS:", self.getMemoryUSS()) From 399a4eccbb325800c03876a4aa75b43b01c6d518 Mon Sep 17 00:00:00 2001 From: Likhitha Date: Tue, 23 Apr 2024 10:39:22 +0900 Subject: [PATCH 3/3] Documentation --- PAMI/weightedFrequentPattern/basic/WFIM.py | 93 +++++++++++++------ .../basic/WFRIMiner.py | 3 +- .../basic/WUFIM.py | 3 +- 3 files changed, 70 insertions(+), 29 deletions(-) diff --git a/PAMI/weightedFrequentPattern/basic/WFIM.py b/PAMI/weightedFrequentPattern/basic/WFIM.py index 727cea37..62c508e6 100644 --- a/PAMI/weightedFrequentPattern/basic/WFIM.py +++ b/PAMI/weightedFrequentPattern/basic/WFIM.py @@ -3,14 +3,16 @@ # patterns from tree.It employs downward closure property to reduce the search space effectively. # # **Importing this algorithm into a python program** -# ---------------------------------------------------------- -# # # from PAMI.weightFrequentPattern.basic import basic as alg # +# iFile = 'sampleDB.txt' +# +# minSup = 10 # can also be specified between 0 and 1 +# # obj = alg.basic(iFile, wFile, minSup, minWeight) # -# obj.startMine() +# obj.mine() # # frequentPatterns = obj.getPatterns() # @@ -48,8 +50,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 - """ from PAMI.weightedFrequentPattern.basic import abstract as _fp @@ -74,10 +74,13 @@ class _Node: itemId: int storing item of a node + counter: int To maintain the support of node + parent: node To maintain the parent of node + children: list To maintain the children of node @@ -98,7 +101,7 @@ def addChild(self, node: '_Node') -> None: Retrieving the child from the tree :param node: Children node - :type node: Node + :type node: _Node :return: Updates the children nodes and parent nodes """ self.children[node.itemId] = node @@ -113,8 +116,10 @@ class _Tree: root : Node The first node of the tree set to Null. + summaries : dictionary Stores the nodes itemId which shares same itemId + info : dictionary frequency of items in the transactions @@ -237,14 +242,15 @@ def generatePatterns(self, prefix: List[str]) -> Generator[Tuple[List[str], int] class WFIM(_fp._weightedFrequentPatterns): """ - :Description: - * WFMiner is one of the fundamental algorithm to discover weighted frequent patterns in a transactional database. - * It stores the database in compressed fp-tree decreasing the memory usage and extracts the patterns from tree.It employs employs downward closure property to reduce the search space effectively. + About this algorithm + ==================== - :Reference : - U. Yun and J. J. Leggett, “Wfim: weighted frequent itemset mining with a weight range and a minimum weight,” - in Proceedings of the 2005 SIAM International Conference on Data Mining. SIAM, 2005, pp. 636–640. - https://epubs.siam.org/doi/pdf/10.1137/1.9781611972757.76 + :Description: * WFMiner is one of the fundamental algorithm to discover weighted frequent patterns in a transactional database. + * It stores the database in compressed fp-tree decreasing the memory usage and extracts the patterns from tree.It employs employs downward closure property to reduce the search space effectively. + + :Reference: U. Yun and J. J. Leggett, “Wfim: weighted frequent itemset mining with a weight range and a minimum weight,” + In: Proceedings of the 2005 SIAM International Conference on Data Mining. SIAM, 2005, pp. 636–640. + https://epubs.siam.org/doi/pdf/10.1137/1.9781611972757.76 :param iFile: str : Name of the Input file to mine complete set of weighted Frequent Patterns. @@ -260,43 +266,56 @@ class WFIM(_fp._weightedFrequentPatterns): iFile : file Input file name or path of the input 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 + minWeight: float or int or str The user can specify minWeight either in count or proportion of database size. If the program detects the data type of minWeight is integer, then it treats minWeight is expressed in count. Otherwise, it will be treated as float. Example: minWeight=10 will be treated as integer, while minWeight=10.0 will be treated as float + sep : str This variable is used to distinguish items from one another in a transaction. The default separator is tab space or \t. However, the users can override their default separator. + oFile : file Name of the output file or the path of the output file + startTime:float To record the start time of the mining process + endTime:float To record the completion time of the mining process + 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 + Database : list To store the transactions of a database in list + mapSupport : Dictionary To maintain the information of item and their frequency + lno : int it represents the total no of transactions + tree : class it represents the Tree class + finalPatterns : dict it represents to store the patterns :Methods : - startMine() + mine() Mining process will start from here getPatterns() Complete set of patterns will be retrieved with this function @@ -315,11 +334,15 @@ class WFIM(_fp._weightedFrequentPatterns): frequentOneItem() Extracts the one-frequent patterns from transactions - **Methods to execute code on terminal** - ------------------------------------------- - .. code-block:: console + Execution methods + ================= + **Terminal command** + + + .. code-block:: console + Format: (.venv) $ python3 basic.py @@ -328,19 +351,22 @@ class WFIM(_fp._weightedFrequentPatterns): (.venv) $ python3 basic.py sampleDB.txt weightSample.txt patterns.txt 10.0 3.4 + .. note:: minSup and maxPer will be considered in support count or frequency - .. note:: minSup and maxPer will be considered in support count or frequency + **Calling from a python program** - **Importing this algorithm into a python program** - ----------------------------------------------------- .. code-block:: python from PAMI.weightFrequentPattern.basic import basic as alg + iFile = 'sampleDB.txt' + + minSup = 10 # can also be specified between 0 and 1 + obj = alg.basic(iFile, wFile, minSup, minWeight) - obj.startMine() + obj.mine() frequentPatterns = obj.getPatterns() @@ -362,11 +388,12 @@ class WFIM(_fp._weightedFrequentPatterns): 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() @@ -390,6 +417,7 @@ def __init__(self, iFile: str, wFile: str, minSup: str, minWeight: int, sep: str def __creatingItemSets(self) -> None: """ Storing the complete transactions of the database/input file in a database variable + :return: None """ self.__Database = [] @@ -426,6 +454,7 @@ def __creatingItemSets(self) -> None: def _scanningWeights(self) -> None: """ Storing the weights of the variables in input file in a weights variable + :return: None """ global _weights @@ -487,6 +516,7 @@ def __convert(self, value: Union[int, float, str]) -> Union[int, float]: def __frequentOneItem(self) -> List[str]: """ Generating One frequent items sets + :return: list """ global _maxWeight @@ -505,6 +535,7 @@ def __frequentOneItem(self) -> List[str]: def __updateTransactions(self, itemSet: List[str]) -> List[List[int]]: """ Updates the items in transactions with rank of items according to their support + :Example: oneLength = {'a':7, 'b': 5, 'c':'4', 'd':3} rank = {'a':0, 'b':1, 'c':2, 'd':3} @@ -549,10 +580,12 @@ def __savePeriodic(self, itemSet: List[int]) -> str: temp = temp + self.__rankDup[i] + "\t" return temp - @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 program to start the operation + :return: None """ self.mine() @@ -560,6 +593,7 @@ def startMine(self) -> None: def mine(self) -> None: """ main program to start the operation + :return: None """ global _minSup, _minWeight, _miniWeight, _maxWeight, _weights @@ -597,6 +631,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 @@ -607,6 +642,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 @@ -617,6 +653,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 @@ -627,6 +664,7 @@ def getRuntime(self) -> float: def getPatternsAsDataFrame(self) -> pd.DataFrame: """ + Storing final frequent patterns in a dataframe. :return: returning frequent patterns in a dataframe @@ -642,6 +680,7 @@ 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 @@ -656,6 +695,7 @@ def save(self, outFile: str) -> None: def getPatterns(self) -> Dict[str, int]: """ + Function to send the set of frequent patterns after completion of the mining process. :return: returning frequent patterns @@ -666,7 +706,6 @@ def getPatterns(self) -> Dict[str, int]: def printResults(self) -> None: """ This function is used to print the results - :return: None """ print("Total number of Weighted Frequent Patterns:", len(self.getPatterns())) print("Total Memory in USS:", self.getMemoryUSS()) diff --git a/PAMI/weightedFrequentRegularPattern/basic/WFRIMiner.py b/PAMI/weightedFrequentRegularPattern/basic/WFRIMiner.py index 37b6a738..60ca790b 100644 --- a/PAMI/weightedFrequentRegularPattern/basic/WFRIMiner.py +++ b/PAMI/weightedFrequentRegularPattern/basic/WFRIMiner.py @@ -683,7 +683,8 @@ def _savePeriodic(self, itemSet) -> str: temp = temp + self._rankDup[i] + "\t" return temp - @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: """ Frequent pattern mining process will start from here diff --git a/PAMI/weightedUncertainFrequentPattern/basic/WUFIM.py b/PAMI/weightedUncertainFrequentPattern/basic/WUFIM.py index 88fc15fc..27bfa00f 100644 --- a/PAMI/weightedUncertainFrequentPattern/basic/WUFIM.py +++ b/PAMI/weightedUncertainFrequentPattern/basic/WUFIM.py @@ -728,7 +728,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: """ startMine() method where the patterns are mined by constructing tree and remove the false patterns by counting the original support of a patterns.