Skip to content

Commit dfbd6e8

Browse files
Merge pull request #564 from LasyaPalla/main
Updated few changes in the files according to inspection profiles
2 parents fa2a4d8 + 498e7fa commit dfbd6e8

File tree

215 files changed

+1929
-1744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+1929
-1744
lines changed

PAMI/AssociationRules/basic/_ARWithLift.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def printResults(self) -> None:
394394
if len(_ab._sys.argv) == 5:
395395
_ap = ARWithLift(_ab._sys.argv[1], float(_ab._sys.argv[3]), _ab._sys.argv[4])
396396
if len(_ab._sys.argv) == 4:
397-
_ap = ARWithLift(_ab._sys.argv[1], _ab._sys.argv[3],sep='\t')
397+
_ap = ARWithLift(_ab._sys.argv[1], float(_ab._sys.argv[3]),sep='\t')
398398
_ap.mine()
399399
_ap.mine()
400400
print("Total number of Association Rules:", len(_ap.getPatterns()))

PAMI/AssociationRules/basic/_RuleMiner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _generation(self, prefix, suffix):
7575
:type suffix: str
7676
"""
7777
if len(suffix) == 1:
78-
conf = self._generaeWithConfidence(prefix, suffix[0])
78+
self._generaeWithConfidence(prefix, suffix[0])
7979
for i in range(len(suffix)):
8080
suffix1 = suffix[:i] + suffix[i+1:]
8181
prefix1 = prefix + ' ' + suffix[i]
@@ -223,7 +223,7 @@ def _generation(self, prefix, suffix):
223223
:type suffix: str
224224
"""
225225
if len(suffix) == 1:
226-
conf = self._generateWithLeverage(prefix, suffix[0])
226+
self._generateWithLeverage(prefix, suffix[0])
227227
for i in range(len(suffix)):
228228
suffix1 = suffix[:i] + suffix[i+1:]
229229
prefix1 = prefix + ' ' + suffix[i]
@@ -263,7 +263,7 @@ def run(self):
263263
suffix = self._singleItems[:i] + self._singleItems[i+1:]
264264
prefix = self._singleItems[i]
265265
for j in range(i+1, len(self._singleItems)):
266-
conf = self._generateWithLeverage(self._singleItems[i], self._singleItems[j])
266+
self._generateWithLeverage(self._singleItems[i], self._singleItems[j])
267267
self._generation(prefix, suffix)
268268

269269
class RuleMiner:
@@ -547,7 +547,7 @@ def printResults(self):
547547
if len(_ab._sys.argv) == 6:
548548
_ap = RuleMiner(_ab._sys.argv[1], _ab._sys.argv[3], float(_ab._sys.argv[4]), _ab._sys.argv[5])
549549
if len(_ab._sys.argv) == 5:
550-
_ap = RuleMiner(_ab._sys.argv[1], _ab._sys.argv[3], _ab._sys.argv[4],sep='\t')
550+
_ap = RuleMiner(_ab._sys.argv[1], _ab._sys.argv[3], float(_ab._sys.argv[4]),sep='\t')
551551
_ap.mine()
552552
_ap.mine()
553553
print("Total number of Association Rules:", len(_ap.getPatterns()))

PAMI/AssociationRules/basic/leverage.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class leverage:
145145
_memoryRSS = float()
146146
_associationRules = {}
147147

