10BC0 Move assert_no_warnings to the dedicated test. · scikit-learn/scikit-learn@54a5f26 · GitHub
[go: up one dir, main page]

Skip to content

Commit 54a5f26

Browse files
committed
Move assert_no_warnings to the dedicated test.
1 parent 0b23b24 commit 54a5f26

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

sklearn/semi_supervised/tests/test_label_propagation.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_distribution():
3939
samples = [[1., 0.], [0., 1.], [1., 1.]]
4040
labels = [0, 1, -1]
4141
for estimator, parameters in ESTIMATORS:
42-
clf = assert_no_warnings(estimator(**parameters).fit, samples, labels)
42+
clf = estimator(**parameters).fit(samples, labels)
4343
if parameters['kernel'] == 'knn':
4444
continue # unstable test; changes in k-NN ordering break it
4545
assert_array_almost_equal(clf.predict_proba([[1., 0.0]]),
@@ -53,15 +53,15 @@ def test_predict():
5353
samples = [[1., 0.], [0., 2.], [1., 3.]]
5454
labels = [0, 1, -1]
5555
for estimator, parameters in ESTIMATORS:
56-
clf = assert_no_warnings(estimator(**parameters).fit, samples, labels)
56+
clf = estimator(**parameters).fit(samples, labels)
5757
assert_array_equal(clf.predict([[0.5, 2.5]]), np.array([1]))
5858

5959

6060
def test_predict_proba():
6161
samples = [[1., 0.], [0., 1.], [1., 2.5]]
6262
labels = [0, 1, -1]
6363
for estimator, parameters in ESTIMATORS:
64-
clf = assert_no_warnings(estimator(**parameters).fit, samples, labels)
64+
clf = estimator(**parameters).fit(samples, labels)
6565
assert_array_almost_equal(clf.predict_proba([[1., 1.]]),
6666
np.array([[0.5, 0.5]]))
6767

@@ -71,7 +71,7 @@ def test_alpha_deprecation():
7171
y[::3] = -1
7272

7373
lp_default = label_propagation.LabelPropagation(kernel='rbf', gamma=0.1)
74-
lp_default_y = assert_no_warnings(lp_default.fit, X, y).transduction_
74+
lp_default_y = lp_default.fit(X, y).transduction_
7575

7676
lp_0 = label_propagation.LabelPropagation(alpha=0, kernel='rbf', gamma=0.1)
7777
lp_0_y = assert_warns(DeprecationWarning, lp_0.fit, X, y).transduction_
@@ -94,7 +94,7 @@ def test_label_spreading_closed_form():
9494
expected = np.dot(np.linalg.inv(np.eye(len(S)) - alpha * S), Y)
9595
expected /= expected.sum(axis=1)[:, np.newaxis]
9696
clf = label_propagation.LabelSpreading(max_iter=10000, alpha=alpha)
97-
assert_no_warnings(clf.fit, X, y)
97+
clf.fit(X, y)
9898
assert_array_almost_equal(expected, clf.label_distributions_, 4)
9999

100100

@@ -110,7 +110,7 @@ def test_label_propagation_closed_form():
110110

111111
clf = label_propagation.LabelPropagation(max_iter=10000,
112112
gamma=0.1)
113-
assert_no_warnings(clf.fit, X, y)
113+
clf.fit(X, y)
114114
# adopting notation from Zhu et al 2002
115115
T_bar = clf._build_graph()
116116
Tuu = T_bar[np.meshgrid(unlabelled_idx, unlabelled_idx, indexing='ij')]
@@ -141,8 +141,7 @@ def test_convergence_speed():
141141
# This is a non-regression test for #5774
142142
X = np.array([[1., 0.], [0., 1.], [1., 2.5]])
143143
y = np.array([0, 1, -1])
144-
mdl = assert_no_warnings(label_propagation.LabelSpreading, kernel='rbf',
145-
max_iter=5000)
144+
mdl = label_propagation.LabelSpreading(kernel='rbf', max_iter=5000)
146145
mdl.fit(X, y)
147146

148147
# this should converge quickly:
@@ -154,5 +153,14 @@ def test_convergence_warning():
154153
# This is a non-regression test for #5774
155154
X = np.array([[1., 0.], [0., 1.], [1., 2.5]])
156155
y = np.array([0, 1, -1])
157-
mdl = label_propagation.LabelSpreading(kernel='rbf', max_iter=5)
156+
mdl = label_propagation.LabelSpreading(kernel='rbf', max_iter=1)
158157
assert_warns(ConvergenceWarning, mdl.fit, X, y)
158+
159+
mdl = label_propagation.LabelPropagation(kernel='rbf', max_iter=1)
160+
assert_warns(ConvergenceWarning, mdl.fit, X, y)
161+
162+
mdl = label_propagation.LabelSpreading(kernel='rbf', max_iter=500)
163+
assert_no_warnings(mdl.fit, X, y)
164+
165+
mdl = label_propagation.LabelPropagation(kernel='rbf', max_iter=500)
166+
assert_no_warnings(mdl.fit, X, y)

0 commit comments

Comments
 (0)
0