Skip to content

Commit 55926f4

Browse files
Fixed some code style issues #207
1 parent 4630f03 commit 55926f4

File tree

6 files changed

+46
-36
lines changed

6 files changed

+46
-36
lines changed

instance_selection/_CNN.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def filter(self, samples, y):
7979
indexes.append(index)
8080
store_not_modified = True
8181
delete_multiple_element(handbag, indexes)
82-
del handbag
82+
8383
samples = pd.DataFrame(store, columns=self.x_attr)
8484
y = pd.DataFrame(
8585
np.array(store_classes, dtype=object).flatten().astype(int))

instance_selection/_LocalSets.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ class LSSm(LocalSets):
146146
147147
"""
148148

149-
def __init__(self):
150-
"""A constructor for the class."""
151-
super().__init__()
152-
153149
def filter(self, instances, labels):
154150
"""
155151
The function takes in a dataframe of instances and a dataframe of
@@ -200,10 +196,6 @@ class LSBo(LocalSets):
200196
201197
"""
202198

203-
def __init__(self):
204-
"""A constructor for the class."""
205-
super(LSBo, self).__init__()
206-
207199
def filter(self, instances, labels):
208200
"""
209201
> The function takes in a dataframe of instances and a dataframe of

instance_selection/_MSS.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ def _enemy_distance(dat, tar):
9090
for sample_1, x1_class in zip(dat, tar):
9191
if x1_class == x_class:
9292
continue
93-
else:
94-
euc = np.linalg.norm(sample - sample_1)
95-
if euc < distance:
96-
distance = euc
93+
euc = np.linalg.norm(sample - sample_1)
94+
if euc < distance:
95+
distance = euc
9796
solution.append([sample, x_class, distance])
9897

9998
solution.sort(key=lambda x: x[2])

semisupervised/DemocraticCoLearning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def predict(self, samples):
395395
confidence = [0 for _ in range(self.n_labels)]
396396
for index, j in enumerate(gj):
397397
izq = (j + 0.5) / (j + 1)
398-
div = True if j != 0 else False
398+
div = j != 0
399399
if div:
400400
der = [
401401
(gj_h[0][index] * self.w1) / gj[index],

semisupervised/DensityPeaks.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from sklearn.svm import SVC
1717

1818
from instance_selection import ENN
19-
2019
from .utils import split
2120

2221

@@ -32,19 +31,19 @@ class STDPNF:
3231
"""
3332

3433
def __init__(
35-
self,
36-
dc=None,
37-
distance_metric="euclidean",
38-
k=3,
39-
gauss_cutoff=True,
40-
percent=2.0,
41-
density_threshold=None,
42-
distance_threshold=None,
43-
anormal=True,
44-
filtering=False,
45-
classifier=None,
46-
classifier_params=None,
47-
filter_method=None,
34+
self,
35+
dc=None,
36+
distance_metric="euclidean",
37+
k=3,
38+
gauss_cutoff=True,
39+
percent=2.0,
40+
density_threshold=None,
41+
distance_threshold=None,
42+
anormal=True,
43+
filtering=False,
44+
classifier=None,
45+
classifier_params=None,
46+
filter_method=None,
4847
):
4948
"""Semi Supervised Algorithm based on Density Peaks."""
5049
self.dc = dc
@@ -70,6 +69,22 @@ def __init__(
7069
else:
7170
self.filter = None
7271

72+
self.y = None
73+
self.l = None
74+
self.u = None
75+
self.classifier_stdpnf = None
76+
self.order = None
77+
self.structure = None
78+
self.structure_stdnpf = None
79+
self.n_id = None
80+
self.distances = None
81+
self.max_dis = None
82+
self.min_dis = None
83+
self.rho = None
84+
self.delta = None
85+
self.nneigh = None
86+
self.data = None
87+
7388
def __build_distance(self):
7489
"""
7590
Calculate distance dict.
@@ -106,7 +121,8 @@ def __auto_select_dc(self):
106121

107122
while True:
108123
nneighs = (
109-
sum([1 for v in self.distances.values() if v < dc]) / self.n_id**2
124+
sum([1 for v in self.distances.values() if
125+
v < dc]) / self.n_id ** 2
110126
)
111127
if 0.01 <= nneighs <= 0.02:
112128
break
@@ -460,7 +476,7 @@ def _fit_stdpnf(self):
460476
while count <= max(self.order.values()):
461477
unlabeled_rows = self.structure_stdnpf.loc[
462478
self.structure_stdnpf["label"] == -1
463-
].index.to_list()
479+
].index.to_list()
464480
unlabeled_indexes = []
465481
for row in unlabeled_rows:
466482
if self.order[row] == count:
@@ -476,7 +492,7 @@ def _fit_stdpnf(self):
476492
else:
477493
labeled_data = self.structure_stdnpf.loc[
478494
self.structure_stdnpf["label"] != -1
479-
]
495+
]
480496
complete = labeled_data["sample"]
481497
complete_y = labeled_data["label"]
482498

@@ -486,14 +502,15 @@ def _fit_stdpnf(self):
486502

487503
labeled_data = self.structure_stdnpf.loc[
488504
self.structure_stdnpf["label"] != -1
489-
]
505+
]
490506
self.classifier_stdpnf.fit(
491507
labeled_data["sample"].tolist(), labeled_data["label"].tolist()
492508
)
493509

494510
count += 1
495511

496-
labeled_data = self.structure_stdnpf.loc[self.structure_stdnpf["label"] != -1]
512+
labeled_data = self.structure_stdnpf.loc[
513+
self.structure_stdnpf["label"] != -1]
497514
self.classifier_stdpnf.fit(
498515
labeled_data["sample"].tolist(), labeled_data["label"].tolist()
499516
)
@@ -516,7 +533,8 @@ def _results_to_structure(self, complete, result):
516533
if not is_in:
517534
results_to_unlabeled.append(r)
518535
for r in results_to_unlabeled:
519-
self.structure_stdnpf.at[np.array(self.structure_stdnpf["sample"], r)][
536+
self.structure_stdnpf.at[
537+
np.array(self.structure_stdnpf["sample"], r)][
520538
"label"
521539
] = -1
522540

utils/arff2dataset.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def arff_data(dataset_path, attr=False):
2020
defaults to False (optional)
2121
:return: A bunch object with the data, target and attributes.
2222
"""
23+
if not ".arff" in str(dataset_path).lower():
24+
raise ValueError("File does not an ARFF extension.")
2325
file = open(dataset_path, "r")
2426
attrs, data = _read_file(file)
2527
file.close()
@@ -33,8 +35,7 @@ def arff_data(dataset_path, attr=False):
3335

3436
if not attr:
3537
return Bunch(data=data, target=labels)
36-
else:
37-
return Bunch(data=data, target=labels, attr=attrs)
38+
return Bunch(data=data, target=labels, attr=attrs)
3839

3940

4041
def _read_file(file):

0 commit comments

Comments
 (0)