@@ -360,25 +360,25 @@ def removeBatchUtility(self, tempNode):
360360 curBatchUtility = tempNode .utility [0 ]
361361 tempNode .shiftUtility ()
362362
363- if ( sum (tempNode .utility ) == 0 ) :
364- if ( tempNode .itemName in self .headerTable .table ) :
363+ if sum (tempNode .utility ) == 0 :
364+ if tempNode .itemName in self .headerTable .table :
365365 curNode = self .headerTable .table [tempNode .itemName ][1 ]
366366
367- if ( curNode == tempNode ) :
367+ if curNode == tempNode :
368368 self .headerTable .table [tempNode .itemName ][1 ] = tempNode .next
369369
370370 else :
371- while ( curNode != None and curNode .next != tempNode ) :
371+ while curNode is not None and curNode .next is not tempNode :
372372 curNode = curNode .next
373373
374- if ( curNode != None ) :
374+ if curNode is not None :
375375 curNode .next = tempNode .next
376376
377377 self .headerTable .removeUtility (tempNode .itemName , curBatchUtility )
378378
379379 curChilds = list (tempNode .children .keys ())
380380 for child in curChilds :
381- if ( sum (tempNode .children [child ].utility ) == 0 ) :
381+ if sum (tempNode .children [child ].utility ) == 0 :
382382 del tempNode .children [child ]
383383
384384
@@ -604,7 +604,7 @@ def createPrefixBranch(self, root):
604604 """
605605 stack = []
606606
607- while ( root is not None ) :
607+ while root is not None :
608608 stack .append (root )
609609 root = root .parent
610610
@@ -621,10 +621,10 @@ def fixUtility(self, root):
621621 :type root: Node
622622 """
623623
624- if ( root is None ) :
624+ if root is None :
625625 return
626626
627- if ( len (root .utility ) > 1 ) :
627+ if len (root .utility ) > 1 :
628628 root .utility = [sum (root .utility )]
629629
630630 for child in root .children :
@@ -654,12 +654,12 @@ def createConditionalTree(self, root, transactions, minUtil):
654654
655655 for transaction in transactions :
656656 for item in transaction ["transaction" ]:
657- if ( root .headerTable .table [item ][0 ] < minUtil ) :
657+ if root .headerTable .table [item ][0 ] < minUtil :
658658 transaction ["transaction" ].remove (item )
659659
660660 tempTree = _HUSTree (1 , 1 )
661661 for transaction in transactions :
662- if ( len (transaction ["transaction" ]) != 0 ) :
662+ if len (transaction ["transaction" ]) != 0 :
663663 tempTree .addTransaction (transaction ["transaction" ], transaction ["utility" ])
664664
665665 self .fixUtility (tempTree .root )
@@ -685,7 +685,7 @@ def contains(self, superset, subset):
685685
686686 return reduce (and_ , [i in superset for i in subset ])
687687
688- def treeGenerations (self , root , netUtil , candidatePattern , curItem = [] ):
688+ def treeGenerations (self , root , netUtil , candidatePattern , curItem = None ):
689689 """
690690 Generates the tree of the high utility patterns
691691
@@ -706,12 +706,12 @@ def treeGenerations(self, root, netUtil, candidatePattern, curItem = []):
706706 :type curItem: list
707707 """
708708
709- if ( root is None ) :
709+ if root is None :
710710 return
711711
712712
713713 for item in reversed (root .headerTable .orderedItems ):
714- if ( root .headerTable .table [item ][0 ] >= netUtil ) :
714+ if root .headerTable .table [item ][0 ] >= netUtil :
715715 prefixBranches = []
716716
717717 tempNode = root .headerTable .table [item ][1 ]
@@ -738,13 +738,13 @@ def treeGenerations(self, root, netUtil, candidatePattern, curItem = []):
738738 newItemset = curItem .copy ()
739739 newItemset .append (item )
740740
741- if ( len (newItemset ) not in candidatePattern ) :
741+ if len (newItemset ) not in candidatePattern :
742742 candidatePattern [len (newItemset )] = [newItemset ]
743743
744744 else :
745745 candidatePattern [len (newItemset )].append (newItemset )
746746
747- if ( len (conditionalTree .headerTable .table ) != 0 ) :
747+ if len (conditionalTree .headerTable .table ) != 0 :
748748 self .treeGenerations (conditionalTree , netUtil , candidatePattern , newItemset )
749749
750750 @deprecated ("It is recommended to use 'mine()' instead of 'mine()' for mining process. Starting from January 2025, 'mine()' will be completely terminated." )
@@ -792,7 +792,7 @@ def mine(self):
792792 startIndex = 0
793793 endIndex = self .__windowSize * self .__paneSize
794794
795- while ( endIndex <= len (self ._transactions ) ):
795+ while endIndex <= len (self ._transactions ):
796796
797797 filteredItemsets = {}
798798
@@ -808,12 +808,12 @@ def mine(self):
808808 for item in itemSet :
809809 itemSetUtility += transactionwiseUtility [transId ][item ]
810810
811- if ( itemSetUtility >= self ._minUtil ) :
811+ if itemSetUtility >= self ._minUtil :
812812 results .append ([itemSet , itemSetUtility ])
813813
814814 self .__finalPatterns [(startIndex , endIndex )] = results
815815
816- if ( endIndex >= len (self ._transactions ) ):
816+ if endIndex >= len (self ._transactions ):
817817 break
818818
819819 self .__tree .removeBatch ()
0 commit comments