Skip to content

Commit 85ac68d

Browse files
Format code with yapf, black, autopep8 and isort
1 parent 91dec8f commit 85ac68d

File tree

4 files changed

+121
-44
lines changed

4 files changed

+121
-44
lines changed

semisupervised/utils/_split.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ def split(samples, y):
2222
y = y.to_numpy()
2323

2424
labeled_indexes = y != (-1 or np.NaN or None)
25-
25+
2626
labeled_indexes = np.ravel(labeled_indexes)
2727

2828
L = samples.iloc[labeled_indexes].to_numpy()
2929
U = samples.iloc[~labeled_indexes].to_numpy()
3030
y = y[labeled_indexes]
3131

3232
assert len(L) == len(y), f"L {len(L)} != {len(y)} y"
33-
assert len(L) + len(U) == samples.shape[
34-
0], f"L {len(L)} + U {len(U)} != X {samples.shape[0]}"
33+
assert (
34+
len(L) + len(U) == samples.shape[0]
35+
), f"L {len(L)} + U {len(U)} != X {samples.shape[0]}"
3536

3637
return L, U, y

tests/test_InstanceSelection.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytest
1212
from sklearn.datasets import load_iris
1313

14-
from instance_selection import ENN, CNN, RNN, ICF, MSS, DROP3, LSSm, LSBo
14+
from instance_selection import CNN, DROP3, ENN, ICF, MSS, RNN, LSBo, LSSm
1515

1616

1717
def to_dataframe(y):
@@ -76,8 +76,7 @@ def base(x, y, algorithm, params=None):
7676
model = algorithm(**params) if params is not None else algorithm()
7777
x_filtered, y_filtered = model.filter(x, y)
7878

79-
assert x_filtered.shape[1] == x.shape[1] and y_filtered.shape[1] == \
80-
y.shape[1]
79+
assert x_filtered.shape[1] == x.shape[1] and y_filtered.shape[1] == y.shape[1]
8180

8281
assert x_filtered.shape[0] == y_filtered.shape[0]
8382
assert x_filtered.shape[0] < x.shape[0]
@@ -90,7 +89,7 @@ def test_enn_original(iris_dataset):
9089
:param iris_dataset: This is the dataset to use
9190
"""
9291
x, y = iris_dataset
93-
base(x, y, ENN, {'nearest_neighbors': 3, 'power_parameter': 2})
92+
base(x, y, ENN, {"nearest_neighbors": 3, "power_parameter": 2})
9493

9594

9695
def test_cnn(iris_dataset):
@@ -120,7 +119,7 @@ def test_icf(iris_dataset):
120119
:param iris_dataset: This is the dataset to use
121120
"""
122121
x, y = iris_dataset
123-
base(x, y, ICF, {'nearest_neighbors': 3, 'power_parameter': 2})
122+
base(x, y, ICF, {"nearest_neighbors": 3, "power_parameter": 2})
124123

125124

126125
def test_mss(iris_dataset):
@@ -140,7 +139,7 @@ def test_drop3(iris_dataset):
140139
:param iris_dataset: This is the dataset to use
141140
"""
142141
x, y = iris_dataset
143-
base(x, y, DROP3, {'nearest_neighbors': 3, 'power_parameter': 2})
142+
base(x, y, DROP3, {"nearest_neighbors": 3, "power_parameter": 2})
144143

145144

146145
def test_local_sets_lssm(iris_dataset):
@@ -169,11 +168,17 @@ def test_enn_ss(iris_dataset_ss):
169168
170169
:param iris_dataset: This is the dataset to use
171170
"""
172-
original, original_labels, complete, complete_labels, = iris_dataset_ss
171+
(
172+
original,
173+
original_labels,
174+
complete,
175+
complete_labels,
176+
) = iris_dataset_ss
173177

174178
model = ENN()
175-
x, y = model.filter_original_complete(original, original_labels,
176-
complete, complete_labels)
179+
x, y = model.filter_original_complete(
180+
original, original_labels, complete, complete_labels
181+
)
177182