148-
def __init__(self, iFile, minLev, sep, maxTS):
148+
def __init__(self, iFile, minLev, maxTS, sep):
149149
"""
150150
:param iFile: input file name or path
151151
:type iFile: str
@@ -339,11 +339,11 @@ def printResults(self):
339339

340340
if __name__ == "__main__":
341341
_ap = str()
342-
if len(_ab._sys.argv) == 4 or len(_ab._sys.argv) == 5:
342+
if len(_ab._sys.argv) == 5 or len(_ab._sys.argv) == 6:
343+
if len(_ab._sys.argv) == 6:
344+
_ap = leverage(_ab._sys.argv[1], float(_ab._sys.argv[3]), int(_ab._sys.argv[4]),_ab._sys.argv[5])
343345
if len(_ab._sys.argv) == 5:
344-
_ap = leverage(_ab._sys.argv[1], float(_ab._sys.argv[3]), _ab._sys.argv[4])
345-
if len(_ab._sys.argv) == 4:
346-
_ap = leverage(_ab._sys.argv[1], _ab._sys.argv[3],sep='\t')
346+
_ap = leverage(_ab._sys.argv[1],float(_ab._sys.argv[3]),int(_ab.sys.argv[4]),sep='\t')
347347
_ap.mine()
348348
_ap.mine()
349349
print("Total number of Association Rules:", len(_ap.getAssociationRules()))

PAMI/contiguousFrequentPattern/basic/PositionMining.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@
3232

3333

3434
import pandas as pd
35-
import numpy as np
36-
import math
37-
from PAMI.contiguousFrequentPattern import abstract as _ab
35+
#import numpy as np
36+
#import math
37+
from PAMI.contiguousFrequentPattern.basic import abstract as _ab
3838
from deprecated import deprecated
3939

4040

4141
class Node:
4242
def __init__(self,symbol,leaf=False):
4343
self._val=symbol
44-
self.children=[None for i in range(26)]
44+
self.children=[None for _ in range(26)]
4545
self.leaf=leaf
4646
self.freq={}
4747
self.count=1
@@ -125,7 +125,7 @@ def getfreqs(self):
125125

126126
temp={}
127127
for i in self.symbol_freq:
128-
if(len(self.symbol_freq[i])>=self.min_sup):
128+
if len(self.symbol_freq[i])>=self.min_sup:
129129
temp.update({i:self.symbol_freq[i]})
130130
self.symbol_freq=temp
131131

@@ -151,8 +151,8 @@ def getPatternsAsDataFrame(self):
151151
:rtype: pd.DataFrame
152152
"""
153153

154-
dataFrame = {}
155-
data = []
154+
#dataFrame = {}
155+
#data = []
156156
seqs=[]
157157
sup=[]
158158
for i in self.frequentPatterns:
@@ -245,22 +245,22 @@ def join(self,db,length):
245245
"""
246246
for seq1 in db:
247247
for seq2 in db:
248-
if(seq1!=seq2):
249-
if(length==1):
248+
if seq1!=seq2:
249+
if length==1:
250250
word=seq1+seq2
251251
# print(seq1,seq2,db[seq1],db[seq2])
252252
minus_1={i-1 for i in db[seq2]}
253253
positions=db[seq1].intersection(minus_1)
254-
if(len(positions)>=self.min_sup):
254+
if len(positions)>=self.min_sup:
255255
self.table[length+1].update({word:positions})
256256

257257

258258
else:
259-
if(seq1[1:]== seq2[:-1]):
259+
if seq1[1:]== seq2[:-1]:
260260
word=seq1+seq2[-1]
261261
minus_1={i-1 for i in db[seq2]}
262262
positions=db[seq1].intersection(minus_1)
263-
if(len(positions)>=self.min_sup):
263+
if len(positions)>=self.min_sup:
264264
self.table[length+1].update({word:positions})
265265

266266

PAMI/correlatedPattern/basic/CoMine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def _creatingItemSets(self) -> None:
268268
quit()
269269

270270

271-
def _convert(self, value: Union[int, float, str]) -> None:
271+
def _convert(self, value: Union[int, float, str]):
272272
"""
273273
To convert the type of user specified minSup value
274274
@@ -357,7 +357,7 @@ def recursive(self, item, nodes, root):
357357
itemNodes = {}
358358
for transaction, count in transactions:
359359
transaction = [i for i in transaction if i in itemCounts]
360-
transaction = sorted(transaction, key=lambda item: itemCounts[item], reverse=True)
360+
transaction = sorted(transaction, key=lambda _item: itemCounts[_item], reverse=True)
361361
node = newRoot
362362
for item in transaction:
363363
node = node.addChild(item, count)

PAMI/correlatedPattern/basic/CoMinePlus.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def _creatingItemSets(self) -> None:
268268
quit()
269269

270270

271-
def _convert(self, value: Union[int, float, str]) -> None:
271+
def _convert(self, value: Union[int, float, str]):
272272
"""
273273
To convert the type of user specified minSup value
274274
@@ -351,7 +351,7 @@ def recursive(self, item, nodes, root):
351351
itemNodes = {}
352352
for transaction, count in transactions:
353353
transaction = [i for i in transaction if i in itemCounts]
354-
transaction = sorted(transaction, key=lambda item: itemCounts[item], reverse=True)
354+
transaction = sorted(transaction, key=lambda _item: itemCounts[_item], reverse=True)
355355
node = newRoot
356356
for item in transaction:
357357
node = node.addChild(item, count)
@@ -417,7 +417,7 @@ def mine(self) -> None:
417417
nitemsCounts[trans] = 0
418418
nitemsCounts[trans] += count
419419

420-
nitemsCounts = {k:v for k, v in nitemsCounts.items() if v <= bound and v >= self._minSup}
420+
nitemsCounts = {k:v for k, v in nitemsCounts.items() if bound >= v >= self._minSup}
421421
nitemNode = {}
422422
for transaction, count in ntransactions:
423423
temp = []

PAMI/correlatedPattern/basic/_CoMine.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def createHeaderList(self, mapSupport: Dict[int, int], minSup: int) -> None:
195195
for x, y in mapSupport.items():
196196
if y >= minSup:
197197
t1.append(x)
198-
itemSetBuffer = [k for k, v in sorted(mapSupport.items(), key=lambda x: x[1], reverse=True)]
198+
itemSetBuffer = [k for k, v in sorted(mapSupport.items(), key=lambda _x: _x[1], reverse=True)]
199199
self.headerList = [i for i in t1 if i in itemSetBuffer]
200200

201201
def addPrefixPath(self, prefix: List['_Node'], mapSupportBeta, minSup) -> None:
@@ -438,7 +438,7 @@ def _saveItemSet(self, prefix, prefixLength, support) -> None:
438438
self._itemSetCount += 1
439439
self._finalPatterns[tuple(l)] = [support, all_conf]
440440

441-
def _convert(self, value: Union[int, float, str]) -> None:
441+
def _convert(self, value: Union[int, float, str]) -> float | int | str:
442442
"""
443443
To convert the type of user specified minSup value
444444
@@ -530,8 +530,7 @@ def _correlatedPatternGrowthGenerate(self, correlatedPatternTree, prefix, prefix
530530
mapSupportBeta = {}
531531
while path is not None:
532532
if path.parent.itemId != -1:
533-
prefixPath = []
534-
prefixPath.append(path)
533+
prefixPath = [path]
535534
pathCount = path.counter
536535
parent1 = path.parent
537536
while parent1.itemId != -1:

PAMI/coveragePattern/basic/CMine.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858

5959
from PAMI.coveragePattern.basic import abstract as _ab
6060
from typing import List, Dict, Tuple, Set, Union, Any, Generator
61-
from deprecated import deprecated
61+
from deprecation import deprecated
62+
6263

6364
class CMine(_ab._coveragePatterns):
6465
"""
@@ -177,7 +178,8 @@ class CMine(_ab._coveragePatterns):
177178
_lno = 0
178179

179180

180-
def _convert(self, value) -> Union[int, float]:
181+
@staticmethod
182+
def _convert(value) -> Union[int, float]:
181183
"""
182184
To convert the user specified minSup value
183185
@@ -255,7 +257,7 @@ def tidToBitset(self,item_set: Dict[str, int]) -> Dict[str, int]:
255257
256258
:param item_set:
257259
:return: Dictionary
258-
:rtype: dict
260+
:rtype: dict[str,int]
259261
"""
260262
bitset = {}
261263

@@ -265,7 +267,7 @@ def tidToBitset(self,item_set: Dict[str, int]) -> Dict[str, int]:
265267
for i in range(1,len(v)):
266268
diff = int(v[i]) - int(v[i-1])
267269
bitset[k] = (bitset[k] << diff) | 0b1
268-
bitset[k] = (bitset[k] << (self._lno - int(v[i])))
270+
bitset[k] = (bitset[k] << (self._lno - int(v[-1])))
269271
return bitset
270272

271273
def genPatterns(self,prefix: Tuple[str, int],tidData: List[Tuple[str, int]]) -> None:
@@ -397,8 +399,8 @@ def getPatterns(self) -> Dict[str, int]:
397399
"""
398400
Function to send the set of coverage patterns after completion of the mining process
399401
400-
:return: returning coverage patterns
401-
:rtype: dict
402+
:return: Dictionary of patterns and their support counts.
403+
:rtype: Dict[str, int]
402404
"""
403405
return self._finalPatterns
404406

PAMI/coveragePattern/basic/CPPG.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ def _updateDatabases(self, dict1: Dict[str, List[str]]) -> List[List[str]]:
256256
list2.append([i for i in dict1 if i in list1])
257257
return list2
258258

259-
def _buildProjectedDatabase(self, data: List[List[str]], info: List[str]) -> Dict[str, List[List[str]]]:
259+
@staticmethod
260+
def _buildProjectedDatabase(data: List[List[str]], info: List[str]) -> Dict[str, List[List[str]]]:
260261
""" To construct the projected database for each prefix
261262
:param data: list of transactions with support per prefix
262263
:type data: list
@@ -328,7 +329,8 @@ def _savePeriodic(self, itemSet: List[str]) -> str:
328329
t1 = t1 + self._rankedUp[i] + "\t"
329330
return t1
330331

331-
def _convert(self, value: Union[int, float, str]) -> Union[int, float]:
332+
@staticmethod
333+
def _convert(value: Union[int, float, str]) -> Union[int, float]:
332334
"""
333335
To convert the given user specified value
334336

PAMI/extras/calculateMISValues/usingBeta.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
You should have received a copy of the GNU General Public License
3333
along with this program. If not, see <https://www.gnu.org/licenses/>.
3434
"""
35-
import sys as _sys
35+
36+
import sys
37+
#import sys as _sys
38+
from typing import Union
3639
import pandas as _pd
3740
import validators as _validators
3841
from urllib.request import urlopen as _urlopen
3942

40-
class usingBeta():
43+
class usingBeta:
4144
"""
4245
4346
:Description: This code is used to calculate multiple minimum support of items in the the given database. Output can be stored in file or as as dataframe.
@@ -69,7 +72,7 @@ class usingBeta():
6972
_LS: int = int()
7073
_finalPatterns: dict = {}
7174

72-
def __init__(self, iFile: str, beta: int, LS: int, sep: str="\t"):
75+
def __init__(self, iFile: Union[str, _pd.DataFrame], beta: int, LS: int, sep: str="\t"):
7376
self._iFile = iFile
7477
self._beta = beta
7578
self._LS = LS
@@ -84,9 +87,9 @@ def _creatingItemSets(self) -> None:
8487
self._Database = []
8588
self._mapSupport = {}
8689
if isinstance(self._iFile, _pd.DataFrame):
87-
if self._iFile.empty:
90+
if not self._iFile:
8891
print("its empty..")
89-
i = self._iFile.columns.values.tolist()
92+
i = self._iFile.columns.tolist()
9093
if 'Transactions' in i:
9194
self._Database = self._iFile['Transactions'].tolist()
9295

@@ -110,7 +113,7 @@ def _creatingItemSets(self) -> None:
110113
except IOError:
111114
print("File Not Found")
112115

113-
def _creatingFrequentItems(self) -> tuple:
116+
def _creatingFrequentItems(self):
114117
"""
115118
This function creates frequent items from _database.
116119
:return: frequentTidData that stores frequent items and their tid list.
@@ -168,6 +171,6 @@ def save(self, outFile: str) -> None:
168171

169172

170173
if __name__ == '__main__':
171-
cd = usingBeta(sys.argv[1], sys.argv[3], sys.argv[4], sys.argv[5])
174+
cd = usingBeta(sys.argv[1], int(sys.argv[3]), int(sys.argv[4]), sys.argv[5])
172175
cd.calculateMIS()
173176
cd.save(sys.argv[2])

0 commit comments

Comments
 (0)