178183
new_orig = []
179184
for ori in original.to_numpy():

tests/test_SemiSupervised.py

Lines changed: 101 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
from sklearn.neighbors import KNeighborsClassifier
1515

1616
from instance_selection import ENN
17-
from semisupervised import STDPNF, CoTraining, TriTraining, \
18-
DemocraticCoLearning
17+
from semisupervised import STDPNF, CoTraining, DemocraticCoLearning, TriTraining
1918

2019

2120
@pytest.fixture
@@ -56,10 +55,10 @@ def base(x_train, x_test, y_train, y_test, opt_labels, algorithm, params=None):
5655
:param algorithm: the algorithm to use
5756
:param params: a dictionary of parameters to pass to the algorithm
5857
"""
59-
assert isinstance(x_train, pd.DataFrame) and isinstance(y_train,
60-
pd.DataFrame)
61-
assert isinstance(x_test, pd.DataFrame) and isinstance(y_test,
62-
pd.DataFrame)
58+
assert isinstance(x_train, pd.DataFrame) and isinstance(
59+
y_train, pd.DataFrame)
60+
assert isinstance(x_test, pd.DataFrame) and isinstance(
61+
y_test, pd.DataFrame)
6362
model = algorithm(**params) if params is not None else algorithm()
6463

6564
model.fit(x_train, y_train)
@@ -75,23 +74,57 @@ def test_co_training(digits_dataset_ss):
7574
:param digits_dataset_ss: The dataset we're using
7675
"""
7776
x_train, x_test, y_train, y_test, opt_labels = digits_dataset_ss
78-
base(x_train, x_test, y_train, y_test, opt_labels, CoTraining,
79-
{'p': 1, 'n': 3, 'k': 1, 'u': 7})
80-
base(x_train, x_test, y_train, y_test, opt_labels, CoTraining,
81-
{'p': 1, 'n': 3, 'k': 1, 'u': 7,
82-
'c1': KNeighborsClassifier, 'c1_params': {'n_neighbors': 3},
83-
'c2': KNeighborsClassifier})
77+
base(
78+
x_train,
79+
x_test,
80+
y_train,
81+
y_test,
82+
opt_labels,
83+
CoTraining,
84+
{"p": 1, "n": 3, "k": 1, "u": 7},
85+
)
86+
base(
87+
x_train,
88+
x_test,
89+
y_train,
90+
y_test,
91+
opt_labels,
92+
CoTraining,
93+
{
94+
"p": 1,
95+
"n": 3,
96+
"k": 1,
97+
"u": 7,
98+
"c1": KNeighborsClassifier,
99+
"c1_params": {"n_neighbors": 3},
100+
"c2": KNeighborsClassifier,
101+
},
102+
)
84103

85104
with pytest.raises(ValueError):
86105
base(x_train, x_test, y_train, y_test, opt_labels, CoTraining)
87106

88107
with pytest.raises(ValueError):
89-
base(x_train, x_test, y_train, y_test, opt_labels, CoTraining,
90-
{'p': 1, 'n': 3, 'k': 100, 'u': 7})
108+
base(
109+
x_train,
110+
x_test,
111+
y_train,
112+
y_test,
113+
opt_labels,
114+
CoTraining,
115+
{"p": 1, "n": 3, "k": 100, "u": 7},
116+
)
91117

92118
with pytest.raises(ValueError):
93-
base(x_train, x_test, y_train, y_test, opt_labels, CoTraining,
94-
{'p': 5, 'n': 5, 'k': 100, 'u': 15})
119+
base(
120+
x_train,
121+
x_test,
122+
y_train,
123+
y_test,
124+
opt_labels,
125+
CoTraining,
126+
{"p": 5, "n": 5, "k": 100, "u": 15},
127+
)
95128

96129

97130
def test_tri_training(digits_dataset_ss):
@@ -101,9 +134,19 @@ def test_tri_training(digits_dataset_ss):
101134
:param digits_dataset_ss: the dataset we're using
102135
"""
103136
x_train, x_test, y_train, y_test, opt_labels = digits_dataset_ss
104-
base(x_train, x_test, y_train, y_test, opt_labels, TriTraining,
105-
{'c1': KNeighborsClassifier, 'c1_params': {'n_neighbors': 3},
106-
'c2': KNeighborsClassifier})
137+
base(
138+
x_train,
139+
x_test,
140+
y_train,
141+
y_test,
142+
opt_labels,
143+
TriTraining,
144+
{
145+
"c1": KNeighborsClassifier,
146+
"c1_params": {"n_neighbors": 3},
147+
"c2": KNeighborsClassifier,
148+
},
149+
)
107150

108151

109152
def test_demo_co_learning(digits_dataset_ss):
@@ -114,9 +157,19 @@ def test_demo_co_learning(digits_dataset_ss):
114157
"""
115158
x_train, x_test, y_train, y_test, opt_labels = digits_dataset_ss
116159
base(x_train, x_test, y_train, y_test, opt_labels, DemocraticCoLearning)
117-
base(x_train, x_test, y_train, y_test, opt_labels, DemocraticCoLearning,
118-
{'c1': KNeighborsClassifier, 'c1_params': {'n_neighbors': 3},
119-
'c2': KNeighborsClassifier})
160+
base(
161+
x_train,
162+
x_test,
163+
y_train,
164+
y_test,
165+
opt_labels,
166+
DemocraticCoLearning,
167+
{
168+
"c1": KNeighborsClassifier,
169+
"c1_params": {"n_neighbors": 3},
170+
"c2": KNeighborsClassifier,
171+
},
172+
)
120173

121174

122175
def test_density_peaks(digits_dataset_ss):
@@ -141,14 +194,32 @@ def test_density_peaks_filtering(digits_dataset_ss):
141194
"""
142195
x_train, x_test, y_train, y_test, opt_labels = digits_dataset_ss
143196
with pytest.raises(AttributeError):
144-
base(x_train, x_test, y_train, y_test, opt_labels, STDPNF,
145-
{'filtering': True})
146-
base(x_train, x_test, y_train, y_test, opt_labels, STDPNF,
147-
{'filtering': True, 'filter_method': 'ENANE'})
148-
149-
base(x_train, x_test, y_train, y_test, opt_labels, STDPNF,
150-
{'filtering': True, 'filter_method': ENN, 'dc': 'auto',
151-
'classifier': KNeighborsClassifier})
197+
base(x_train, x_test, y_train, y_test,
198+
opt_labels, STDPNF, {"filtering": True})
199+
base(
200+
x_train,
201+
x_test,
202+
y_train,
203+
y_test,
204+
opt_labels,
205+
STDPNF,
206+
{"filtering": True, "filter_method": "ENANE"},
207+
)
208+
209+
base(
210+
x_train,
211+
x_test,
212+
y_train,
213+
y_test,
214+
opt_labels,
215+
STDPNF,
216+
{
217+
"filtering": True,
218+
"filter_method": ENN,
219+
"dc": "auto",
220+
"classifier": KNeighborsClassifier,
221+
},
222+
)
152223

153224

154225
def test_different_len(digits_dataset_ss):

tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def arff_path_file():
1818
It returns the path to the iris dataset in the datasets folder
1919
:return: The path to the iris.arff file
2020
"""
21-
return join('datasets', 'iris.arff')
21+
return join("datasets", "iris.arff")
2222

2323

2424
def test_arff_data(arff_path_file):
@@ -30,5 +30,5 @@ def test_arff_data(arff_path_file):
3030
"""
3131
dataset = arff_data(arff_path_file)
3232
assert isinstance(dataset, Bunch)
33-
dataset1 = arff_data(arff_path_file, ['a', 'b', 'c', 'd'])
33+
dataset1 = arff_data(arff_path_file, ["a", "b", "c", "d"])
3434
assert isinstance(dataset1, Bunch)

0 commit comments

Comments
 (0)